我正在使用slick2d我遇到过这个问题,我无法让这个精灵表动画完全使用更新功能尝试了大部分方法。
package javagame;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Play extends BasicGameState{
Image worldMap;
boolean quit = false;
int[] duration = {200,200};
float monsterPositionX = 0;
float monsterPositionY = 0;
float shiftX = monsterPositionX +320;
float shiftY = monsterPositionY +160;
public Image monsterImage = null;
public SpriteSheet monsterSheet;
public Animation monster;
public Animation monsterAnimationDown;
public Animation monsterAnimationUp;
public Animation monsterAnimationLeft;
public Animation monsterAnimationRight;
public Play(int state){
}
public void init(GameContainer gc, StateBasedGame sbg)throws SlickException{
monsterImage = new Image("/res/Monster.png");
monsterSheet = new SpriteSheet(monsterImage, 64 , 64);
monsterAnimationUp = new Animation(monsterSheet, 0,8,8,8,true,200,false);
monsterAnimationLeft = new Animation(monsterSheet, 0,9,8,9,true,200,false);
monsterAnimationDown = new Animation(monsterSheet, 0,10,8,10,true,200,false);
monsterAnimationRight = new Animation(monsterSheet, 0,11,8,11,true,200,false);
monster = monsterAnimationDown;
}
//renders images to screen0
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)throws SlickException{
monster.draw(shiftX,shiftY);
if(quit == true){
g.drawString("Resume (R)", 250, 100);
g.drawString("Main Menu (M)", 250, 150);
g.drawString("Quit Game (Q)", 250, 200);
if(quit == false){
g.clear();
}
}
}
// changes translations of game objects
public void update(GameContainer gc, StateBasedGame sbg, int delta)throws SlickException{
Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_W)){
monster = monsterAnimationUp;
monster.setPingPong(true);
monsterPositionY += delta *.1f;
}else if(input.isKeyDown(Input.KEY_S)){
monster = monsterAnimationDown;
monsterPositionY -= delta *.1f;
} else if(input.isKeyDown(Input.KEY_D)){
monster = monsterAnimationRight;
monsterPositionX += delta *.1f;
}else if(input.isKeyDown(Input.KEY_A)){
monster = monsterAnimationLeft;
monsterPositionX -= delta *.1f;
}
if(input.isKeyDown(Input.KEY_W)&& input.isKeyDown(Input.KEY_D)){
monster = monsterAnimationUp;
monster.setPingPong(true);
monsterPositionY += delta *.1f;
monsterPositionX += delta *.1f;
}if(input.isKeyDown(Input.KEY_W)&& input.isKeyDown(Input.KEY_A)){
monster = monsterAnimationUp;
monster.setPingPong(true);
monsterPositionY += delta *.1f;
monsterPositionX -= delta *.1f;
}if(input.isKeyDown(Input.KEY_S)&& input.isKeyDown(Input.KEY_D)){
monster = monsterAnimationDown;
monster.setPingPong(true);
monsterPositionY -= delta *.1f;
monsterPositionX += delta *.1f;
}if(input.isKeyDown(Input.KEY_S)&& input.isKeyDown(Input.KEY_A)){
monster = monsterAnimationDown;
monster.setPingPong(true);
monsterPositionY -= delta *.1f;
monsterPositionX -= delta *.1f;
}
}
}
你能提供一种让动画有效的方法吗?
答案 0 :(得分:0)
我不习惯这种方法,但也许你必须start the animation。
然后,您应该通过在更新方法中提供增量来更新动画对象。
在 @profile = Profile.new(profile_params)
if @profile.save
# ...
else
# ...
end
:
Play.update
希望这有帮助