I have recently created my account here and wanted to ask this simple question just to start getting familiar with the forum.
I am starting my first project with SFML wich is a basic 2D scroller prototype. I decided to implement a State Machine for the Main Menu and the Game scene, using inheritance. Something like:
// Base class
class State {
...
virtual void Update(float deltaTime);
...
}
// Derived classes
class MainMenu : public State {
...
}
class GameScene : public State {
...
}
Should I make my State class inherit from sf::Drawable? That enables me to do:
_window->draw(myAmazingState.top());
// rather than myAmazingState.top().Draw(_window);
Do you think this will cause me any trouble late in the development?
By the way, this will be called in my Application::Draw() function:
void Application::Draw() {
_window->clear(0,0,0,255);
...
_window->draw(myAmazingState.top());
...
_window->display();
}
I found SFML very well written. So I would love to start participating in this froum. Thanks in advance!
Should I make my State class inherit from sf::Drawable? That enables me to do:
_window->draw(myAmazingState.top());
// rather than myAmazingState.top().Draw(_window);
The question you should ask yourself: what do you want to achieve with the sf::Drawable? Ideally the answer is not syntax on its own, but rather some of the abstraction it provides. Do you use the sf::RenderStates parameter, for example?
If there's no benefit right now, I would tend to keep things simple. It's not uncommon that user classes have a custom Update() and Draw() function, for game logic and rendering. The advantage of a custom function is that you can pass extra parameters that don't fit the sf::Drawable interface, for example:
void GameScene::Draw(bool showGui, /* other options */)
If it should really prove to be a problem, it's quite an easy and quick change.