Adding time to a timer/counter
Posted
by
BoneStarr
on Stack Overflow
See other posts from Stack Overflow
or by BoneStarr
Published on 2011-11-28T13:48:35Z
Indexed on
2011/11/28
17:56 UTC
Read the original article
Hit count: 329
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!
© Stack Overflow or respective owner