- Home /
Separate functions for separate touches
Hi,
I am trying to handle the touch input for a game, and am having trouble determining which touch should be doing what.
Basically, when the player touches anywhere on screen, it should move the character around the screen. However, when they touch a GUI element and move their finger around, it should move a separate object without affecting the character. With my current method, both touches move the character around.
I was hoping someone would have a suggestion on how to accomplish this.
Thanks!
Answer by Jessy · Jan 20, 2011 at 07:19 PM
Store the touchIDs, and check for them, as necessary. Every time a finger touches the screen, it will be assigned the lowest available positive integer. Example:
- You put two fingers on the screen simultaneously.
- One will be given the touchID of 0, the other, 1.
- If you remove "fingertip 0", the next fingertip that hits the screen will be zero.
- However, if you leave 1 onscreen, and then put two more down at the same time, one new touch will be 0, and the other 2.
- Only after 1 is removed, will something else be able to be considered 1.
That's exactly what I was looking for. I actually wasn't sure how the engine handled the touch array when a touch was released. Thanks for the help!
Your answer
Follow this Question
Related Questions
Not getting a response when a touch doesn't move with TKtouchkit 1 Answer
How to drag object along with dragging touch? 1 Answer
Help with iphone/android touch controls 2 Answers
grid movement via touch on iphone 3 Answers
Different resolutions make the swipe of my player go at different speeds on different devices 0 Answers