2011-10-24 5 views
0
public function SeedsAndPots() 

    { 
     startpage = new StartPage(); 
     addChild(startpage); 

     buttonPage = new ButtonPage(); 
     addChild(buttonPage); 
     buttonPage.addEventListener(MouseEvent.CLICK, GoToGame);  

    } 
    public function GoToGame(e:MouseEvent):void 
    { 
     removeChild(startpage); 
     buttonPage.removeEventListener(MouseEvent.CLICK, GoToGame); 
     removeChild(buttonPage); 
     gamePage = new GamePage(); 
     addChild(gamePage); 

    } 

//時間が0の場合、私は自分のGameOver-Pageに行ってください。
}
}Timcounterに0(Flash Builder)が表示されているとき、メインクラスにGameOver-Pageを追加するにはどうすればよいですか?

答えて

0

時間を秒単位で反映するようにカウントダウン変数を作成します。

ゲームページを毎秒カウントダウンするときにタイマーをインスタンシエートします。

時間が0になったら、ロジックを適用して現在のレベルを終了し、ページ上にゲームを表示します。

// store time remaining in a countdown timer 
    protected var countdown:uint = 60; 

    // create a timer, counting down every second 
    protected var timer:Timer; 

    // in your go to game, or when you want to start the timer  
    public function GoToGame(e:MouseEvent):void 
    { 
     // ... your go to game function 

     // start your countdown timer. 
     timer = new Timer(1000); 
     timer.addEventListener(TimerEvent.TIMER, timerHandler); 
     timer.start(); 
    } 

    protected function timerHandler(event:TimerEvent):void 
    { 
     // countdown a second 
     --countdown; 

     // update any counter time text field display here... 

     // if you've reached 0 seconds left 
     if(countdown == 0) 
     { 
      // stop the timer 
      timer.removeEventListener(TimerEvent.TIMER, timerHandler); 
      timer.reset(); 

      // remove current gamePage 
      // addChild to your game over page. 
     } 
    } 
+0

ありがとう、私はそのコードを試してみよう... –

関連する問題