Introducing the state pattern

All of the problems mentioned previously can be avoided after some careful white-boarding and consideration. The possibility was brought up earlier of different game states simply being localized to their own classes. All of these classes will share the same methods for being updated and rendered, which makes inheritance the word of the hour. Let's take a look at our base state header:

class StateManager; class BaseState{ friend class StateManager; public: BaseState(StateManager* l_stateManager) :m_stateMgr(l_stateManager),m_transparent(false), m_transcendent(false){} virtual ~BaseState(){} virtual void OnCreate() = 0; virtual void OnDestroy() = 0; virtual void Activate() = 0; virtual void Deactivate() = 0; virtual ...

Get SFML Game Development By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.