As far as I could tell, there are 4 phases to a touch event. In a game I'm working on, I need to detect when a finger slides OFF a display object. What would be the best approach to solving this?
Thanks!
Label: corona android iphone ipad building error inmobi problem display screen View image tableView failed object physics touch button game lua config event listener |
As far as I could tell, there are 4 phases to a touch event. In a game I'm working on, I need to detect when a finger slides OFF a display object. What would be the best approach to solving this?
Thanks!
I have this question as well. This seems like such a common use case I must be missing something. Can someone point me in the right direction?
-Andy
In the code for Mutant ABCs I created a routine for the Next and Previous buttons that would highlight when you touched -- and if you dragged your finger off and then back on it would unhighlight/highlight as needed.
Basically, look for the "moved" event.phase and see if the event.x and event.y coordinates are inside the target object. If not, you know the finger has slid off the object.
Jay
So to do this you have to have a global listener that checks all buttons in the game, right?
I just have a listener for each button that can be touched -- it's actually the same listener that handles the highlight/unhighlight action for all buttons. When each button is released the listener checks to see which button it was and runs the appropriate code.
I'm actually in the middle of writing up an article about this for my GameDevNation.com site. If you're a member (blatant plug) you'll see if online probably some time tomorrow.
Jay
Thanks.
I'd love to see the code. I used a global listener, since if I attach the listener to every button, then the move event doesn't fire if the finger is no longer on the button
Here's a link to a video that shows what I do:
http://instantvideowebpages.com/play/?m=645
There's a link form the video to the GameDevNation.com site where you can download the entire article plus sample code. You have to be a member, but that's free.
Jay