Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

Occasionally touch events get dropped, so you may also need to implement the same logic in touchesCancelled:withEvent.

See http://discussions.apple.com/thread.jspa?messageID=8397178

share|improve this answer
    
I did occasionally see some cancelled touches. However I eliminated the problem by improving the performance of my game loop (OpenGL performance improvements). –  MrDatabase Jan 14 '11 at 18:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.