Trouble with touch events on iPhone

Posted by MrDatabase on Game Development See other posts from Game Development or by MrDatabase
Published on 2011-01-06T18:15:16Z Indexed on 2011/01/06 18:58 UTC
Read the original article Hit count: 301

Filed under:
|

I'm making a simple 2D game for iPhone. Think of the game as a ball on the screen that goes up while the user is touching the screen and falls down when the user stops touching the screen.

The ball starts moving up in touchesBegan:withEvent and starts moving down in touchesEnded:withEvent. This works fine almost all the time. However on occasion the ball will keep moving up after the user stops touching... or the ball will keep moving down while the user is touching. Why is this happening?

Just fyi the ball is drawn on a UIWindow. The taps are handled by a UIImageview subclass that's clearColor and takes up the entire screen. This "touchLayer" is also moved to the front of the window in the game loop.

Any idea why this control scheme occasionally fails? Perhaps the touch events just aren't firing? Or they're fired out of order?

Cheers!

© Game Development or respective owner

Related posts about iphone

Related posts about touch