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

Author Topic: Switching 'scenes'  (Read 15435 times)

0 Members and 1 Guest are viewing this topic.

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Switching 'scenes'
« on: August 17, 2014, 11:56:09 pm »
How do you switch 'scenes' in SFML? Example: From the menu to the game.
This is something that I have not seen anywhere :/

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Switching 'scenes'
« Reply #1 on: August 17, 2014, 11:59:36 pm »
It's not a feature of SFML and thus you have to actually program it yourself.
Also if you "have not seen [it] anywhere" then you didn't even try really looking around. Google will give you all kinds of results for "scene/state/screen management" and given the amounts of links I've already posted, you'd certainly have found one to my SmallGameEngine which was based on a state machine tutorial and essentially demonstrates that exactly.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #2 on: August 18, 2014, 12:02:02 am »
I have searched for hours and did not find anything useful. Will check 'SmallGameEngine'.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #3 on: August 18, 2014, 12:13:50 am »
This is probably one of those things that people don't know the programmer jargon for and thus can't search for unless they happen to have read about it at least once in the past.

The keyword is "state."  Switching from a menu to another menu to the actual game is an example of changing the state of your program.  You should have no difficulty whatsoever finding zillions of google hits about state machines and correctly switching state and the like.  Just for good measure, here's a specific link that discusses managing states in games: http://gameprogrammingpatterns.com/state.html

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #4 on: August 18, 2014, 12:35:39 am »
Indeed, but I DID hear about "statemanager". I was just wondering if there was an easier way. :)

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #5 on: August 18, 2014, 12:42:23 am »
The simplest version of a state manager is very easy.  The link I gave goes through quite a few options, so you can easily pick the one that's appropriate for your program.

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #6 on: August 18, 2014, 12:45:21 am »
I tried eXpl0it3rs link and that works perfectly fine!
Thanks you guys :)

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #7 on: August 18, 2014, 06:57:07 pm »
I do have 2 problems with it:
1) I want to make a new 'state' but I get the error: "OptionsMenuState" : undeclared identifier

2) m_next = StateMachine::build<PlayState>(m_machine, m_window, false);
works from IntroState.cpp, but not from another script.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
AW: Switching 'scenes'
« Reply #8 on: August 18, 2014, 07:23:35 pm »
Well getting some example code and using a library with a simple API doesn't replace the fact that you first need to learn the language in question, meaning C++. ;)

If it's undeclared then the compiler couldn't find the declaration and if it works in one but not the other file you're probably not including the right headers... Basic C++...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #9 on: August 18, 2014, 08:06:10 pm »
Okay, let me tell you this. I know HTML, CSS, PHP, Java, JavaScript, Python. I know how programming languages work. And it is obvious that if you put "1" in "1.hpp" and if you need it, you need to include "1.hpp". That's obvious. In many languages. But I have looked through every file, but I cannot find it. At all.
Because there is nothing where a state such as "IntroState" is made.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Switching 'scenes'
« Reply #10 on: August 18, 2014, 08:33:54 pm »
Well the header inclusion is a bit more complex than as in PHP, Java, JavaScript and Python, but you don't have to believe me, instead you should look it up, for example in a good C++ book.

Not fully sure what you can't find. The OptionsMenuState is a state of your own, so you'll have to create the definition and deceleration on your own and make sure that the right headers get included at the right place.

The state factory function is a a template which is defined in the StateMachine header. To be able to use it from a specific file, you need to include the right headers.

Also don't forget to forward declare things whenever possible.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

teunissenstefan

  • Newbie
  • *
  • Posts: 19
    • View Profile
    • Email
Re: Switching 'scenes'
« Reply #11 on: August 18, 2014, 10:24:30 pm »
 I don't read books.

What I did was I basically copied everything from PlayState.cpp and .hpp but renamed everything that had to be renamed.
So I really don't know where I went wrong.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
Re: Switching 'scenes'
« Reply #12 on: August 18, 2014, 11:47:20 pm »
I don't read books.
Good luck then! ::)

So I really don't know where I went wrong.
Me neither. ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Switching 'scenes'
« Reply #13 on: August 19, 2014, 12:02:46 am »
there are so many things that could be wrong for you to receive that error...
including you not correctly renaming everything that needed to be renamed. that's a real problem when copy/pasting.

by the way eXpl0it3r, thanks for the SmallGameEngine. it's a great starting point for beginners, and gave me a really better idea on how to make a more functional and clean code.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11027
    • View Profile
    • development blog
    • Email
AW: Re: Switching 'scenes'
« Reply #14 on: August 19, 2014, 07:58:36 am »
by the way eXpl0it3r, thanks for the SmallGameEngine. it's a great starting point for beginners, and gave me a really better idea on how to make a more functional and clean code.
I very glad to hear that it was useful for you. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything