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

Author Topic: eXpl0it3r's Small Game Engine  (Read 2433 times)

0 Members and 1 Guest are viewing this topic.

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
eXpl0it3r's Small Game Engine
« on: October 03, 2012, 08:48:19 pm »
Hi eXpl0it3r,

I was checking out your code for your Small Game Engine.  How do the pause and resume work?  They currently just have a "cout statement" to indicate that those functions were called, but how would they work in a real game?

IOW, one is playing a game but wants to pause to go to a menu to set some options, view current statistics for the game, etc.  How would the pause and resume functions work?

Thanks,
Raptor

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: eXpl0it3r's Small Game Engine
« Reply #1 on: October 03, 2012, 10:00:13 pm »
Oh nearly a personal message. ;D

Hi Raptor88! :)

Hmmm I'm not sure if the concept is explained on the original tutorial, anyways the function itself are there for the user to implement things.
For instance if you want to reset things as soon as you resume the state, you could place that code in the resume function.
The GameEngine calls pause() if you load another state without replacing it and calls resume() after getting back to the paused state, e.g. when you switch from the PlayState to the MenuState GameEngine calls pause() on the PlayState and when you switch back again it call resume() on the PlayState.

How you handle what gets displayed in the pausing state is completly up to you, i.e. if you draw a rectangle and then call pause manually the rectangle will still get drawn. If you want to prevent this, then you could have a boolean member variable and when it is set to true you simply don't draw the rectangle but something else.
Which lead me to think that I probably should add this member variable to the GameState itself... ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: eXpl0it3r's Small Game Engine
« Reply #2 on: October 03, 2012, 11:01:18 pm »
Oh nearly a personal message. ;D

Hi Raptor88! :)

Hmmm I'm not sure if the concept is explained on the original tutorial, anyways the function itself are there for the user to implement things.
For instance if you want to reset things as soon as you resume the state, you could place that code in the resume function.
The GameEngine calls pause() if you load another state without replacing it and calls resume() after getting back to the paused state, e.g. when you switch from the PlayState to the MenuState GameEngine calls pause() on the PlayState and when you switch back again it call resume() on the PlayState.

How you handle what gets displayed in the pausing state is completly up to you, i.e. if you draw a rectangle and then call pause manually the rectangle will still get drawn. If you want to prevent this, then you could have a boolean member variable and when it is set to true you simply don't draw the rectangle but something else.
Which lead me to think that I probably should add this member variable to the GameState itself... ;)

Being a beginner with C++ and SFML, I still don't get it.

Suppose I have my craps table displayed with all of the chips bet so far and am in my "GetBets" class, waiting for the player to either make more bets or roll the dice.  But the player wants to go to the MainMenu to change an option, display statistics of the game progress, etc.  When he clicks on the "MainMenu" button, wouldn't I just change the state to the MainMenu instead of calling the pause function?  Then after doing things in the MainMenu, just do a return and be exactly where he left off?

Why call the pause function and then the resume function after doing things in the pause function?  An example would be really helpful for beginners like me.

Thanks,
Raptor

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: eXpl0it3r's Small Game Engine
« Reply #3 on: October 04, 2012, 12:49:59 am »
When he clicks on the "MainMenu" button, wouldn't I just change the state to the MainMenu instead of calling the pause function?  Then after doing things in the MainMenu, just do a return and be exactly where he left off?
Yes this would work perfectly. ;)

Why call the pause function and then the resume function after doing things in the pause function?  An example would be really helpful for beginners like me.
The two functions are specially useful if you call them manually. For example you have a game with enemies etc and now you stop at a certain location at which enemies could attack you if you don't keep moving, but since you have to grab some food, you'd want to pause the game. By pressing P for example you could then call the pause() function, which will set a Boolean and in the update & draw call you now don't update the enemies etc anymore but show a semi-transparent overlay saying "Game Paused". When you return you could press ESC which then calls resume() which changes the Boolean back and your game can proceed.

That's just one example, there are many different use cases...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Raptor88

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: eXpl0it3r's Small Game Engine
« Reply #4 on: October 04, 2012, 02:02:08 am »
When he clicks on the "MainMenu" button, wouldn't I just change the state to the MainMenu instead of calling the pause function?  Then after doing things in the MainMenu, just do a return and be exactly where he left off?
Yes this would work perfectly. ;)

Why call the pause function and then the resume function after doing things in the pause function?  An example would be really helpful for beginners like me.
The two functions are specially useful if you call them manually. For example you have a game with enemies etc and now you stop at a certain location at which enemies could attack you if you don't keep moving, but since you have to grab some food, you'd want to pause the game. By pressing P for example you could then call the pause() function, which will set a Boolean and in the update & draw call you now don't update the enemies etc anymore but show a semi-transparent overlay saying "Game Paused". When you return you could press ESC which then calls resume() which changes the Boolean back and your game can proceed.

That's just one example, there are many different use cases...

Understand now.  Thanks for the help!
Raptor