I’ve looked all over the web and everyone can teach you how to make a timer for your game or a countdown, but I can’t seem to find out how to add time to an already counting timer.
So here is my counter class:
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.text.TextField;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
public class Score extends MovieClip
{
public var second:Number = 0;
public var timer:Timer = new Timer(100);
private var stageRef:Stage;
public function Score(stageRef:Stage)
{
x = 560.95;
y = 31.35;
this.stageRef = stageRef;
timer.addEventListener(TimerEvent.TIMER, scoreTimer);
timer.start();
}
public function scoreTimer(evt:TimerEvent):void
{
second += 1;
scoreDisplay.text = String("Score: " +second);
}
That works without any issues or problems and just keeps counting upwards at a speed of 100ms, what I want to know is how to add say 30 seconds if something happens in my game, say you kill an enemy for example.
Please help!
This can be as simple as calling a method which updates your
secondproperty. Your methods would end up looking something like this.Because you don’t use your
timer‘s values for updating the display, a reset or delay won’t adjust your scoreDisplay. Instead it will just keep on counting where it left off because thesecondproperty itself is not reset during these actions.