Olá sou novo aqui no forum
e novo tbm na linguagem java
estou desenvolvendo um jogo 2d
para fins de estudo e estou tendo um problema
estoou utilizando as libs do slick2d e estou com problemas na animação de um sprite sheet
a sprite sheet é 4 x 4 (colunas/linhas) ou seja em uma linha ele olha pra cima
outra para baixo e as outras duas ele olha pro lado
se eu apenas construo o personagem e nao jogo um novo valor para a linha
ele anima(anda), mas a partir do momento em que eu jogo um valor para ele trocar a linha da imagem(direção do personagem)
ele nao anima mais.
package test;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
public class SetupClass extends BasicGame {
private Personagem personagem;
static int dy;
static int dx;
static int anima;
public SetupClass(String title) {
super(title);
}
public void init(GameContainer container) throws SlickException {
personagem = new Personagem();
}
public void update(GameContainer container, int delta) throws SlickException {
//CAPTAÇÃO DE MOVIMENTOS D O TECLADO
//EM FIM FUNCIONANDO
Input input = container.getInput();{
if (input.isKeyDown(Input.KEY_DOWN)) {
dy = 1;
anima = 0;
} else if (input.isKeyDown(Input.KEY_UP)) {
dy = -1;
anima = 120;
} else if (input.isKeyDown(Input.KEY_LEFT)) {
dx = -1;
anima = 40;
} else if (input.isKeyDown(Input.KEY_RIGHT)) {
dx = 1;
anima = 80;
} else {
dy = 0;
dx = 0;
}
personagem.atualizarPosicao(anima);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
personagem.mexer();
}
public static int getAnima() {
return anima;
}
public static int getDy() {
return dy;
}
public static int getDx() {
return dx;
}
public void render(GameContainer container, Graphics g) throws SlickException {
g.drawAnimation(personagem.getLuffy(), personagem.getX(), personagem.getY());
}
public static void main(String[] args) throws SlickException {
AppGameContainer app = new AppGameContainer(new SetupClass("Setup test"));
app.setDisplayMode(800, 600, false);
app.start();
}
}
package test;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
public class Personagem {
private SpriteSheet sprite = null;
static Animation luffy = null;
private static Image imagem = null;
public Personagem () throws SlickException {
//imagem = new Image("res//Luffy-TW2[1].png").getSubImage(0, 0, 132, 40);
// sprite = new SpriteSheet(imagem, 33, 40);
// luffy = new Animation(sprite, 300);
atualizarPosicao(SetupClass.getAnima());
}
private int x, y, dx, dy;
public void atualizarPosicao(int cordenadaLinha ) throws SlickException {
Personagem.imagem = new Image("res//Luffy-TW2[1].png").getSubImage(0, cordenadaLinha, 132, 40);
sprite = new SpriteSheet(imagem, 33, 40);
luffy = new Animation(sprite, 300);
}
public void mexer() throws SlickException {
x += SetupClass.getDx();
y += SetupClass.getDy();
if (this.x < 1) { // limites da tela
x = 1;
}
if (this.x > 500) {
x = 500;
}
if (this.y < 1) {
y = 1;
}
if (this.y > 500) {
y = 500;
}
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getDx() {
return dx;
}
public int getDy() {
return dy;
}
public Animation getLuffy() {
return luffy;
}
}
se alguem kiser baixar o fonte pra dar uma olhada
https://github.com/Feenux/Jogo
agradeço a todos que puderem me ajudar
lembrando que comecei a mexer com java a pouco tempo
e estou vendo alguns tutoriais pra aprender