16
SFML projects / SFGUI
« on: October 31, 2011, 02:17:53 pm »
Thanks, binary! I got it working. I'm not very experienced with CMake and that was a good tutorial (the most I've done is compiled SFML 2!).
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I should have seen your second design earlier ... Because it's kind of similar to what PeterWelzien suggested. Thank you, this is what I'm going to consider for my next design.
But I have a new question. I saw some designs given in this thread that use a stack of states, with the running one one top of the stack. Is it really useful to store old states ? Do you have an example of situation where this could be necessary ?
Thank you very much!
What are you (all) thinking about the difficulty levels, are they okay? Which one did you choose?
Hello
This subject highly interests me. I've been confronted to state machine designs issues (I'm still a beginner in game programming). For my last project, I used the implementation given by the LazyFoo tutorial.
My main problem was that retrieving data from a previous state was a real pain in the ***. It seems Vit got a similar problem.
My question is : if you pass the previous state pointer to the constructor of the new one, is there another way than casting the pointer (which is an abstract GameState class pointer) to be able to get some data ?
I never really used casting, and in my mind, if you need to cast, this means the program design is flawed. Is it true ? Or is casting something common ?
Thanks for your advices, I hope what I asked was understandable (I don't speak english very often ...).
static void GameState::Start(GameState* state)
{
while(state)
{
GameState* next = state->Run();
delete state;
state = next;
}
}
if(myLoadLevelButtonWasPressed)
{
Game_GameState* gameState = new Game_GameState();
gameState->SetLevel(myInputBox.GetString());
return gameState;
}
if(myExitButtonWasPressed)
{
return 0;
}
int main()
{
sf::RenderWindow window;
window.Create();
Game game(window);
game.Run();
}
class Game
{
public:
Game(sf::RenderWindow& window) : m_window(window)
{
}
sf::RenderWindow& GetWindow()
{
return m_window;
}
void Run()
{
while(m_window.IsOpened())
{
m_window.Display();
}
}
private:
sf::RenderWindow& m_window;
}
void some_func()
{
int width = game->GetWindow().GetWidth();
}