I wonder where I can find information regarding advanced information on handling touch events… like for example for buttons in a game. I can’t find any information beside “normal” touch events. This stuff doesn’t include answers on how to prevent moving from outside a button on the button which is triggering the touch.
Or for example a user is touching a button but then moving away from the button while still touching the screen… when he finishes the touch outside the button (meaning: ends his touch NOT on the button) the button event listener still is triggered.
Can anyone explain please how to use this advanced touch events?
I looked up some video which did explain this awhile ago… but this vid is now set to private and I can’t find the information here on the pages.
I too would love to find out more on this. For example, I created a little button and in its onEvent event handler I put in a little print to give me the event.phase
I click and hold, I get “began”
I move the finger (or mouse on sim) I get “moved”
I release the finger I get “ended”
If I click and move out of button while I hold clicked and then release I get “cancelled”
So far so good. Here’s the interesting bit.
I click hold and slowly move out of button. I get “moved” times x as long as I keep moving. However, as soon as I am out of buttons boundaries its label colors change back to Defaul from Over. I want to catch that event but event.phase does not register anything there.
you can use the getCurrentStage and setFocus function for example
function button:touch(e)
if e.phase == “began” then
display.getCurrentStage():setFocus(self)
self.isFocus = true
--turn the button ON here
elseif e.phase == “ended” or e.phase == “cancelled” then
display.getCurrentStage():setFocus(nil)
self.isFocus = nil
--turn the button Off and trigger something here
end
end
if you use this code when you touch the button and then move your finger out from the button but the button will still be receiving touch how ever when you start the touch from out side of the button the problem is more complicated
Thanks much for your input. The button is handling its state changes itself so I don’t actually need to change the button. I just need to detect the moment it looses focus and turns itself back to the Default label colors so I can change other things that I happen to overlay on the button. I think I will be able to achieve this with the second code bit you provided. Much appreciated.
I too would love to find out more on this. For example, I created a little button and in its onEvent event handler I put in a little print to give me the event.phase
I click and hold, I get “began”
I move the finger (or mouse on sim) I get “moved”
I release the finger I get “ended”
If I click and move out of button while I hold clicked and then release I get “cancelled”
So far so good. Here’s the interesting bit.
I click hold and slowly move out of button. I get “moved” times x as long as I keep moving. However, as soon as I am out of buttons boundaries its label colors change back to Defaul from Over. I want to catch that event but event.phase does not register anything there.
you can use the getCurrentStage and setFocus function for example
function button:touch(e)
if e.phase == “began” then
display.getCurrentStage():setFocus(self)
self.isFocus = true
--turn the button ON here
elseif e.phase == “ended” or e.phase == “cancelled” then
display.getCurrentStage():setFocus(nil)
self.isFocus = nil
--turn the button Off and trigger something here
end
end
if you use this code when you touch the button and then move your finger out from the button but the button will still be receiving touch how ever when you start the touch from out side of the button the problem is more complicated
Thanks much for your input. The button is handling its state changes itself so I don’t actually need to change the button. I just need to detect the moment it looses focus and turns itself back to the Default label colors so I can change other things that I happen to overlay on the button. I think I will be able to achieve this with the second code bit you provided. Much appreciated.