I have an object on screen which is dragged around by the user - this works fine and uses ‘return true’ to prevent touches on background objects from registering.
However, what I would like to happen is that if the user touches somewhere on the background, the object will reposition itself to the touch location (this works fine) and THEN have the “moved” phase apply to the object and not the background.
I ahve tried the following with no luck:
resetPin = function(e)
if e.phase == "began" then
stage:setFocus( e.target, e.id )
local touchingObj = false
--check if touch event has occured within the boundaries of the object...
if e.x \< object.x + object.rad and e.x \> object.x - object.rad and e.y \< object.y + object.rad and e.y \> object.y - object.rad then
touchingObj = true
end
--...if not then move object
if touchingObj = false then
object.x = e.x
object.y = e.y
stage:setFocus( e.target, nil )
stage:setFocus( object, e.id )
end
elseif e.phase == "moved" then
elseif e.phase == "ended" then
end
end
background:addEventListener("touch", resetPin)
I’ve tried using setFocus() in both the began and moved phases, with no luck.
Has anyone come across any samples that do something like this?
I guess a similar method would be needed for any app which requires you to create an object at the location of the touch event, and then allows you to drag that object within the same touch event [import]uid: 84115 topic_id: 28725 reply_id: 328725[/import]