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

Author Topic: whats the best/correct way to use multiple screens  (Read 3568 times)

0 Members and 1 Guest are viewing this topic.

Lkcynric

  • Newbie
  • *
  • Posts: 17
    • View Profile
whats the best/correct way to use multiple screens
« on: June 05, 2017, 12:39:49 am »
Hi!

[Backstory] Feel free to ignore it.
I'm making a simple game, just to learn how to do new things and also learn how to you use SFML.

Its my first time using it and its been fun, but I have a few questions i couldn't find answer for, hope someone can help me.  Yes i tried google and also searched the forum (keywords: window create resize) but didn't find what I am looking for.

[questions]
If I have to use several screens in my game, only displaying one at a time, whats the best/correct way to do this?

Right now I create 1 RenderWindow and pass it to 2 separate .hpp files which use the windows differently (different sizes,  background color, etc). When one closes, the other one opens. Check the spoilers if my explanation on how I do it was poor .
(click to show/hide)

My question is, how should I do this?

- create 1 RenderWindow for each screen I use?
- Use only 1 RenderWindow and resize it and set a new view?
- Use 1 RenderWindow without any formating and then use RenderWindow.create to give it settings for each screen I use?

Every way works. But I have no clue what positive and negative aspects they have.
For this simple game it makes no difference, I think, but I want to learn about it, for future reference.

Thank you for your time reading this!
And IF(you answered){thank you for your answer};

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: whats the best/correct way to use multiple screens
« Reply #1 on: June 05, 2017, 11:12:54 am »
Use some sort of state machine. They come in many flavors, if you want one possible example check out my SmallGameEngine or another example in my SmallGameFramework.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Lkcynric

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: whats the best/correct way to use multiple screens
« Reply #2 on: June 05, 2017, 11:55:43 pm »
Thank you!
Thats a bit too complicated (at least at first glance) for what i am playing with at the moment, but I will be reading it for future reference. Will give it a try in the future.

If you don't mind, which of my 3 simple methods you think its best?
2 render windows
1 render window and using .create to give it settings when changing from one screen to the other
or 1 render window and using a new view to change between them.

I am using .create at the moment, simply because i can change the style of the window, but its probably not worth it. I noticed when I changed from 1 render window and setting a new view, to the .create it took a lot longer to show the window. But after 3 or 4 runs its instant now. Maybe because of the SSD.

Not knowing how they work, setting a new view each time is probably the fastest and least resources consuming one.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: whats the best/correct way to use multiple screens
« Reply #3 on: June 06, 2017, 03:22:59 am »
"Multiple screens" in "game state" management tends to mean multiple set-ups of imagery on a single window and switching amongst those set-ups rather than changing the window when changing the imagery.
It would not be particularly good to close and re-open a window when someone pauses the game, for example.

One simple way to manage screens in this context is to use an enum and to determine what gets drawn depending on the enum's current state. This enum can be changed to control which screen is shown. Expect to be using a lot of "if enum is in this state then do/draw this" statements in this case ;)

tl:dr;
Use one window and change what you draw to it.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Lkcynric

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: whats the best/correct way to use multiple screens
« Reply #4 on: June 06, 2017, 03:36:32 pm »
Oh I see. It seams I misunderstood the "state machine" meaning. I didn't have time to look at the examples he provided yet. But your explanations made it simple to understand.

Thank you! I thought that might be the "correct" way to do things, I guess it truly is.
Thank you both! :)