斯利克动画 - 必须有每帧时长 [英] Slick Animation - There must be one duration per frame
问题描述
我试图做一个游戏的油滑,我开始之前,我想测试我将使用直升机动画。它只是打开,然后立即用这些错误关闭:
I am trying to make a game in Slick, and before I start I want to test the helicopter animation I will be using. It just opens and then immediately closes with these errors:
在异常线程主了java.lang.RuntimeException:必须有每帧时长
在org.newdawn.slick.Animation(Animation.java:111)
在javagame.Menu.init(Menu.java:22)
在javagame.Game.initStatesList(Game.java:19)
在org.newdawn.slick.state.StateBasedGame.init(StateBasedGame.java:170)
在org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:433)
在org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:357)
在javagame.Game.main(Game.java:29)
Exception in thread "main" java.lang.RuntimeException: There must be one duration per frame 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) at org.newdawn.slick.AppGameContainer.setup(AppGameContainer.java:433) at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:357) at javagame.Game.main(Game.java:29)
下面是我的code:
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;
}
}
感谢您的帮助!如果我是完全错误的,我怎么会对此,我很抱歉。我便无法找到一个体面的教程救我一命!
Thanks for the help! If I am completely wrong on how I am going about this, I am sorry. I could't find a decent tutorial to save my life!
推荐答案
的问题是,你正在过动画的构造函数4张图片和2只duration值试试这个:
the problem is that you are passing the Animation constructor 4 Images and only 2 duration values, try this:
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;
}
这篇关于斯利克动画 - 必须有每帧时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!