我對使用外部Java庫非常陌生,我開始使用基於LWJGL的Slick2D。我寫了一個簡單的StateBasedGame,它只是在屏幕上打印三個選項。儘管關於一些(jar?)文件不存在,它給了我一個錯誤(參見下面的參考資料)。LWJGL 2代碼與LWJGL 3代碼不兼容?
這讓我想起了一個事實,即我遇到的大部分教程都是在一兩年前製作的,當時LWJGL 3還沒有出來或者還不穩定。這意味着他們都使用LWJGL 2.問題是,我嘗試使用LWJGL 3的許多代碼不能用最初寫在LWJGL 2中的代碼工作。爲什麼?如果我想學習SLick2D,轉回LWJGL 2是否是個好主意?請幫忙,因爲我編寫的簡單程序甚至不編譯。
這裏是我的代碼無法(至少在LWJGL 3)工作:
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
public class Game extends StateBasedGame {
Menu menu;
public Game(String title) {
super(title);
menu = new Menu(0);
}
public static void main(String[] args) {
try {
AppGameContainer agc = new AppGameContainer(new Game("Text Based"));
agc.setDisplayMode(600, 600, false);
agc.start();
} catch (SlickException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void initStatesList(GameContainer container) throws SlickException {
System.out.println("InitStates");
addState(new Menu(0));
getState(menu.getID()).init(container, this);
enterState(menu.getID());
}
}
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class Menu extends BasicGameState {
private int ID;
private int menu;
public Menu(int id) {
this.ID = id;
}
@Override
public void init(GameContainer container, StateBasedGame sbg) throws SlickException {
}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
g.setColor(Color.white);
g.drawString("Higher or Lower", 50, 10);
g.drawString("1. Play Game", 50, 100);
g.drawString("2. High Scores", 50, 120);
g.drawString("3. Quit", 50, 140);
}
@Override
public void update(GameContainer arg0, StateBasedGame arg1, int arg2) throws SlickException {
}
@Override
public int getID() {
return ID;
}
}
以下是錯誤:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl64 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:72)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:87)
at org.lwjgl.Sys.<clinit>(Sys.java:117)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at Game.main(Game.java:17)
好的,謝謝!這爲我解決了很多問題,因爲我無法找到任何lwjgl64.dll文件,而我可以找到一個lwjgl32.dll文件。我很高興你現在告訴我,因爲這一切對我來說都沒有意義。 – Eames