Jump to content
  • Advertisement
Sign in to follow this  
Elit3d

SDL Pausing game help?

This topic is 1331 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know this might sound stupid but what is the best way to go about pausing my game by pressing esc. I need it to pause everything then resume once i repress that key. Many thanks!

Share this post


Link to post
Share on other sites
Advertisement

I know this might sound stupid but what is the best way to go about pausing my game by pressing esc. I need it to pause everything then resume once i repress that key. Many thanks!

 

set paused = true when esc is pressed, don't update your game state if paused is true.

Share this post


Link to post
Share on other sites

 

I know this might sound stupid but what is the best way to go about pausing my game by pressing esc. I need it to pause everything then resume once i repress that key. Many thanks!

 

set paused = true when esc is pressed, don't update your game state if paused is true.

 

 

is paused already in the sdl library?

Share this post


Link to post
Share on other sites


is paused already in the sdl library?

No.

 

His suggestion is to create a bool variable called "paused".

Toggle the variable when Escape is pressed.

Check the state of the variable in your update loop to determine what updates.

Share this post


Link to post
Share on other sites

is paused already in the sdl library?

Most people think of pausing in the simple sense, it freezes the game, but in reality it never does. That may or may not be obvious, if you think about a game like the old Zelda games, pausing would take you to some kind of inventory screen. Obviously the game world was still paused in that case but many other elements of the screen had to still function.

Basically pausing doesn't simply halt the game, it halts the ingame logic. How you do that depends completely on the way you've structured your code, if you have your game calling some kind of tick function you probably want it to continue calling it, but maybe a layer under there where it is calling tick on the game objects like the AI, movement, etc, you would either designate some variable and basically stop updating them altogether if it was true, or you could just pass them a delta time of zero to get the same basic behavior.

A library is unlikely to have any kind of pause function unless it has some access to the game loop and actually "knows" where the logic is going to happen so it can stop calling updates on it.

Share this post


Link to post
Share on other sites

 

is paused already in the sdl library?

Most people think of pausing in the simple sense, it freezes the game, but in reality it never does. That may or may not be obvious, if you think about a game like the old Zelda games, pausing would take you to some kind of inventory screen. Obviously the game world was still paused in that case but many other elements of the screen had to still function.

Basically pausing doesn't simply halt the game, it halts the ingame logic. How you do that depends completely on the way you've structured your code, if you have your game calling some kind of tick function you probably want it to continue calling it, but maybe a layer under there where it is calling tick on the game objects like the AI, movement, etc, you would either designate some variable and basically stop updating them altogether if it was true, or you could just pass them a delta time of zero to get the same basic behavior.

A library is unlikely to have any kind of pause function unless it has some access to the game loop and actually "knows" where the logic is going to happen so it can stop calling updates on it.

 

ok so if i had my paused bool and resume bool, how would i actually go about pausing the game? I tried SDL_Delay() but it doesnt work as expected. It kinda just slows it down

Share this post


Link to post
Share on other sites

ok so if i had my paused bool and resume bool, how would i actually go about pausing the game? I tried SDL_Delay() but it doesnt work as expected. It kinda just slows it down


It's slowing down because SDL_Delay actually freezes your program for a specified amount of time. You only want to freeze your logic time.
You probably have a float elapsedTime or something like that. When paused is true you need to set this elapsedTime variable to zero. That way your application is able to do work (processing input, handle incoming events from the OS, ...) while your game logic does not progress.

Share this post


Link to post
Share on other sites

You know the part where you update() your game objects? When the game is paused, simply don't do that. You may wish to continue drawing them or running some animations, depending on the game.

Share this post


Link to post
Share on other sites

You know the part where you update() your game objects? When the game is paused, simply don't do that. You may wish to continue drawing them or running some animations, depending on the game.

i see many thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!