Hi, I'm working through the book, currently at Chapter 5. Up to this point in the book, the game FPS stats are implemented as members of the Application class. After working through the State and StateStack code, it occurred to me that I could make the stats into a "DebugState" object, essentially the same as the MenuState, so that display of the stats can be toggled on and off with the "D" key.
I'd also like to show the Player Aircraft's coordinates on the DebugState layer. However, after the code reorganization with the State objects, the Aircraft object is now a private member of the World object, which is in turn a member of the GameState object, and not so easy to access from another State object:
class GameState : public State
{
...
private:
World mWorld;
}
class World : public sf::NonCopyable
{
public:
explicit World(sf::RenderWindow& window);
...
private:
Aircraft* mPlayerAircraft; <-- need to get x,y from this member
};
class Aircraft : public Entity {...}
class Entity : public SceneNode {...}
class SceneNode
{
public:
sf::Vector2f getWorldPosition() const; <-- method to get x,y
}
Perhaps I could move the World member from GameState into Application, then add it to the State::Context? It would then be accessible to all States, in the same way as the Player object:
class Application
{
...
private:
sf::RenderWindow mWindow;
TextureHolder mTextures;
FontHolder mFonts;
Player mPlayer;
World mWorld;
StateStack mStateStack;
};
// Constructor
Application::Application()
: mWindow(sf::VideoMode(640,480), "States", sf::Style::Close)
, mTextures()
, mFonts()
, mPlayer()
, mWorld(mWindow)
, mStateStack(State::Context(mWindow, mTextures, mFonts, mPlayer, mWorld))
{
...
}
Any ideas or hints are welcome!