【发布时间】:2014-04-30 16:53:04
【问题描述】:
我对 Java 还很陌生,目前正在开发一个小游戏,只是为了测试我能用 Java 做什么。但是遇到了一个随机问题:我不知道如何制作 GUI(单人游戏、多人游戏、选项...的菜单)和 HUD(值 [生命、法力、经验...] 的图形显示)已经说过:我正在使用库 jinput、lwjgl、lwjgl_util 和 Slick2D。我的窗口是通过 lwjgl 的 Display 类呈现的。这是我的 Main.class 代码:
public class Main
{
public static int disWidth = 800;
public static int disHeight =600;
public static void main(String[] args)
{
initDisplay();
initGL();
initGame();
gameLoop();
// initGui();
cleanUp();
}
private static void initGame()
{
Game.game = new Game();
}
private static void getInput()
{
Game.game.getInput();
}
private static void initGui()
{
//Render the gui
}
private static void update()
{
Game.game.update();
// GUI.gui.update() or something
}
private static void render()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
Game.game.render();
Display.update();
Display.sync(60);
}
private static void initGL()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Display.getWidth(), 0, Display.getHeight(), -1, 1);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glClearColor(0, 0, 0, 0);
}
private static void gameLoop()
{
Time.init();
int frames = 0;
long lastTime = System.nanoTime();
long totalTime = 0;
while(!Display.isCloseRequested())
{
long now = System.nanoTime();
long passed = now - lastTime;
lastTime = now;
totalTime += passed;
if(totalTime >= 1000000000)
{
System.out.println(frames);
totalTime = 0;
frames = 0;
}
Time.update();
getInput();
update();
render();
frames++;
}
}
private static void cleanUp()
{
Display.destroy();
Keyboard.destroy();
}
private static void initDisplay()
{
try
{
Display.setDisplayMode(new DisplayMode(disWidth, disHeight));
Display.create();
Keyboard.create();
}
catch (LWJGLException ex)
{
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
【问题讨论】:
标签: java user-interface interface 2d lwjgl