O'Reilly logo

Mastering SFML Game Development 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

Implementing the game state

Now it's getting more interesting. The game state is where all of the fun happens, so we need to make sure it's set up properly. Let us start, as per usual, with the creation of the state:

void State_Game::OnCreate() { auto context = m_stateMgr->GetContext(); EventManager* evMgr = context->m_eventManager; evMgr->AddCallback("Key_Escape", &State_Game::MainMenu, this); evMgr->AddCallback("Player_MoveLeft", &State_Game::PlayerMove, this); evMgr->AddCallback("Player_MoveRight", &State_Game::PlayerMove, this); evMgr->AddCallback("Player_MoveUp", &State_Game::PlayerMove, this); evMgr->AddCallback("Player_MoveDown", &State_Game::PlayerMove, this); sf::Vector2u size = context->m_wind->GetWindowSize(); m_view.setSize(static_cast<float>(size.x), ...

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