动作3如何跟踪时间过去了? [英] actionscript 3 how to keep track of time elapsed?
问题描述
即时通讯新的ActionScript3闪光灯。我有一个int变量,我想补充+2每一秒,因为比赛开始。我怎样才能做到这一点?我怎么知道多少时间已经过去了?在此先感谢!
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!
推荐答案
的getTimer()将返回到底有多少距离时,闪光灯开始毫秒一个int。
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.
这篇关于动作3如何跟踪时间过去了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!