PDA

View Full Version : Game Timer


amcquade
07-07-2003, 04:11 PM
Hi,

there are a few threads on game timer problems, but none have worked so far for me.

My problem is that I need the timer to start as the frame is entered, the below script makes it start when the film loads:

onClipEvent (enterFrame) {
// calculate time left
time = (getTimer())/1000;
// display time left
_root.score = time;
}

I'd also like to be able to restart the timer as the game starts again.

many thanks in advance.

Al

:confused:

JEBoothjr
07-07-2003, 04:57 PM
I'm not sure exactly what your trying to do. Get the elapsed game time? Do you need it seconds?

You can use setInterval.


function theTimer () {
_root.score++;
trace(_root.score);
}
setTime = setInterval (theTimer, 1000);


use

clearInterval(setTime);

to stop it, then you can reset it and do anything else you want with it.

amcquade
07-07-2003, 05:59 PM
Sorry gentlemen, a bit more background for you:

Scene one: Loading frame
Scene two: Text Instructions
Scene three: game starts, a man swimming down a river avoiding bolders and rocks. I'm timing him to see how long it takes to swim down the river!!! So the problem is that my timer starts from the beginning of Scene two, I need it to start at scene 3.

So at the moment it's:

onClipEvent (enterFrame) {
// calculate time left
time = (getTimer())/1000;
// display time left
_root.score = time;
}


This works, it just comes on one scene too early. So if they're reading the instructions - the clock has started!!!

Thanks a million for your help, really appreciated.

Al
:)