Actionscript 3 flash游戏中的倒计时
我正在制作一个简单的直升机游戏来尝试制作flash游戏。我想做一个倒计时计时器,从3秒开始倒计时,然后开始循环,但我不知道该怎么做。我不使用flash中的帧,而是使用动作脚本(3)来进行“输入帧”循环,如果这样有帮助的话。看起来是这样的: addEventListener(Event.ENTER_FRAME,mainLoop)Actionscript 3 flash游戏中的倒计时,actionscript-3,timer,countdown,flash,Actionscript 3,Timer,Countdown,Flash,我正在制作一个简单的直升机游戏来尝试制作flash游戏。我想做一个倒计时计时器,从3秒开始倒计时,然后开始循环,但我不知道该怎么做。我不使用flash中的帧,而是使用动作脚本(3)来进行“输入帧”循环,如果这样有帮助的话。看起来是这样的: addEventListener(Event.ENTER_FRAME,mainLoop) 我肯定我需要把计时器放在上面,我只是不知道怎么做计时器。任何建议都可能会有所帮助,因为我是AS3新手,谢谢。要制作倒计时计时器,您可以使用,如下所示: trace('3'
我肯定我需要把计时器放在上面,我只是不知道怎么做计时器。任何建议都可能会有所帮助,因为我是AS3新手,谢谢。要制作倒计时计时器,您可以使用,如下所示:
trace('3');
// create a timer with : delay: 1 second, repeats: 3
var timer:Timer = new Timer(1000, 3);
timer.addEventListener(
TimerEvent.TIMER,
// on every repeat
function(e:TimerEvent):void {
trace(Math.abs(timer.currentCount - 3)); // gives : 2, 1, 0
}
)
timer.addEventListener(
TimerEvent.TIMER_COMPLETE,
// at the timer end
function(e:TimerEvent):void {
// do other instructions
trace('go');
}
)
// start the timer
timer.start();
希望这能有所帮助。我希望我能在代码方面帮助您。我得到的是,你试着倒计时3秒,然后从某个地方开始。 是的,您需要一个计时器:
var theTime:Timer
theTime = new Timer(countDownLoading*1000); //1000 is in milisecond
var countDown = 1;
var totalCountDown = 3; // How long it'g gonna count
var countDownLap = totalLoading;
theTime.addEventListener(TimerEvent.TIMER,tick); //adding timer event
function tick(e:TimerEvent){
if(countDownLap == 0)//if the cound down is 0
{
time.stop();
gotoAndStop(2);
trace("Finish counting");
} else { //not counting down yet, then lets count
countDownLap = countDownLap - countDown; //
trace(countDownLap);
}
//timer goes like the ticking clock so if the count down is not 0.
//everytime the ticking starts the cound down (3) - 1
}
我希望这能有所帮助。试试。我不建议使用inline anonymousfunctions@null我试图通过一个最简单的工作示例演示如何使用
计时器对象。我认为PO知道如何使用事件处理程序,在这个级别上,我不认为匿名函数会导致问题。您的答案应该包括对解决方案的解释。请看。