How to install Slick2d?

半城伤御伤魂 提交于 2019-12-24 04:55:09

问题


Hi I'm trying to create a game using the LWJGL library and the Slick2D game library however when I attempt to run it I get an error. Here is my code:

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();

 }



}

And this is the error I get when running it:

Error: Could not find or load main class path>.native.<macosx>

Though no errors come up inside the code before running, and I don't know where I should look to fix this as it appears to be a path error. Thanks.


回答1:


How to install Slick 2D

  • Download Slick from the official website: http://slick.ninjacave.com/

  • Import the externals JARs ibxm.jar, lwjgl.jar, slick.jar. They are on slick/lib.

  • Unzip your natives library, for example natives-linux if you use linux.

  • Create a folder inside your project and past it your unzipped natives library.

  • If your IDE haven't create automaticly the link to your natives library, do it.

Don't miss the 4th and the 5th parts or you can have an error like that:

Error: Could not find or load main class path>.native.<macosx>

Example for the last step with Eclipse:

Now that should work. Your code work fine for me, but you haven't set the number of FPS so my CPU work at 100%.

You can try to run this program:

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
    {

    }
}


来源:https://stackoverflow.com/questions/27009101/how-to-install-slick2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!