(For more resources related to this topic, see here.)
What is Slick2D?
Slick2D is a multi-platform library for two dimensional game development that sits upon the LWJGL(Light-Weight Java Game Library). Slick2D simplifies the processes of game development such as game loop, rendering, updating, frame setup, and state-based game creation. It also offers some features that LWJGL does not, such as particle emitters and integration with Tiled (a map editor).
Developers of all skill levels can enjoy Slick2D, as it offers a degree of simplicity that you can’t find in most libraries. This simplicity not only makes it a great library for programmers but artists as well, who may not have the technical knowledge to create games in other libraries.
Downloading the Slick2D and LWJGL files
The Slick2D and LWJGL jar files, plus the LWJGL native files, are needed to create a Slick2D game project. The only system requirement for Slick2D is a Java JDK. To get the files, we perform the following steps:
- Obtaining the LWJGL files:
- Navigate to http://www.lwjgl.org/download.php.
- Download the most recent stable build.
- The .zip file will include both the LWJGL jar file and the native files. (This .zip file will be referenced as lwjgl.zip file.)
- Obtaining the Slick2D files:
- Due to hosting issues, the Slick2D files are being hosted by a community member at http://slick.ninjacave.com. If this site is not available, follow the alternative instructions at step 3.
- Click on Download.
- Alternative method of obtaining the Slick2D files:
- Navigate to https://bitbucket.org/kevglass/slick.
- Download the source.
- Build the ant script located at slick/trunk/Slick/build.xml
- Build it in eclipse or command line using $ ant.
Setting up an eclipse project
We will utilize the Eclipse IDE that can be found at http://www.eclipse.org/ when working with Slick2D in this article. You may, however, utilize other options.
Perform the following these steps to set up a Slick2D project:
- Navigate to File | New | Java Project.
- Name your project and click on Finish.
- Create a new folder in your project and name it lib.
- Add two subfolders named jars and native.
- Place both lwjgl.jar and slick.jar in the jars subfolder inside our eclipse project.
- Take all the native files from lwjgl.zip and place them in the native subfolder.
Copy the contents of the subfolders inside native from lwjgl.zip not the subfolders themselves.
- Right-click on project then click on Properties.
- Click on Java Build Path and navigate to the Libraries tab.
- Add both the jars from the project.
- Select and expand lwjgl.jar from the Libraries tab and click on Native library location: (None) then click on Edit and search the workspace for the native’s folder.
The native files included in lwjgl.zip are platform-specific libraries that allow the developers to make one game that will work on all of the different platforms.
What if I want my game to be platform-specific?
No real benefit exists to being platform-specific with Slick2D. In the foregoing tutorial, we will establish a game as a multi-platform game. However, if you want your game to be platform-specific, you can make it platform-specific. In the previous tutorial (step 6) we took the content of each operating system’s folder and put that content into our native folder. If, instead, you desire to make your game platform-specific, then instead of copying the contents of these folders, you would copy the entire folder as illustrated as follows:
When defining the natives for LWJGL (step 10 in previous example), simply point towards the operating system of your choice.
In this article we learned tons of important things necessary to create a project in Slick2D. So far we covered:
- Downloading the necessary library files
- Setting up a project (platform-specific or multi-platform)
- Native files
Resources for Article:
- HTML5 Games Development: Using Local Storage to Store Game Data [Article]
- Adding Sound, Music, and Video in 3D Game Development with Microsoft Silverlight 3: Part 2 [Article]
- Adding Finesse to Your Game [Article]