ForumsProgramming ForumTUTORIAL: adding a 'pause game' feature

7 7111
akunu
offline
akunu
35 posts
Nomad

When I first started out in the game programming world, on of the hardest things for me to figure out was hour to let a user pause a game. It turns out a lot of people have trouble with this.

It's actually VERY simple:
var paused:Boolean = false;
addEventListener(Event.ENTER_FRAME, update);
function update(e:Event):void
{
If(!paused){
//...insert regular code here
}else{
//maybe a add a pause menu or something
}
}

EXPLINATION:
Really, all we're doing here is temporarily stoping the game from going to the next frame (updating) until the paused variable is true.

I hope this helps someone!

  • 7 Replies
domecraft
offline
domecraft
333 posts
Nomad

What programming language is this for?? Be more specific.

Darkroot
offline
Darkroot
2,763 posts
Peasant

domecraft I read somewhere you programmed 3 games I now find it hard to believe since you can't tell what Actionscript looks like.

domecraft
offline
domecraft
333 posts
Nomad

I was kidding.... I just wanted to be picked.....Btw I did program 3 games just not on actionscript.

akunu
offline
akunu
35 posts
Nomad

Sorry, that was in as3. Here's the as2 version:

var paused:Boolean = false
_root.onEnterFrame = function(){
if(!paused){
//...insert regular code here
}else{
//maybe a add a pause menu or something
}
}

gaboloth
offline
gaboloth
1,612 posts
Peasant

Actually I don't know as3 but however reading the 1st code I could easily imagine how it can be in as2, but thanks anyway.

GeraldGefter
offline
GeraldGefter
24 posts
Nomad

if you understand Object-Oriented Programming main things
You probably can say that you now both actionscripts C++ java etc

Kevin4762
offline
Kevin4762
2,420 posts
Nomad

Could you show me how to add a pause feature for C++? I'm not too fond of AS2 or AS3.

Showing 1-7 of 7