// // state.h // #ifndef state_h #define state_h #include "cocos2d.h" class HelloWorld; class State : public cocos2d::Layer { public: /** * Called when entering state * * @param previousState previous state or null if this is the first state */ virtual void didEnterWithPreviousState(State* previousState) {}; /** * Called every frame by state machine * * @param delta time */ virtual void updateWithDeltaTime(float delta) {}; /** * Checks if next state is valid for transition * * @param state next state * * @return true if valid, false otherwise */ virtual bool isValidNextState(State* state) {return false;}; /** * Called when exiting current state * * @param nextState next state */ virtual void willExitWithNextState(State* nextState) {}; /** * Get state machine * * @return state machine */ HelloWorld* getStateMachine() { return _HelloWorld; } /** * Set State machine, this will be set when state has been added to state machine * * @param stateMachine parent state machine */ void setStateMachine(HelloWorld* stateMachine) { _HelloWorld = stateMachine; } virtual ~State(){}; protected: HelloWorld* _HelloWorld; }; #endif /* state_h */