Reputation: 193
Well, I have two TIMER type variables in my code AS3, but there comes a certain part of my game, I have to decrement the value of them.
var tempo1:Timer = new Timer(4000);
var tParada:Timer = new Timer(2000, 1);
I wonder how can I do to go decrementing these values, starting from an external class ...
Thank U.
Upvotes: 0
Views: 174
Reputation: 14406
Just decriment the delay every time the timer fires.
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;
}
}
Or, if wanted it smoother, you could do something like this:
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);
Upvotes: 1