如何递减定时器变量 - AS3

How to decrement Timer variable - AS3

好吧,我的代码AS3中有两个TIMER类型的变量,但是有一部分 我的游戏,我必须减少它们的价值。

var tempo1:Timer = new Timer(4000);
var tParada:Timer = new Timer(2000, 1);

我想知道如何从外部开始减少这些值 class ...

谢谢你

只需减少每次计时器触发时的延迟。

var tempo1:Timer = new Timer(4000);
tempo1.addEventListener(TimerEvent.TIMER, tick);
var minValue:int = 1000;

tempo1.start();

function tick(e:TimerEvent):void {
    if(tempo1.delay - 100 >= minValue){
        tempo1.delay -= 100;
    }
}

或者,如果想要更流畅,您可以这样做:

import flash.events.TimerEvent;
import flash.utils.Timer;
import fl.transitions.Tween;
import fl.transitions.easing.*;

var tempo1:Timer = new Timer(33); //30 times a seconds or so
    tempo1.addEventListener(TimerEvent.TIMER, tick);
    var curTickTime:int = 4000;

    tempo1.start();

    function tick(e:TimerEvent):void {
        if(tempo1.delay * tempo1.currentCount >= curTickTime){
            trace("tick"); //this should effectively be a tick
            tempo1.reset();
            tempo1.start();

            //do whatever you do on a tick
        }
    }

//tween the tick delay from the starting value to 100ms over a period of 5 seconds
var tween:Tween = new Tween(this, "curTickTime", Strong.easeOut, curTickTime, 100, 5, true);