ForumsProgramming ForumCountdown Timer

6 2718
mystera
offline
mystera
39 posts
Nomad

How do I make a countdown timer in AS2

  • 6 Replies
mystera
offline
mystera
39 posts
Nomad

Sorry for doubleposting, but I mean like a 10 second countdown and when it reaches 0 it will go to the gameover screen. Thx

Fighterlegend
offline
Fighterlegend
44 posts
Nomad

var seconds:Number;
if (seconds>0)
seconds = 10;
seconds--;
}else if (seconds<=0){
//do stuff
}

Fighterlegend
offline
Fighterlegend
44 posts
Nomad

Ohh, my bad, did something bad..

Raw scripts suck><



seconds = 10;
if (seconds<=0){
//do stuff
}else{
seconds--;
}

Buttersnack
offline
Buttersnack
332 posts
Peasant

I use a triggered movieclip. When you press start or whatever starts the countdown, the bar movieclip tweens for 10 seconds and on that frame (240 if you're using 24 FPS) add a gotoAndStop, play, or gotoAndPlay.

mystera
offline
mystera
39 posts
Nomad

I think MCs will be easier but I want to try some coding. However, I don't need to know yet, since I had some other changes in my game.

Programpro
offline
Programpro
562 posts
Nomad

Okay, in main frame enter:

var framerate 15;

except replace 15 with your framerate (fps). I don't know a command that returns the current framerate, so I have this which you can alter as you alter your framerate.

Then:

var countdown = framerate * 10;

if (countdown <= 0) {
//game ovah!
} else {
countdown--;
}


This way it will be flexible, as you can manually change the framerate var if you want to change the game's framerate. This is also more reliable than using a timer like, say, the PC's core millisecond timer. The reason is that, if your game slows down (fps drop), this timer will slow down with it. Otherwise, it could end up making it harder for players with slower computers, because they can do less in the allotted time.

So, yeah, there yah go. Each frame, one is subtracted, until the 150th frame where it will cut to gameover.

Hope I helped you!

Showing 1-6 of 6