Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

actionscript 3 how to keep track of time elapsed?

im new to actionscript3 flash. I have a int variable and i would like to add +2 every second since game started. How can i do this ? how do i know how much time has elapsed? thanks in advance!

like image 558
user648244 Avatar asked Mar 30 '11 17:03

user648244


1 Answers

getTimer() will return an int of exactly how many milliseconds from when flash started.

import flash.utils.getTimer;

var myInt:int = getTimer() * 0.001;

myInt will now be however many seconds the program has been running.

edit: oh to tell how long it has been running just keep the initial myInt and check it against the current timer.

so when the game first starts.

var startTime:int = getTimer();

then every frame or whenever you need to check it.

var currentTime:int = getTimer();


var timeRunning:int = (currentTime - startTime) * 0.001; // this is how many seconds the game has been running.
like image 56
Feltope Avatar answered Sep 27 '22 17:09

Feltope