0
我使用slick2d我遇到過這個問題,我無法讓這個精靈表動畫的所有我已經嘗試使用大多數的方法更新功能。我不能讓我的動畫發揮我使用slick2d和64 64通過
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;
}
}
}
您能否提供一種方法使動畫能夠正常工作?