闪光游戏中的倒数计时器

时间:2015-03-13 21:51:07

标签: actionscript-3 timer countdown flash

我正在制作一款简单的直升机游戏,试图制作Flash游戏。我想制作倒数计时器,从3秒开始倒计时,然后开始循环,但我不知道该怎么办。我没有在flash中使用帧,而是使用动作脚本(3)来制作“ENTER_FRAME”循环,如果这有帮助的话。它看起来像这样:

addEventListener(Event.ENTER_FRAME,mainLoop);

我确定我需要将计时器放在它上面,我只是不确定如何制作计时器。任何建议都可能有所帮助,因为我是AS3的新手,谢谢。

2 个答案:

答案 0 :(得分:0)

要制作倒数计时器,您可以使用 Timer ,如下所示:

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();

希望可以提供帮助。

答案 1 :(得分:-1)

我希望我可以帮助您完成代码。我得到的是你试着让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
    }

我希望这有帮助。