如何安装Slick2d? [英] How to install Slick2d?

查看:371
本文介绍了如何安装Slick2d?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用LWJGL库和Slick2D游戏库创建一个游戏,但是当我尝试运行它时,我收到一个错误。这是我的代码:

 包测试; 

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自动生成的构造函数stub
}

@Override
public void init(GameContainer container)throws SlickException {
// TODO Auto-生成的方法stub

}

@Override
// Delta是自上次更新以来已经过去的时间
public void update(GameContainer container,int delta)throws SlickException {
// TODO自动生成的方法存根

}

@Override
public void render(GameContainer container,图形arg1)throws SlickException {
// TODO自动生成的方法存根

}
//需要处理抛出的光滑异常,所以我们通过主抛出的slickexception处理它
public static void main(String [] args)throws SlickException {
//在名为Setup Test的新SetupClass下创建一个名为app的新游戏容器
AppGameContainer app = new AppGameContainer(new SetupClass(Setup Test ));
//参数1和2是窗口的高度和宽度的分辨率
//第三个参数是布尔确定是否是全屏
app.setDisplayMode(800,600,false);
//启动app
app.start();

}



}

这是运行它时所得到的错误:

 错误:找不到或加载主类路径> ; .native< MacOSX的> 

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

解决方案

如何安装Slick 2D




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


  • 导入外部JARs ibxm.jar,lwjgl.jar,slick.jar。他们在slick / lib上。


  • 解压您的本地图书馆,例如,如果您使用linux,则为natives-linux。


  • 在项目中创建一个文件夹,并将其解压缩到您的解压缩的本机库。


  • 如果您的IDE没有自动创建链接




不要错过第4和第5部分或您可能会出现以下错误:

 错误:找不到或加载主类路径> .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 ());
// app.setDisplayMode(screenSize.width,screenSize.height,true); =>全屏
app.setDisplayMode(640,480,false);
app.setShowFPS(false); // true显示FPS
app.setVSync(true)的数字; // false禁用FPS同步
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
{

}
}


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.

解决方案

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
    {

    }
}

这篇关于如何安装Slick2d?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆