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 ...

Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.