The GestureLayer class
For the scope of this game, we will observe just a few basic gestures. These are defined by an enum EGestureType
in GameGlobals.h
as follows:
enum EGestureType { E_GESTURE_NONE = 0, E_GESTURE_TAP, E_GESTURE_SWIPE_UP, E_GESTURE_SWIPE_DOWN, E_GESTURE_SWIPE_LEFT, E_GESTURE_SWIPE_RIGHT, };
As you can see, we will observe the player's touches for taps and swipes in four directions: up, down, left and right. A lot of developers have written great code that observes multiple taps, pinch-zoom gestures, panning gestures, and so on. I encourage you to plug them into this class and increase its capabilities.
Without further ado, let's take a look at the class declaration of GestureLayer
from the GestureLayer.h
file:
class GestureLayer : public CCLayer { public: GestureLayer(); ~GestureLayer(); static GestureLayer* create(CCObject* target, SEL_CallFuncO handler); virtual bool init(CCObject* target, SEL_CallFuncO handler); // touch listeners virtual void...