SFML community forums

Help => General => Topic started by: makerimages on December 27, 2012, 12:08:52 pm

Title: simple way for multiple screens
Post by: makerimages on December 27, 2012, 12:08:52 pm
Hello, I`m new here and I only started learning C++ and SFML about 2 months ago.

I`d like to know if there is a simple way to handle multiple screens in a game. Since Eng is not my native (I`m from Estonia) the http://www.sfml-dev.org/wiki/en/tutoriels/multiecransjeu_en was a bit tricky to undrestand( i do know english VERY GOOD, it just that the overall construction of the screen management reamined a bit fuzzy).

If you know any simple multiple screen managements or can describe how it works in general, I`d be very happy
Title: Re: simple way for multiple screens
Post by: eXpl0it3r on December 27, 2012, 12:17:35 pm
Don't look at such old and specific code. ;)

I've written a SmallGameEngine (https://github.com/eXpl0it3r/SmallGameEngine) based on the this tutorial (http://gamedevgeek.com/tutorials/managing-game-states-in-c/), which itself is based on this article (http://www.codeproject.com/Articles/1374/State-Pattern-in-C-Applications). As you see it's a widespread and quite general topic, so you should find enough reading material. ;)
Title: Re: simple way for multiple screens
Post by: FRex on December 27, 2012, 02:08:31 pm
I'm just an inexperienced hobbyist and I'm still working on my approach but I myself go with stack based approach where top screen gets all controll over state manager, which mantains some shared instances(render window, font, pointer to itself) in a pack class, that gets passed to each state by reference in it's run() method. In main() I just instance my engine, put first state in it and then call mainRun() which is basically:
while(!mStack.empty())
{
cleanUp();//deletes states that got pop'd, it's delayed so I can still mess around with state internal variables after it got pop'd since it's not deleted yet
mStack.top()->run(mPack);
}
 
Game closing is just calling leaveBottom(0); which will pop all states, I used to call popTop(1000) to close game before writing that convinence leaveBottom method. I think that's alright approach, it decouples everything nicely. I can have 20 different game states, and 3 different eye-candy menu states, and mix and match menu to game as I please, without changing anything except the line in menu that does pack.Manager->pushTop(new GameState());