Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: simple way for multiple screens  (Read 1418 times)

0 Members and 2 Guests are viewing this topic.

makerimages

  • Newbie
  • *
  • Posts: 24
  • Yay!
    • View Profile
    • Email
simple way for multiple screens
« 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
Makerimages-It`s in the pixel

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: simple way for multiple screens
« Reply #1 on: December 27, 2012, 12:17:35 pm »
Don't look at such old and specific code. ;)

I've written a SmallGameEngine based on the this tutorial, which itself is based on this article. As you see it's a widespread and quite general topic, so you should find enough reading material. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: simple way for multiple screens
« Reply #2 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());
Back to C++ gamedev with SFML in May 2023