import java.awt.Canvas;
public class GSM extends Canvas implements Runnable {
//The game state manager
public final long secondNS = 1000000000;
public final long frameNS = secondNS/60;
public boolean running = true;
public long now = System.nanoTime();
public long startTime = now;
public long lastFrame = now;
public long lastSecond = now;
public int frames = 0;
public void run()
{
System.out.println("Program started.");
while(running)
{
now = System.nanoTime();
if(now - lastFrame >= frameNS)
{
lastFrame = now;
frames++;
}
if(now - lastSecond >= secondNS)
{
lastSecond = now;
System.out.println(frames);
frames = 0;
}
}
}
public static void main(String[] args)
{
new GSM();
}
}
刚开始制作游戏引擎,但程序马上终止。有人可以指出错误吗?我知道有一些缺失,这将是超级明显的,我要facepalm,我感谢你的帮助。谢谢!程序在运行前终止?
你真的需要从学习基础开始。即使是一个简单的游戏引擎也是一个复杂的软件,你还没有专业知识。从更简单的项目开始,继续前进。 – chrylis 2014-08-28 22:54:56
你知道即使你创建了一个'Thread'来运行你的'Runnable',它不会在屏幕上显示任何GUI,因为它是一个'Canvas',对吧?而且,你正忙着在你的'while'循环中等待,这是一件坏事。 – 2014-08-28 23:08:35