2012-12-19 32 views
3

我想在油滑區做一個遊戲,在我開始之前我想測試我將要使用的直升機動畫。它剛剛打開,然後立即關閉這些錯誤:油滑的動畫 - 每幀必須有一個持續時間

線程「main」中的異常java.lang.RuntimeException:每幀必須有一個持續時間 at org.newdawn.slick.Animation。(Animation.java:111 ) at javagame.Menu.init(Menu.java:22) at javagame.Game.initStatesList(Game.java:19) at org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:170) 在org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:433) at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:357) at javagame.Game.main(Game.java:29)

這裏是我的代碼:

package javagame; 

import org.newdawn.slick.*; 
import org.newdawn.slick.state.*; 
import org.newdawn.slick.tests.AnimationTest; 


public class Menu extends BasicGameState { 

     Animation sprite, fly; 


    public Menu(int state){ 

     } 

     public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{ 
      Image [] flyanimation = {new Image("res/copter1.png"), new Image("res/copter2.png"), 
        new Image("res/copter3.png"), new Image("res/copter4.png")}; 
      int [] duration = {300, 300}; 

      fly = new Animation(flyanimation, duration, false); 
      sprite = fly; 
     } 

     public void render(GameContainer gc, StateBasedGame sbg, Graphics g)throws SlickException{ 
      sprite.draw(150, 150); 
     } 

     public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{ 
      Input input = gc.getInput(); 
      if(input.isKeyDown(Input.KEY_SPACE)){ 
       sprite = fly; 
       sprite.update(delta); 
      } 
     } 

     public int getID(){ 
      return 0; 
     } 
    } 

感謝您的幫助!如果我完全錯了我如何去做這件事,我很抱歉。我找不到一個體面的教程來拯救我的生命!

回答

3

的問題是,你正在過動畫構造4張圖片,只有2持續時間值,試試這個:

   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{ 
     Image [] flyanimation = {new Image("res/copter1.png"), new Image("res/copter2.png"), 
       new Image("res/copter3.png"), new Image("res/copter4.png")}; 
     int [] duration = {300, 300, 300, 300}; 

     fly = new Animation(flyanimation, duration, false); 
     sprite = fly; 
    }