Hey everyone So I have a countdown timer that I have managed to implement in my game that I saw on some forums. Now I set up a new function to add some seconds to the timer whenever the user Hittest with a Movie Clip but it doesnt seem to work right the errors I'm getting is while it does add more time, It's not really adding it because when i do add more time and say the timer counts down to 10 depending on how much more seconds I added with the Hittest the game ends on 10 rather than 0 seconds. So I don't think its actually changing the time interval internally.
Also when I restart the game it shows the past time for the one second interval then once it starts counting down it finally resets and starts counting down normally.
Here is how I have it setup:
My initialized variables in my constructor:
count = 30; //Count down from 60
myTimer = new Timer(1000, count);// Timer intervall in ms
myTimer.addEventListener(TimerEvent.TIMER, countdown);//EventListener for intervalls
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, countdownComplete);
myTimer.start();//start Timer
The countDown function:
private function countdown(e:TimerEvent):void
{
//Display Time in a textfield on stage
countDownTextField.text = String((count)- myTimer.currentCount);
updateCountdownTimer();
}
In my HitTest Function:
private function onPopIsClicked(pop:DisplayObject):void
{
nScore ++;
updateHighScore();
updateCurrentScore();
//Add Explosion Effect
popExplode = new mcPopExplode();
stage.addChild(popExplode);
popExplode.y = mPop.y;
popExplode.x = mPop.x;
elapsedTime += 5;
updateCountdownTimer();
}
Then finally in my updateCountdownTimer():
public function updateCountdownTimer():void
{
countDownTextField.text = String((count)- myTimer.currentCount + elapsedTime);
}
Can you see why I can't add more seconds to the timer correctly?
Thanks in advance.
**** UPDATE ******
count = 10; //Count down from 10
myTimer = new Timer(1000, count);// Timer intervall in ms
updateCountdownTimer();
myTimer.addEventListener(TimerEvent.TIMER, countdown);//EventListener for intervalls
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, countdownComplete);
myTimer.start();//start Timer
private function countdown(e:TimerEvent):void
{
//Display Time in a textfield on stage
updateCountdownTimer();
}
private function onPopIsClicked(pop:DisplayObject):void
{
elapsedTime += 2;
myTimer.repeatCount += elapsedTime; //add time to the timer
count += elapsedTime;
updateCountdownTimer();
trace("pop clicked and time");
}
public function updateCountdownTimer():void
{
countDownTextField.text = String((count)- myTimer.currentCount);
}