Forum Topic: Timer Seconds

(98 views • 8 replies)

This topic is 1 page long.

<< < > >>
None

UknownXL

Reply To Post Reply & Quote

Posted at: 11/6/09 08:03 PM

UknownXL EVIL LEVEL 10

Sign-Up: 05/22/05

Posts: 1,335

Im making a timer in my game and I was wondering how I would make a timer using seconds. Basically i want it to count up (in seconds) when the timer is activated. I have something and its like this but the time is way to fast.

_root.mtime = 0;
onEnterFrame = function () {
if (_root.mtime>=0) {
_root.mtime += 1;
}
};


None

hdxmike

Reply To Post Reply & Quote

Posted at: 11/6/09 08:11 PM

hdxmike LIGHT LEVEL 09

Sign-Up: 09/11/09

Posts: 1,805

getTimer() ???

1000 = 1 sec


None

UknownXL

Reply To Post Reply & Quote

Posted at: 11/6/09 08:17 PM

UknownXL EVIL LEVEL 10

Sign-Up: 05/22/05

Posts: 1,335

Ok I know this is probably the biggest noob question I have asked, but what do you mean?


None

Headshot777

Reply To Post Reply & Quote

Posted at: 11/6/09 08:28 PM

Headshot777 LIGHT LEVEL 20

Sign-Up: 05/04/08

Posts: 3,176

At 11/6/09 08:03 PM, UknownXL wrote: Im making a timer in my game and I was wondering how I would make a timer using seconds. Basically i want it to count up (in seconds) when the timer is activated. I have something and its like this but the time is way to fast.

_root.mtime = 0;
onEnterFrame = function () {
if (_root.mtime>=0) {
_root.mtime += 1;
}
};

Make a second variable called mtime2 and use that for your timer, then replace your old script with this.

_root.mtime = 0;
onEnterFrame = function () {
_root.mtime++
if (_root.mtime>= PUT YOUR FPS HERE) {
_root.mtime2 += 1;
_root.mtime = 0
}
};

And where it says PUT YOUR FPS HERE, put your frames per second number.

12

BBS Signature

None

hdxmike

Reply To Post Reply & Quote

Posted at: 11/6/09 08:59 PM

hdxmike LIGHT LEVEL 09

Sign-Up: 09/11/09

Posts: 1,805

At 11/6/09 08:28 PM, Headshot777 wrote: cody stuff

Yeah thats how i used to do it, problem is its not time based its frame based, if your flash framrate lags so does the timer so its not really a timeer


Happy

matrix5565

Reply To Post Reply & Quote

Posted at: 11/6/09 10:39 PM

matrix5565 LIGHT LEVEL 15

Sign-Up: 02/28/06

Posts: 567

getTimer() holds the time in milliseconds since the Flash began.
So to get the time since an event, you set a variable to getTimer() and find out how much time has passed since then:

_root.startTime = 0;
function startTimer():Void
{
    startTime = getTimer();
}
function getTimer():Number
{
    return getTimer()-_root.startTime;
}

Angry

matrix5565

Reply To Post Reply & Quote

Posted at: 11/6/09 10:41 PM

matrix5565 LIGHT LEVEL 15

Sign-Up: 02/28/06

Posts: 567

Also, I have no idea why I named that second function 'getTimer'

But I think you get the idea.

I'm double posting way too much tonight...

None

K-Guare

Reply To Post Reply & Quote

Posted at: 11/6/09 11:39 PM

K-Guare FAB LEVEL 17

Sign-Up: 05/23/08

Posts: 2,429

At 11/6/09 08:03 PM, UknownXL wrote: but the time is way to fast.

Divide that time by the framerate
to get the time in seconds.

dr. seuss
"unless someone like you cares a whole awful lot, nothing is going to get better. it's not."

BBS Signature

None

TheBoob

Reply To Post Reply & Quote

Posted at: 11/6/09 11:43 PM

TheBoob NEUTRAL LEVEL 12

Sign-Up: 04/12/02

Posts: 387

One thing i have noticed in my time making flash, is its not good to mix timers and enter frame effects. (this is just my opinion)

I would either recommend using timers for EVERYTHING or enterframe events for EVERYTHING. When you use only one, everything is linked together, so computer speed doesn't effect ability to preform a task.

If you want my personal opinion, i like making games with enterframe events for everything, because if you computer lags it does not hinder your ability to play the game (as much as if you do it the other way).


All times are Eastern Standard Time (GMT -5) | Current Time: 05:04 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!