私はゲームを始めましたが、何か問題があります。実際には何も表示されず、どちらもエラーが表示されません。それだけでそれを実行し、何もしない。ここでの主なゲームを始めよう
package Game;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class Game extends Canvas implements Runnable{
private static final long serialVersionUID
= 1550691097823471818L;
public static final int WIDTH = 640, HEIGHT = WIDTH/12*9;
private Thread thread;
private boolean running = false;
public Game(){
new Window(WIDTH, HEIGHT, "TITLE OF THAE GAME", this);
}
public synchronized void start(){
thread = new Thread(this);
thread.start();
running = true;
}
public synchronized void stop(){
try{
thread.join();
running = false;
}catch(Exception e){
e.printStackTrace();
}
}
public void run(){
long lastTime = System.nanoTime();
double amoutOfTicks = 60.0;
double ns = 1000000000.0/amoutOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int frames = 0;
while(running){
long now = System.nanoTime();
delta += (now-lastTime)/ns;
lastTime = now;
while (delta>=1){
tick();
delta--;
}
if(running)
render();
frames++;
if(System.currentTimeMillis() - timer > 1000){
timer += 1000;
System.out.println("FPS: "+ frames);
frames = 0;
}
}
stop();
}
private void tick(){
}
private void render(){
BufferStrategy bs = this.getBufferStrategy();
if(bs == null){
this.createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.dispose();
bs.show();
}
public static void main(String[] args){
}
}
ある
CLASS
package Game;
import java.awt.Canvas;
import java.awt.Dimension;
import javax.swing.JFrame;
public class Window extends Canvas{
private static final long serialVersionUID = -2408406005333728354L;
public Window(int height, int width, String title, Game game){
JFrame tit = new JFrame(title);
tit.setPreferredSize(new Dimension(width, height));
tit.setMaximumSize(new Dimension(width, height));
tit.setMinimumSize(new Dimension(width, height));
tit.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //It make the game close up to the end without bugs
tit.setResizable(false); //not able to resize
tit.setLocationRelativeTo(null); //put the frame in the middle of the screen, originaly it starts up left
tit.add(game); // adding pur game class to the frame
tit.setVisible(true); //to make it visible
game.start(); // makes the game start
}
}
実は、私は理解していないものがあり、それはserialVersionUID
次のとおりです。ここで
私はこれらのコードを(コピーされた)ビルドに使うソースです。
ありがとうございます。
あなたの 'main'メソッドは空です。それはあなたがプログラムを始めるときに実行されるものです。そこに何もない場合、プログラムは起動するとすぐに終了します。 – resueman
新しいゲーム();あなたがメインで必要なものすべてです。 – eldo