jMonkeyEngine 3 Tutorial (1) - Hello SimpleApplication

In this tutorial series, we assume that you use the jMonkeyEngine SDK. As an intermediate or advanced Java developer, you will quickly see that, in general, you can develop jMonkeyEngine code in any integrated development environment (NetBeans IDE, Eclipse, IntelliJ) or even from the command line.

OK, let's get ready to create our first jMonkeyEngine3 application.

Create a Project

In the jMonkeyEngine SDK:

Choose File→New Project… from the main menu.

In the New Project wizard, select the template JME3→Basic Game. Click Next.

Specify a project name, e.g. “HelloWorldTutorial”

Specify a path where to store your new project, e.g. a jMonkeyProjects directory in your home directory.

We recommend to go through the steps yourself, as described in the tutorials. Alternatively, you can create a project based on the JmeTests template in the jMonkeyEngine SDK. It will create a project that already contains the jme3test.helloworld samples (and many others). For example, you can use the JmeTests project to verify whether you got the solution right.

Extend SimpleApplication

For this tutorial, you want to create a jme3test.helloworld package in your project, and create a file HelloJME3.java in it.

In the jMonkeyEngine SDK:

Right-click the Source Packages node of your project.

Choose New…→Java Class to create a new file.

Enter the class name: HelloJME3

Enter the package name: jme3test.helloworld.

Click Finish.

The SDK creates the file HelloJME3.java for you.

Sample Code

Replace the contents of the HelloJME3.java file with the following code:

Look at the FPS text and object count information in the bottom left. You will use this information during development, and you will remove it for the release. (To read the numbers correctly, consider that the 14 lines of text counts as 14 objects with 914 vertices.)

Press Escape to close the application.

Congratulations! Now let's find out how it works!

Understanding the Code

The code above has initialized the scene, and started the application.

Start the SimpleApplication

Look at the first line. Your HelloJME3.java class extends com.jme3.app.SimpleApplication.

publicclass HelloJME3 extends SimpleApplication {// your code...}

Every JME3 game is an instance of the com.jme3.app.SimpleApplication class. The SimpleApplication class is the simplest example of an application: It manages a 3D scene graph, checks for user input, updates the game state, and automatically draws the scene to the screen. These are the core features of a game engine. You extend this simple application and customize it to create your game.

You start every JME3 game from the main() method, as every standard Java application:

The app.start(); line opens the application window. Let's learn how you put something into this window (the scene) next.

Understanding the Terminology

What you want to do

How you say that in JME3 terminology

You want to create a cube.

I create a Geometry with a 1x1x1 Box shape.

You want to use a blue color.

I create a Material with a blue Color property.

You want to colorize the cube blue.

I set the Material of the Box Geometry.

You want to add the cube to the scene.

I attach the Box Geometry to the rootNode.

You want the cube to appear in the center.

I create the Box at the origin = at Vector3f.ZERO.

If you are unfamiliar with the vocabulary, read more about the Scene Graph here.

Initialize the Scene

Look at rest of the code sample. The simpleInitApp() method is automatically called once at the beginning when the application starts. Every JME3 game must have this method. In the simpleInitApp() method, you load game objects before the game starts.