I loaded an image then I tried img:setDrag{drag=true} but I got a compiler error? Which instruction must I use so?
I just coded it, I think it works, so if anybody need this lack in corona sdk, use this:
local function dragDrop(evt)
local obj=evt.target
local stage=display.getCurrentStage()
if evt.phase==“began” then
obj.drag=true
obj.parent:insert(obj)
stage:setFocus(obj)
elseif evt.phase==“moved” and obj.drag then
obj.x=evt.x
obj.y=evt.y
if obj.bounds~=nil then
if obj.x<obj.bounds[1] then obj.x=obj.bounds[1]
elseif obj.x>obj.bounds[3] then obj.x=obj.bounds[3]
end
if obj.y<obj.bounds[2] then obj.y=obj.bounds[2]
elseif obj.y>obj.bounds[4] then obj.y=obj.bounds[4]
end
end
else
obj.drag=false
stage:setFocus(obj,nil)
end
return true
end
img.bounds={50,50,400,400}
img:addEventListener(“touch”,dragDrop)
I just coded it, I think it works, so if anybody need this lack in corona sdk, use this:
local function dragDrop(evt)
local obj=evt.target
local stage=display.getCurrentStage()
if evt.phase==“began” then
obj.drag=true
obj.parent:insert(obj)
stage:setFocus(obj)
elseif evt.phase==“moved” and obj.drag then
obj.x=evt.x
obj.y=evt.y
if obj.bounds~=nil then
if obj.x<obj.bounds[1] then obj.x=obj.bounds[1]
elseif obj.x>obj.bounds[3] then obj.x=obj.bounds[3]
end
if obj.y<obj.bounds[2] then obj.y=obj.bounds[2]
elseif obj.y>obj.bounds[4] then obj.y=obj.bounds[4]
end
end
else
obj.drag=false
stage:setFocus(obj,nil)
end
return true
end
img.bounds={50,50,400,400}
img:addEventListener(“touch”,dragDrop)