Slick is a 2D game library for Java. It is far superior to Java’s own 2D engine: Slick is hardware accelerated, cross-platform compatible, and designed with game development in mind. It’s based on the popular LWJGL library which runs the top Java games out there like Minecraft and Revenge of the Titans.
This guide will show you how to properly setup Slick2D in Netbeans so you can start making your own games. Unlike other tutorials, you will be updated to the most current build of Slick and LWJGL. This will solve a variety of known issues such as sound incompatibility and poor performance.
It is assumed that you already know how to use Netbeans and have the latest Java Development Kit installed on your computer. I do suggest using the older JDK 5 if your audience could potentially be on a Mac. A significant number of my Mac testers are stuck on the outdated version of Java because they don’t have the latest OS X. Also, Apple has traditionally been behind by an entire version when releasing their own runtime environment. This may change in the immediate future but it is what we have to deal with for the time being.
It’s necessary to get the nightly build because the official release is grossly outdated. Extract the Slick zip to an easily accessible location on your computer like “C:\Slick\”. Even though the nightly build is newer, the LWJGL files in the nightly build are still outdated. This can be solved by overwriting the LWJGL files in your slick folder with the new ones. Open the LWJGL zip and open the jar folder. Copy these files and paste them into the Slick “lib” folder, overwriting the old files.
The next thing we need is a folder of native files so that Netbeans can run your game. We do not want to use the native files that came with Slick because they are tied to the outdated version of LWJGL that you just overwrote. Open the LWJGL zip and copy the “native” folder to your Slick folder so you can find it easily later. The native jar files in the lib folder you created also need to be updated. Copy the native files from each operating system into their corresponding jar file (ie. from “native/windows/” to “lib/natives-win32.jar”). This can be done using any archive software like Win-Rar.
Start Netbeans and go to Tools >> Libraries. Click on New Library. Set the library name to “Slick” and click “OK”. Ensure that the Classpath tab is selected and click “Add JAR/Folder…”. Browse to the slick folder you made earlier and select the “lib” folder. Click the sources tab and click “Add JAR/Folder…” again. This time, select the “src” folder.
Now you can make a new project for your game. Create a new blank project. Ensure that your project is selected, then click on File >> Project Properties. Select “Libraries” from the list on the left. Click on “Add Library” and select “Slick”. You also need to set arguments so that you can run your game from Netbeans. In the properties window, choose “Run” on the left. In the VM Options field enter the path to the natives folder for your operating system: