bom gente, eu estou começando a aprender sobre programação, e me deparei co um problema que estou rachando a cabeça para resolver…
criei uma imagem em png com o meu personagem, e coloquei em um construtor o codigo para chamar e coloca-lo n a tela, o app abre normal, não sei se o erro estrá no codigo do construtor, no codigo de renderização ou no caminho da imagem! alguem me ajuda!
codigo construtor:
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class spritesheet {
public BufferedImage sprites;
public spritesheet(String path) {
try {
sprites = ImageIO.read(this.getClass().getResource(path));
} catch (IOException e) {
e.printStackTrace();
}
}
public BufferedImage getSprite(int x, int y, int h, int w) {
return sprites.getSubimage(x, y, w, h);
}
}
codigo de renderização:
private static spritesheet sheet;
private static BufferedImage Player;
public static void main(String[]args) {
sheet = new spritesheet("/spritesh.png");
Player = sheet.getSprite(0, 0, 64,64 );
}
public void dust() {
BufferStrategy bufs = this.getBufferStrategy();
if(bufs == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = imagem.getGraphics();
g.setColor(new Color(120,120,120));
g.fillRect( 0,0, largura*4,altura*4);
g.drawImage(Player, 20, 20,null);
g = bufs.getDrawGraphics();
g.drawImage(imagem,0,0, largura*4, altura*4, null);
bufs.show();
}