Buron
Buron

Reputation: 1233

How to know touch duration in cocos2d?

Is there any native cocos2d method to calculate touch duration or to detect long touch or small drag not using UILongPressGestureRecognizer ?

Upvotes: 0

Views: 327

Answers (1)

Ramy Al Zuhouri
Ramy Al Zuhouri

Reputation: 21996

It's a matter of registering the time between a ccTouchBegan and ccTouchEnded event.

A UITouch object has this property:

@property(nonatomic, readonly) NSTimeInterval timestamp;

So simply store the value of the first time interval in some ivar when you get a ccTouchBegan event, and make the difference with the time that you get in ccTouchEnded.

Upvotes: 2

Related Questions