actionscript 3如何跟踪已过去的时间?

use*_*244 6 flash timer actionscript-3

我是动作脚本flash的新手.我有一个int变量,我希望自游戏开始以来每秒增加+2.我怎样才能做到这一点 ?我怎么知道已经过了多少时间?提前致谢!

Fel*_*ope 20

getTimer()将返回一个int,它精确到闪存启动时的毫秒数.

import flash.utils.getTimer;

var myInt:int = getTimer() * 0.001;
Run Code Online (Sandbox Code Playgroud)

myInt现在将在程序运行的几秒钟内完成.

编辑:哦,告诉它运行多长时间保持初始myInt并检查当前计时器.

所以当游戏首次开始时.

var startTime:int = getTimer();
Run Code Online (Sandbox Code Playgroud)

然后每一帧或每当你需要检查它.

var currentTime:int = getTimer();


var timeRunning:int = (currentTime - startTime) * 0.001; // this is how many seconds the game has been running.
Run Code Online (Sandbox Code Playgroud)