O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding LongPress

Longpress or press and hold is a common gesture in which you touch the screen and hold for a couple of seconds instead of removing the finger immediately. The code for longpress is the same, except that it has a different recognizer associated with it. You also need to provide the duration after which the gesture is to be recognized.

Getting ready

There are no additional requirements needed, but you might want to test the duration that is most convenient through user testing.

How to do it…

We will add the following code in the init function to initiate the longpress gesture recognizer. Here, along with the function, we will instruct that if a finger is pressed and held for more than 25 milliseconds, it needs to be considered a longpress. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required