I’m a bit surprised I’ve not found anything on this topic, but how do I detect when a user untouches the screen after having pressed it. For example, an onscreen button.
From what I can tell so far, my problem stems from the “ended/canceled” condition is never triggered in my touch function if the user moves his/her finger outside of my button image.
Here’s the code I’ve been using:
local p1\_btn\_left;
p1\_btn\_left = display.newCircle( 20, display.contentHeight-40, 20 );
local function onButtonTouch(self,e)
--print ("phase: " .. e.phase)
if e.phase == "began" then
print ("BEGAN")
elseif e.phase == "moved" then
print ("MOVED")
if e.x \> self.contentBounds.xMax or
e.x \< self.contentBounds.xMin or
e.y \> self.contentBounds.yMax or
e.y \< self.contentBounds.yMin then
print ("OUT!!!")
end
elseif e.phase == "ended" or e.phase == "cancelled" then
print ("ENDED")
end
end
p1\_btn\_left.touch = onButtonTouch
p1\_btn\_left:addEventListener( "touch", p1\_btn\_left )
I can see in the console when I touch my object, the BEGAN gets written, when I move the MOVED gets written, but if I let go of the screen outside of the button I never get an ENDED. Actually, I also never get an OUT either… I was trying to see if I can detect when the touch event MOVED out of the button bounds, but that didn’t do anything…
Do I need a runtime event listener to detect this condition? [import]uid: 100618 topic_id: 29489 reply_id: 329489[/import]