Skip to main content
Participant
October 29, 2016
Beantwortet

How to make 'game over' appear when timer hits 0 AS3

  • October 29, 2016
  • 2 Antworten
  • 1964 Ansichten

So I am new to using Animate and AS3 and I can't find how to make  'game over'  appear on the screen when the timer runs out. I am making an escape game and I have made a timer that countdowns from 90 seconds but when it gets to 0 I want it to say game over. Instead it does nothing.

Here is the Actionscript I have used for my timer:

//Timer

var nCount:Number = 90;

var myTimer:Timer = new Timer(1000, nCount);

timer_txt.text = nCount.toString();

myTimer.start();

myTimer.addEventListener(TimerEvent.TIMER, countdown);

function countdown(e:TimerEvent):void

{

nCount--;

timer_txt.text = nCount.toString();

}

But what do I need to add in order to make 'game over' pop up when the timer hits 0? I have also created the game over screen on the second frame on the timeline.

Thanks!

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von Ned Murphy

function countdown(e:TimerEvent):void

{

     nCount--;

     timer_txt.text = nCount.toString();

     if(nCount == 0){

          myTimer.stop();

          myTimer.removeEventListener(TimerEvent.TIMER, countdown);

          gotoAndStop(2);

     }

}

2 Antworten

Ned Murphy
Legend
October 30, 2016

You're welcome

Ned Murphy
Ned MurphyAntwort
Legend
October 29, 2016

function countdown(e:TimerEvent):void

{

     nCount--;

     timer_txt.text = nCount.toString();

     if(nCount == 0){

          myTimer.stop();

          myTimer.removeEventListener(TimerEvent.TIMER, countdown);

          gotoAndStop(2);

     }

}

Participant
October 29, 2016

Thank you!