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\$

1 Answer 1

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\$
1
  • \$\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\$ Commented Nov 18, 2016 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .