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.
Execute the following code:
//ColorTouchSprite.h enum { TS_NONE, TS_TAP, TS_HOLD, TS_DRAG }; @interface ColorTouchSprite : CCSprite { @public float holdTime; //How long have we held down on this? int touchedState; //Current touched state bool isTouched; //Are we touching this currently? float lastMoved; //How long has it been since we moved this? CGPoint lastTouchedPoint; //Where did we last touch? const float...