0
\$\begingroup\$

I have a Pong game using SFML organized after this tutorial.

This is the UML diagram from the tutorial.

Diagram from the end of the tutorial

Now I am not sure where I should put my SFML RenderWindow variable (and other things that might need to be shared between game states.

I have a PlayingGameState with a shared_ptr to a GameStateManager. So the right place should be the GameStateManager class. Or should I put it into the DirectRenderingGameStateManager and change the shared_ptr to DirectRenderingGameStateManager?

\$\endgroup\$
0
\$\begingroup\$

The instance of your sf::RenderWindow should go in your DirectRenderingGameStateManager. You have it marked as <<interface>> in your diagram but you've given it variables, so I'm assuming it's really an abstract (or concrete?) class. Either way, there's no reason for it to go in GameStateManager as that interface has no correlation to graphics.

Generally, place things as low as possible in your inheritance tree and as high as needed. That is: No reason for GameStateManager to know anything about the RenderWindow, but sharing it netween all your Drawables is asking for trouble.

\$\endgroup\$
  • \$\begingroup\$ So the PlayingGameState should have a shared_ptr to DirectRenderingGameStateManager instead of GameStateManager ? Thanks for your answer and sorry for my long delay. \$\endgroup\$ – Philipp Löwen Nov 18 '16 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.