O'Reilly logo

SFML Game Development By Example by Raimondas Pupius

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required