O'Reilly logo

Cocos2d for iPhone 1 Game Development Cookbook by Nathan Burba

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

Tap, hold, and drag input

Tapping, holding, and dragging are the most commonly used input techniques. They form the basic building blocks of input for user interfaces as well as for interacting with game objects. In this recipe, we subclass CCSprite in order to create a sprite which can process touch events and maintain some custom state information. This, plus some logic, allows us to touch, hold, and drag this sprite.

Tap, hold, and drag input

Getting ready

Please refer to the project RecipeCollection01 for full working code of this recipe.

How to do it...

Execute the following code:

//ColorTouchSprite.h enum { TS_NONE, TS_TAP, TS_HOLD, TS_DRAG }; @interface ColorTouchSprite ...

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