2014-02-10 108 views
-1

我正在開發基於回合的雙人遊戲。顯示動畫並重新啓動遊戲

我想要什麼: - 當有人獲勝時,動畫彈出窗口及其顯示播放器1或2獲勝。然後在遊戲重新啓動後等待2秒。

我得到: - 動畫彈出窗口好了,它等待2秒,但之後顯示完成的遊戲板,即遊戲未重新啓動。

animation.java

public void onAnimationEnd(Animation animation) 
{ 
    // Take any action after completing the animation 
    // check for fade in animation 
    if (animation == ani) 
    { 
     //Toast.makeText(getApplicationContext(), "Animation Stopped", 
      // Toast.LENGTH_SHORT).show(); 
     Thread.currentThread(); 
     try 
     { 
      Thread.sleep(2000); 
      finish(); 
     } 
     catch (Exception e) 
     { 

     } 

    } 

} 

gameboard.java

public void winner(int x) 
    { 
        int a=gameArray[x]; 

     Intent i = new Intent(this, animation.class); 
     i.putExtra("winner", a); 
     startActivity(i); 

    } 

我試過,不工作: -

gameboard.java

public void winner(int x) 
    { 
        int a=gameArray[x]; 

     Intent i = new Intent(this, animation.class); 
     i.putExtra("winner", a); 
     startActivity(i); 
        Thread.currentThread(); 
     try 
     { 
      Thread.sleep(2000); 
      finish(); 
        Intent b= new Intent(this, gameboard.class); 
        startActivity(b); 
     } 
     catch (Exception e) 
     { 

     } 

    } 

雖然這樣做動畫根本不顯示,遊戲線程在任何玩家獲勝後都會休眠。但是2秒後遊戲重新開始。

我使用canvas.drawLine繪製了名爲drawBoard()的方法。我該怎麼辦。

回答

0

查看Android SDK中的Timer類。這是一個專門的線程。你可以簡單地把你正在做的任務作爲TimerTask對象來實現。我自己使用它來運行動畫引擎。查看以下方法的API。希望這可以幫助!!!

Timer.schedule(TimerTask task, long delay) 
+0

這正是我一直在尋找。謝謝。 – Mohit