Saturday, March 31, 2018

Simple Arcade Game 1: Installing JME

Welcome to part 1 of making a simple arcade game in jMonkey Engine! In this series we are going to look at making a simple top down game about herding sheep. The focus of these tutorials will be primarily on learning how to use JME to accomplish simple game mechanics and get you started on a project of your own. We'll cover topics such as app states, controls, the scene graph, transforms in 3d space, the asset pipeline and any other topics that crop up while we are finishing this simple game. Before we can dive into writing our first game, we need to get jMonkey Engine to run!

JME is a java library, and of course you will need a version of jdk found here. I'll assume you have at least jdk8 installed for these tutorials.

The simplest way to work with jMonkey Engine is to install the latest community SDK. The JME SDK is a customized version of the Netbeans IDE with some very helpful features that will make working with JME much simpler. It is possible to use your own IDE, or even a text editor and compile on your own, but for this series I will assume you are using the provided SDK and it's helpful JME integrations.

Go ahead and download the jMonkey SDK here.

If you are wondering why my screenshots look different, it's because I use the awesome "DarkMonkey" plugin available under "Tools/Plugins" You may want to look through what plugins are available and see if there are any that interest you or might make development easier.

Once you have the SDK installed you will need to create a new project. In the top left go to "File/New Project..." under Categories choose "JME3" and under Projects choose "Basic Game."



Click Next and choose a name for the project and a folder to store all the project files in. I am naming this project "SheepTut" and storing it in a folder on my secondary drive. Be sure you have access to the folder you choose as you will be adding and removing files often.

Now you have your project created, it should be visible on the left under the "Projects" tab. If for some reason you don't see the projects tab, go to "Windows/Projects" or press "CTRL-1" to open a new projects tab. I keep this docked on the left side for convenience. If you open up all of the project folders you should see something like this:

If your source packages and libraries look different, right click in a blank area in the Projects tab and select "View Java Packages As..." and select "Reduced Tree."

So what are we looking at here? Well first is the Project Assets folder. This folder will be packaged inside the .jar file when you build the project and is where you will be storing all of your game assets, 3d models, textures, sound files, etc. It comes pre-filled with some sub-folders which are all empty by default. This is fine, we'll be adding our own files soon enough.

Next is the Source Packages. These are all of your Java class files and where you will actually be building your game. Right now it has 1 package called "mygame" with 1 Main class. Feel free to create a new package if you would prefer something more descriptive. Java convention states packages should be named after their "reverse internet domain name" so I'll go ahead and create a new package called "com.mrugames." and click and drag the Main class into my new package.


When clicking and dragging a java class it will ask if you wish to refactor, click yes to let the SDK handle formatting the class to it's new package.

The next thing listed in your project tab is the Libraries. This contains all the jMonkey Engine libraries you will need to run your game, as well as your JDK libraries for the version of Java that is installed. If you wish to change the JDK simply right click on your project, go to properties and under Source/Binary file select the JDK you wish to use. If you do not see the version of JDK you were hoping to use and it is installed on your system, then go to Tools/Java Platforms, Add Platform and follow the wizard to locate your JDK.

The last folder listed is called "Important Files." This contains your build file which you will probably not need to edit. The SDK should be able to modify this file for you as needed through project properties. If you do find yourself needing to modify the build script, this is the quickest way to find it.

Now that you are familiar with the jMonkey project, let's open the Main class that was generated an run it! Simply double click Main.java and you will be greeted with a class that extends Simple Application and has 4 methods, a main(), a simpleInitApp(), a simpleUpdate() and a simpleRender(). You should be able to press Run Project(F6) and be greeted by the jMonkeyEngine splash screen!



Press continue to finally run your first jMonkey Engine game:


Congrats! You managed to get jMonkey Engine SDK to run and created your first project! If you had any difficulties getting this far feel free to leave a comment either here, on this blog or at the jMonkey Engine forum where either myself or someone from the super helpful community can point you in the right direction.

Next time we will take a closer look at the Simple Application class, the BaseAppState class and how jMonkey handles frame updates!