Tuesday, April 15, 2014

Slick2D Tutorial: Getting set up.


Let's make a game in Java!

Java is a fun language to use. It's easy to learn and pretty straightforward. Slick2D is a pretty fun library, though outdated and unsupported, it's actually pretty good.

So without further text lets jump right in.

The first this we need to do is to set up our IDE of choice. I would suggest Netbeans, as it is a easy to use IDE that isn't bad like some IDE's out there (I'm looking at you Eclipse).

If you go to Oracle's website (over here) you can download the most recent version of the Java Development Kit (JDK) and Netbeans bundled together (as of writing 8 and 8.0 respectively).

Now for the hard part. We need to download all of the libraries and setup a Netbeans project. Most of this tutorial is following this one, if you want you can just look at that and skip to the next tutorial. EDIT: The other website seems to be down...

First you need to obtain the libraries. Slick2D can be obtained at slick.ninjacave.com. Slick2D is a library built on top of the Lightweight Java Game Library (LWJGL for short). If you read the website, you'll notice that Slick2D contains LWJGL 2.9.0. However, there is a more recent version of LWJGL (2.9.1) available  at lwjgl.org. The actual download link is on Sourceforge. You need to download lwjgl-2.9.1.zip (or the latest version). You can also optionally download the javadoc and sources as well (named lwjgl-docs-2.9.1.zip and lwjgl-source-2.9.1.zip respectively).

Now that we have our two libraries we need to create our project. Open Netbeans and press Ctrl-Shift-N to create a new project. Select 'Java Application' in the first menu (the default) and name it whatever you want. Deselect both options.

Now to add the libraries to the project. First unzip the downloads. Right click the project and click on 'Properties'. Go to 'Libraries.' Click 'Add JAR/Folder.' Go to where you downloaded the library and select "slick/lib/slick.jar." Also select "lwjgl-2.9.1/jar/lwjgl.jar."

Now for the final step: You need to configure Java to know where your natives are. Natives are the *.dll files that come with LWJGL. Right click the project, go to Properties -> Run -> VM Options. Enter

-Djava.library.path="[path to libraries]\lwjgl-2.9.1\native\[osname]

// For me that looks like:
-Djava.library.path="E:\GitHub\SharedLibraries\lwjgl-2.9.1\native\windows"

This tells Java to look in that directory for natives. Natives are code written and compiled into OS-specific langauges.

Now you're done setting up your project! We can actually start writing the code (when I get around to the next tutorial).

Feel free to comment with any questions, comment, or suggestions.