简体   繁体   English

如何在as3中添加计时器

[英]how to add timer in as3

I am doing a game that will count number of clicks then add scores. 我正在做一个游戏,该游戏将计算点击次数,然后增加得分。 What i want is to add a timer, for example: the timer is 10 secs and the click done is 25 and your score is 35 points if the timer stopped the button(the one used to count the num of clicks) cannot be clicked and it will pause for a while, plan to make a little animation before it moves to another frame. 我想要的是添加一个计时器,例如:计时器是10秒,单击完成是25,如果计时器停止了该按钮(用于计算点击次数的按钮),则您的得分是35分,并且它将暂停一会儿,计划在移至另一帧之前先制作一个动画。

Want to make this simple as possible since design is more important than the codes, because it is a design base class. 由于设计比代码重要,因为它是设计基类,因此希望使其尽可能简单。

Please no hitTestObject or classes, and i want to avoid arrays too :( last time a used them is a disaster... 请不要hitTestObject或类,我也想避免数组:(上一次使用它们是一场灾难...

Sorry for being noob And thank you for advance 很抱歉成为菜鸟,谢谢你的进步

Here is the 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");
    }
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();

and also 并且

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM