如何在as3中添加计时器

时间:2013-06-29 17:34:20

标签: actionscript-3 flash-cs5

我正在制作一款可以计算点击次数然后添加分数的游戏。我想要的是添加一个计时器,例如:计时器是10秒,完成点击是25,如果计时器停止按钮(用于计算点击次数的那个),你的得分是35分,并且不能点击它会暂停一段时间,计划在移动到另一帧之前制作一个小动画。

希望尽可能简化,因为设计比代码更重要,因为它是一个设计基类。

请不要使用hitTestObject或类,我也想避免使用数组:(上次使用它们是一场灾难......

抱歉是诺布 谢谢你提前

这是cODE:

 var power:Number = 0;
    var myTimer : Timer = new Timer(10 * 1000, 0);


    myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, function( e:TimerEvent ):void    
    {
        myTimer.start();
        trace("time up");
        bgBack.gotoAndPlay("hit");
        if (power == 5)
        {
        bgBack.gotoAndPlay("mini");
        }
        else if (power == 15)
        {
        bgBack.gotoAndPlay("mini");
        }
        else if (power == 25){
        bgBack.gotoAndPlay("belowAve");
        }
        else if (power == 35){
        bgBack.gotoAndPlay("ave");
        }
        else if (power == 50){
        bgBack.gotoAndPlay("ave");
        }
        else if (power == 65){
        bgBack.gotoAndPlay("highAve");
        }
        else if (power == 80){
        bgBack.gotoAndPlay("magni");
        }

});

pressBtn.addEventListener( MouseEvent.CLICK, function( e:MouseEvent ):void
{
   power++;

     if (power == 5)
    {
    gauge.gotoAndPlay("one");
    }
    else if (power == 15)
    {
    gauge.gotoAndPlay("two");
    }
    else if (power == 25){
    gauge.gotoAndPlay("three");
    }
    else if (power == 35){
    gauge.gotoAndPlay("four");
    }
    else if (power == 50){
    gauge.gotoAndPlay("five");
    }
    else if (power == 65){
    gauge.gotoAndPlay("six");
    }
    else if (power == 80){
    gauge.gotoAndPlay("seven");
    }

1 个答案:

答案 0 :(得分:0)

var myTimer : Timer = new Timer( 10 * 1000, 0 );
myTimer.addEventListener( TimerEvent.TIMER_COMPLETE, function( e:TimerEvent ):void
{
    //here the timer ends and you can do stuff with the clicks.
    //the ,0 means it will repeat this over and over and over. 10 seconds * 1000 milliseconds because its kept in milliseconds.
});
myTimer.start();

以及

var myClicks : Number = 0;
stage.addEventListener( MouseEvent.CLICK, function( e:MouseEvent ):void
{
    myClicks++;
});