to estudando criação de games, tava criando Spritesheet mas não to conseguindo importar a classe, pois não aparece a opção de importar a classe e se faço manualmente tb da erro.
package game01;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import com.gcstudios.entities.Entity; // ERRO!
import com.gcstudios.graficos.SpriteSheet; //ERRO!
public class Game01 extends Canvas implements Runnable {
//atributo da Classe JFrame, para criar a jenale.
public static JFrame frame;
// ???
private Thread thread;
private boolean isRuning = true;
private final int WIDTH =560;
private final int HEIGHT = 520;
private final int SCALE = 1;
private BufferedImage image;
public List<Entity> entities;
public Spritesheet spritesheet; //ERRO!
// Metodo construtor da janela!
public Game01(){
/* Instancira um objeto game! "Constroi um objeto".
* Apesar dos atributos serem privados na classe Game o metodo
* construtor tem acesso a les, pois ele e publico!
*/
this.setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
initFrame();
// Inicializar objetos !!
image = new BufferedImage(WIDTH,HEIGHT, BufferedImage.TYPE_INT_RGB);
entities = new ArrayList<Entity>();
spritesheet = new Spritesheet();
}
public void initFrame(){
frame = new JFrame("Marcos RPG");
frame.add(this);
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
//Metodo para começar a rodar o jogo
public synchronized void start(){
thread = new Thread(this);
// ??
isRuning= true;
thread.start();
}
public synchronized void stop(){
// metodo para garantir que as treds parem
isRuning = false;
try {
// metodo para garantir que as treds parem
thread.join();
} catch (InterruptedException ex) {
}
}
public static void main(String[] args) {
// Instancia a clase construtora e cria um novo objeto q é a janela do jogo!
Game01 game = new Game01();
game.start();
}
// tick (atualiza o jogo) e o render (gera a imagem) é necessario para rodar o luping
public void tick(){
// Luping
for (int i = 0; i < entities.size(); i ++){
Entity e = entities.get(i);
e.tick();
}
}
public void render(){
BufferStrategy bs = this.getBufferStrategy();
if (bs == null){
this.createBufferStrategy(3);
return;
}
Graphics g = image.getGraphics();
// aqui eu tenho uma imagem q posso desenhar oq que quizer
g.setColor(new Color(16,16,16));
g.fillRect(0, 0,WIDTH, HEIGHT);
// Luping
for (int i = 0; i < entities.size(); i ++){
Entity e = entities.get(i);
e.render(g);
}
//e deposi renderizar na tela!
g.dispose();
g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, WIDTH*SCALE,HEIGHT*SCALE, null);
bs.show();
}
public void run() {
//Game luping profisional
long lestTime = System.nanoTime();
double amountOfTicks =60.0;
double ns = [telefone removido] / amountOfTicks;
double delta = 0;
//vai mostrar se o jogo esta rodando mesmo em 60 fps
int frames = 0;
double timer = System.currentTimeMillis();
while(isRuning){
long now = System.nanoTime();
delta+= (now - lestTime)/ns;
lestTime = now;
if (delta > 1){
tick();
render();
frames++;
delta--;
}
if(System.currentTimeMillis()- timer >= 1000){
System.out.println("FPS: "+frames);
frames = 0;
timer += 1000;
}
}
// naoe obrigadoa ter stop, e so uma forma de garantir que as treads parem!
stop();
}
}