您好我正在尝试使用LWJGL库和Slick2D游戏库创建游戏,但是当我尝试运行它时出现错误。这是我的代码:
package test;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
public class SetupClass extends BasicGame {
public SetupClass(String title) {
super(title);
// TODO Auto-generated constructor stub
}
@Override
public void init(GameContainer container) throws SlickException {
// TODO Auto-generated method stub
}
@Override
//Delta is the amount of time that has passed since the last update
public void update(GameContainer container, int delta) throws SlickException {
// TODO Auto-generated method stub
}
@Override
public void render(GameContainer container, Graphics arg1) throws SlickException {
// TODO Auto-generated method stub
}
//need to handle throwing slick exception so we handled it through main throwing slickexception
public static void main(String[] args) throws SlickException {
//Create a new game container named app under a new SetupClass named Setup Test
AppGameContainer app = new AppGameContainer(new SetupClass("Setup Test"));
//arguments 1 and 2 are resolution of window by height and width
//3rd argument is the boolean determining whether it is full screen
app.setDisplayMode(800, 600, false);
//Start the app
app.start();
}
}
这是我在运行时遇到的错误:
Error: Could not find or load main class path>.native.<macosx>
虽然在运行之前代码中没有出现错误,但我不知道应该在哪里修复它,因为它似乎是一个路径错误。感谢。
答案 0 :(得分:1)
从官方网站下载Slick:http://slick.ninjacave.com/
导入外部JARs ibxm.jar,lwjgl.jar,slick.jar。他们是光滑的/ lib。
解压缩您的本机库,例如natives-linux如果您使用linux。
在项目中创建一个文件夹,然后将其解压缩为解压缩的本机库。
如果您的IDE无法自动创建指向本机库的链接,请执行此操作。
不要错过第4和第5部分,否则您可能会遇到这样的错误:
Error: Could not find or load main class path>.native.<macosx>
Eclipse的最后一步示例:
现在应该可行。您的代码对我来说罚款,但您还没有设置FPS的数量,因此我的CPU工作在100%。
您可以尝试运行此程序:
import java.awt.Dimension;
import java.awt.Toolkit;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
public class Test extends BasicGame
{
private static Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
public Test()
{
super("Game");
}
public static void main(String[] arguments)
{
try
{
AppGameContainer app = new AppGameContainer(new Test());
// app.setDisplayMode(screenSize.width, screenSize.height, true); => Full screen
app.setDisplayMode(640, 480, false);
app.setShowFPS(false); // true for display the numbers of FPS
app.setVSync(true); // false for disable the FPS synchronize
app.start();
}
catch (SlickException e)
{
e.printStackTrace();
}
}
public void init(GameContainer container) throws SlickException
{
}
public void update(GameContainer container, int delta) throws SlickException
{
}
public void render(GameContainer container, Graphics g) throws SlickException
{
}
}