【问题标题】:How to install Slick2d?如何安装 Slick2d?
【发布时间】:2015-05-19 04:46:17
【问题描述】:

您好,我正在尝试使用 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>

虽然在运行之前代码中没有出现错误,但我不知道我应该在哪里解决这个问题,因为它似乎是一个路径错误。谢谢。

【问题讨论】:

    标签: java eclipse game-engine slick2d buildpath


    【解决方案1】:

    如何安装 Slick 2D

    • 从官网下载Slick:http://slick.ninjacave.com/

    • 导入外部 JAR ibxm.jar、lwjgl.jar、slick.jar。它们在 slick/lib 上。

    • 解压缩您的 natives 库,例如,如果您使用 linux,则为 natives-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
        {
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多