PDA

View Full Version : Game Timer ...


Reflex
09-10-2001, 05:17 AM
I am building a small game that requires a timer.

So far I have a movie clip, instance name of "timer", and within this movie clip is a dynamic text box with a variable name of "newTime".

I have placed the clip on the stage and this is the code given to it :

onClipEvent (load) {
startTime = getTimer();
}
onClipEvent (enterFrame) {
currentTime = getTimer();
newTime = 60 - int((currentTime - startTime) / 1000) ;
}

This works fine as a timer counting backwards from 60. The problem I am having is stopping the timer at 0.

Does anyone have any answers for what I am trying to achieve ?.

Thanks for your time.

Jesse
09-10-2001, 06:17 AM
if (newTime != 0) {
currentTime = getTimer();
newTime = 60-int((currentTime-startTime)/1000);
} else {
// some action
}
?

Reflex
09-10-2001, 06:27 AM
Thanks Jesse

Eric Neely
09-12-2001, 08:29 PM
With this code, what would be the most efficient way to display a 0 before any number less than 10?

Jesse
09-13-2001, 03:32 AM
ahh:
if (newTime<=10) {
newTime = 0;
} else if (newTime != 0) {
currentTime = getTimer();
newTime = 60-int((currentTime-startTime)/1000);
} else {
// some action
}

cinciem
09-26-2001, 08:38 PM
I tried to start this code with a key press and it just stopped the displaying the count-down. It showed the number on the key press... not quite what I had in mind.

I want to start the timer on my keypress and have it count down from 60.:rolleyes:

thanks for any help you can give.

Jesse
10-02-2001, 09:30 AM
Pop this on an MC:
onClipEvent (keyDown) {
go = true;
startTime = getTimer();
}
onClipEvent (enterFrame) {
if (go) {
if (newTime != 0) {
currentTime = getTimer();
newTime = 60-int((currentTime-startTime)/1000);
} else {
// some action
}
}
}
It will start counting down when any key is pressed.

cinciem
10-02-2001, 01:56 PM
Thanks for you help!

Eric Neely
12-03-2001, 04:42 PM
I'm using this code for a game timer... I'd like to pause it when the help button (on the main stage) is pressed. What would be the best way to accomplish this?

Jesse
12-04-2001, 03:13 AM
you'd have to disable the countdown timer thingo, time how long the help screen was up for, then add it to the time limit and continue the timer... or note the number of elapsed seconds each time the help screen is disaplayed, disable the timer, and when you restart the time, subtract that number of seconds from the original time limit... that's prolly easiest.

Eric Neely
12-04-2001, 03:11 PM
That makes sense... but I can't even fathom how to write that code right now... Does anybody here know how to write that off the top of your head?

Thanks for your help on this.

Eric Neely
12-04-2001, 11:37 PM
I really need help with this, and timing is an issue. This is something I need to have wrapped up tomorrow morning...

If anyone could help, I'd really appreciate it...

thanks!
Eric

Jesse
12-07-2001, 02:18 AM
OK here's a 2 minute fix. It does what you want (hold the black button for a few seconds and you'll see what I meant) but it will nly work once. You'll have to correct that yourself if you want it immediately. I'll get around to it at some stage.

renato999
12-07-2001, 04:48 AM
Brilliant! :)