问题描述
我是 actionscript3 flash 的新手.我有一个 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() 将返回一个整数,表示从 Flash 启动开始的确切毫秒数.
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 现在将是程序运行了多少秒.
myInt will now be however many seconds the program has been running.
哦要知道它已经运行了多长时间,只需保留初始 myInt 并根据当前计时器检查它.
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.
这篇关于actionscript 3 如何跟踪经过的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!