zoukankan      html  css  js  c++  java
  • Slick, Phys2D, LWJGL, and Eclipse

    http://n3wt0n.com/blog/slick-phys2d-lwjgl-and-eclipse/

    ——————————————————————————————————————————————————————

    This guide will be as straight-to-the-point as can be. Please note, I make an example of the Linux version in this setup, but you can substitute the instructions for Windows or Mac if that is what you use.

    Purpose

    Create an Eclipse project that uses Slick, Phys2D and LWJGL.

    Requirements

    1. Slick – website – Download the “full distribution” slick.zip (~ 9.8 MB)
    2. LWJGL – website – I prefer to use the “last stable build” from the project repository (currently 2.2.0, ~ 3.6 MB)
    3. Phys2D – website – Download the latest build (current build 2008-04-06, ~ 100 KB)

    Procedure

    This is a personal preference, but I rename the Phys2D download. It downloads as phys2d-060408.jar, so I rename it phys2d.jar.

    Next, extract/unzip the slick.zip file, it doesn’t matter where. We will import the files into the Eclipse workspace later anyway.

    Open up Eclipse and start a new project.

    File >> New >> Java Project

    Presumably, you know your way around Eclipse so I will not help with the specifics of creating a project.

    Now that the project is created, create a new folder called lib in the project.

    File >> New >> Folder Click the project name Folder name: lib

    Next, we import Slick and Phys2D into the project.

    Right click lib >> Left click Import >> General >> File System >> Next Browse to the unzipped slick directory and find the slick/lib folder >> OK Select the following jar files
    • jogg-0.0.7.jar
    • jorbis-0.0.15.jar
    • lwjgl.jar
    • slick.jar
    Click Finish

    You’ve imported Slick, now we import Phys2D.

    Right click lib >> Import >> General >> File System >> Next Browse to the location you put phys2d.jar >> OK Select phys2d.jar >> Finish

    Now your lib folder should have those five jar files in them. Just about done.

    We need to add the jar files into the project build path.

    Right click the Project >> Properties On the left, make sure Java Build Path is selected. Click the Libraries tab >> Add JARs Expand the Project Expand lib Select all of the jar files in the lib directory >> OK >> OK

    You should now see a new directory in the Package Explorer called Referenced Libraries. The project is incomplete without first attaching the native libraries to lwjgl.jar. To do that, we first import those native libraries into the project.

    Right click lib >> Import >> General >> Archive File Browse to the unzipped slick directory and select slick/lib/natives-linux.jar >> OK >> Finish Do the same for natives-win32.jar and natives-mac.jar (if you wish to support those operating systems)

    Next, we attach those native libraries to the lwjgl.jar file.

    Expand Referenced Libraries Right click lwjgl.jar >> Properties Select Native Library at the left of that window Location path: >> Workspace Expand the Project Select lib >> OK >> Apply >> OK

    Now you are ready to build your awesome game.

    But wait, what about using the latest version of lwjgl? We skipped that step.

    Right. We did. As of right now, we’re using the the version of LWJGL that came packaged with Slick. However, some users might run into a problem with LWJGL, particularly if you’re using Ubuntu 9.04 (like I am). At this point, if I were to try to compile a Slick program, I would end up with this error:

    Failed to initialise the LWJGL display

    The solution to which is to use the latest LWJGL native Linux libraries.

    Extract that last stable build of LWJGL that you downloaded (lwjgl-2.2.0.zip). In Eclipse, Right click lib >> Import >> File System >> Next Browse to the unzipped lwjgl-2.2.0 directory, to lwjgl-2.2.0/native/linux >> OK Select all of the .so files (all of the files in the directory) >> Finish Yes To All when asked to overwrite files

    Not entirely done yet. Trying to compile now would result in the following error:

    Version mismatch: jar version is '16', native libary version is '17'

    So we replace the old lwjgl.jar with the new. Find it at lwjgl-2.2.0/jar/lwjgl.jar. Import it into the lib folder of the project. You know how to do that by now. Compile and run again and all should be well.

    P.S. You are done with all the extra unzipped directories and zip files, etc. Everything needed to run your project has been imported into Eclipse. They can be deleted if you so choose.

    Update: It seems that now there is an additional problem, as follows.

    java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

    The solution was found at the jMonkeyEngine forums. You need to tell the lwjgl.jar where it can find the native libraries so it can run. Basically it calls for

    Right click the project >> Properties >> Java Build Path >> Libraries Expand lwjgl.jar Select Native Library >> Edit Click Workspace Expand the project Click lib >> OK >> OK
    1. ArmoredSandwich
      July 19th, 2010 at 10:59 | #1

      Awesome, thanks!

    2. nico
      January 2nd, 2012 at 12:33 | #2

      If you do all these steps in a User Library you can reuse the same User Library for all your projects, no need to repeat all these steps every time you start a new project.

    3. nico
      January 2nd, 2012 at 13:12 | #3

      And your final remark, the java.lang.UnsatisfiedLinkError, is caused because you incorrectly linked the natives-*.jar to lwjgl.jar. It’s enough to include the natives-*.jar on the classpath like the other libraries, and instead put the native location of lwjgl.jar to the directory which contains the .ddl files.

    4. sonicbroom
      March 3rd, 2012 at 09:11 | #4

      brilliant! thanks for sharing this information. i know these things take time!

     ————————————————————————————————————————————————————————————————————————

    发现一个问题:如果native路径下直接放jar包(natives-win32.jar等) ,还是java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path

    必须将包里的文件解开,然后放到native路径下。

    ——————————————————————————————————
    傲轩游戏网
  • 相关阅读:
    Evaluate Reverse Polish Notation(逆波兰表达式)
    PostreSQL linux添加psql 命令
    C#用文件流读取cvs内容并返回DataTable,并把第一行设为列名
    鹅鹅鹅饿饿
    编译器和解释器
    delphi之多线程编程
    Arduino 板子 COM 接口找不到设备
    JS事件冒泡
    vi编辑器的使用(2)
    vi编辑器的使用(1)
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2381661.html
Copyright © 2011-2022 走看看