ForumsProgramming ForumAS2 Timer Help

1 5460
andyhunter
offline
andyhunter
30 posts
Nomad

can you use the current frame rate of your game as a variable?
my timer's code
timer += 1;
if(timer >= 30)
{
timer = 0;
time += 1;
_root.gameOverMenu.timerText.text = time;
}

can i use the game's frame rate instead of 30? if(timer >= frameRate)

  • 1 Reply
WhiskeyedJack
offline
WhiskeyedJack
80 posts
Shepherd

Sounds like you might just want to use an actual timer based on time, not progression of frames then. Check out this post. Although setInterval might be more useful to you.

You could probably make a variable in _root.gameOverMenu like

_root.gameOverMenu.time = 0;


Then you can use:
//as2
var timer:Number = setInterval(timeIncrease, 1000)// 1000 milliseconds = 1 sec

function timeIncrease(){
_root.gameOverMenu.time += 1;
_root.gameOverMenu.timerText.text = _root.gameOverMenu.time;
}


Just make sure you call clearInterval(timer) if you want to stop the timer.
Showing 1-1 of 1