简体   繁体   中英

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.

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...

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++;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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