oi galera, to tentando cria sprite aqui no java mas tive um erro no meu código alguém pode me ajudar sou novo no java.
minha classe principal botei maior parte do codigo;
o erro ta dando em sheet = Spritesheet("/res/mls.png");
diz q tenho q criar um método, mas eu ja fiz a chamada da classe como método.
package game;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
// canvas e uma biblioteca q contem a s propriedades da janela
public class Game extends Canvas implements Runnable{
public static JFrame frame;
private Thread thread;
private boolean isRunning = true;
// largura da janela!
private final int WIDTH = 850;
// altura da janela!
private final int HEIGHT = 550;
// lergura e altura da tela multiplicado por 3!
private final int SCALE = 1;
private BufferedImage image;
private Spritesheet sheet;
//??
public Game(){
sheet = Spritesheet("/res/mls.png");
setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
initFrame();
image = new BufferedImage(WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
}
public void initFrame(){
frame = new JFrame("Meu Jogo!");
frame.add(this);
frame.setResizable(false);
//frame .pack vai fazer a chamada das dimençoes da tela!
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
// metodo
public synchronized void start(){
thread =new Thread(this);
isRunning= true;
thread.start();
}
public synchronized void stop(){
isRunning = false;
try {
thread.join();
} catch (InterruptedException ex) {
}
}
public static void main(String[] args) {
Game game = new Game();
game.start();
}
public void tick(){
}
public void render(){
BufferStrategy bs = this.getBufferStrategy();
if(bs==null){
this.createBufferStrategy(3);
return;
}
Graphics g = image.createGraphics();
g.setColor(new Color(0,0,0));
g.fillRect(0, 0,WIDTH,HEIGHT);
g.setFont(new Font("Arial",Font.BOLD,20));
g.setColor(Color.white);
g.drawString("Está pronto para o RPG?", 20,20);
g = bs.getDrawGraphics();
g.drawImage(image,0,0,WIDTH*SCALE,HEIGHT*SCALE, null);
bs.show();
}
public void run() {
long lestTime = System.nanoTime();
double amountofTicks = 60.0;
double ns =[telefone removido] / amountofTicks;
double delta = 0;
// para mostrar os fremes
int frames = 0;
double time = System.currentTimeMillis();
while(isRunning){
long now = System.nanoTime();
delta+= (now-lestTime)/ns;
lestTime= now;
if(delta>=1){
tick();
render();
frames++;
delta--;
}
// para mostrar os frames por segundo!
if(System.currentTimeMillis() - time >= 100){
System.out.println("fps= "+frames);
frames = 0;
time+= 1000;
}
}
stop();
}
}
minha classe!!!
package game;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
public class Spritesheet {
private BufferedImage spritesheet;
public Spritesheet(String path){
try {
spritesheet = ImageIO.read(getClass().getResource(path));
} catch (IOException ex) {
}
}
public BufferedImage getSprite(int x,int y,int width, int height){
return spritesheet.getSubimage(x, y,width,height);
}
}