Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / some help on pausing and unpausing a game

Author
Message
Lover of games
20
Years of Service
User Offline
Joined: 17th Apr 2005
Location:
Posted: 23rd Dec 2010 14:25
Well, i managed to pause my app so things stop but having a little trouble unpausing....(I reaslly should give this up)anyways, here's my whole while loop



the logic in pausing seems right and unpausing seems right also but i don't know...

"Originally I was going to have a BS on it but you know how that would be. I can't walk around with the letters BS on me." More or less a qoute by Syndrome from Jack, Jack, attack
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 23rd Dec 2010 14:30 Edited at: 23rd Dec 2010 14:38
At a quick glance, your unpausing logic is inside the main game loop ... which isn't run when you're game is paused. That's like saying when I'm full awake I'll go to sleep, and when I want to wake up again, I'll press this button ...... but you're asleep, so you can't press it.

Man analogies suck, I know.

Move your pause toggle code outside of the while(!paused) block, or alternatively, put it in a function and call it from inside the !paused block, and from outside, but be careful not to call it twice when !paused.

Edit:
Also, you can't say
if(input->KeyPressed(DIK_P)){
Do stuff
} else if(input->KeyPressed(DIK_P)){
Do stuff
}

Because the else condition will never happen, as the if comparisons are looking at the same thing. Here comes another great analogy!

You can't say, if I am fat I'll lose wait, else if I'm fat I'll eat more. You're either fat or you're not. If you're fat you'll lose wait, and if you're not fat, you won't eat more, cos you're asking if you'r fat again!

Your logic needs to be something like:
if(input->KeyPressed(DIK_P)){
if toggle{
toggle on stuff
}else {
toggle off stuff
}
}

David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 23rd Dec 2010 14:47 Edited at: 23rd Dec 2010 14:49
Not really addressing the exact issue - but a better way to do this kind of thing is to completely separate the logic update from the visuals/message pump update.

For example, this loop out of one of my projects:



Whilst the logic freezes when paused, the input, visuals and timer continue as-is. This means it's even possible to move through the world whilst everything is frozen

09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0
Lover of games
20
Years of Service
User Offline
Joined: 17th Apr 2005
Location:
Posted: 23rd Dec 2010 15:04
i'll try thanks as my programming I teacher alweays says "Press On"

"Originally I was going to have a BS on it but you know how that would be. I can't walk around with the letters BS on me." More or less a qoute by Syndrome from Jack, Jack, attack

Login to post a reply

Server time is: 2025-05-23 19:37:17
Your offset time is: 2025-05-23 19:37:17