Naseiva Khan
Naseiva Khan

Reputation: 965

Touch detection without event processing

I am using cocos2d. I would like to be able to detect whether the screen is touched at a particular instant - that is, rather than intercepting an event when it occurs, I want to detect the presence of touch at a particular moment.

The reason is that I am animating sprites and want to determine if the sprite should keep moving - if the screen is still touched. I cannot use ccTouchesEnded because each time an animation starts I set isTouchEnabled to false because I also want the user to be able to tap rapidly on the screen to move the sprite but if they tapped too rapidly, it would mess with the position of the sprite during the animation process - which I have found screws up the positions of my objects in weird ways.

Is this possible?

Upvotes: 1

Views: 138

Answers (1)

hotpaw2
hotpaw2

Reputation: 70693

There does not appear to be any public API to detect touches other than enabling and receiving these events in the main UI run loop.

You can keep handling events, and set the state left by the last touch event in a model object or global variables. Then you can poll your app's own internal state at any time.

Instead of disabling touches, you can just have your touch handler not do inappropriate things if the event time stamp is too close to some animation start time.

Upvotes: 1

Related Questions