Application and SimpleApplication

The base classes of the jMonkeyEngine3 are com.jme3.app.Application and its subclass com.jme3.app.SimpleApplication. SimpleApplication extends Application, and offers everything that Application offers, plus pre-configured features such as a scene graph and a flyby cam. Your game class typically extends com.jme3.app.SimpleApplication. You call app.start() and app.stop() on your game instance to start or quit the application. The following code sample shows the typical base structure of a jME3 game:

import com.jme3.app.SimpleApplication;
public class HelloWorld extends SimpleApplication {
    public static void main(String[] args){
        HelloWorld app = new HelloWorld();
        app.start();
    }
    @Override
    public void simpleInitApp() {
       /* Initialize the game scene here */
    }
    @Override
    public void simpleUpdate(float tpf) {
       /* (optional) Interact with game events in the main loop */
    }
    @Override
    public void simpleRender(RenderManager rm) {
       /* (optional) Make advanced modifications to frameBuffer and scene graph. */
    }
}

Let's have a look at what the base classes have to offer.

Application Class

The com.jme3.app.Application class represents an instance of a real-time 3D rendering jME3 application. A com.jme3.app.Application provides all the tools that are commonly used in jME3 applications.

Class field or methodPurpose
contextThe application context contains renderer, AppSettings, timer, etc. The context object is not usually directly accessed by users.
getRenderManager()
getRenderer();
Low-level and high-level rendering interface.
getStateManager()The Application state manager is used to activate physics.
viewPortThe view object for the default camera.
guiViewPortThe view object for the orthogonal GUI view. Used internally for HUDs.
settings
setSettings()
The AppSettings let you specify the display width and height (by default 640x480), color bit depth, z-buffer bits, anti-aliasing samples, and update frequency, video and audio renderer, asset manager.
timerInternal update loop timer. Users have access to the tpf float variable in the simpleUpdate() loop to time actions.
camThe default camera with perspective projection, 45° field of view, near plane = 1 wu, far plane = 1000 wu.
assetManager
getAssetManager()
An object that manages paths for loading models, textures, materials, sounds, etc. By default the AssetManager paths are relative to your projects root directory.
getAudioRenderer()
getListener()
The audio system.
keyInput
mouseInput
joyInput
Default input contexts for keyboard, mouse, and joystick
getInputManager()Use the inputManager to configure your custom inputs.
inputEnabledSet this boolean whether the system should listen for user inputs (or instead just play a non-interactive scene).
setPauseOnLostFocus()Set this boolean whether the game should pause when ever the window loses focus.
pausedSet this boolean during runtime to pause/unpause a game.
start()
start(jMEContextType)
Call this method to start a jME3 game. By default this opens a new jME3 window, initializes the scene, and starts the event loop. Can optionally accept com.​jme3.​system.​JmeContext.Type.* as argument to run headless or embedded. (See below.)
restart()Reloads the AppSettings into the current application context.
stop()Stops the running jME3 game and closes the jME3 window.

The jME Context Type (com.​jme3.​system.​JmeContext.Type.*) is one of the following:

You can switch Context Types when starting the application, for example: app.start(JmeContext.Type.Headless); See also: AppSettings

SimpleApplication Class

The com.jme3.app.SimpleApplication class extends the com.jme3.app.Application class to provide default functionality like a first-person (fly-by) camera, and a scenegraph with a rootNode that is updated and rendered regularly. By default, a SimpleApplication displays statistics (such as frames per second) on-screen, using the com.jme3.app.StatsView class. You deactivate the statistics HUD by calling app.setDisplayFps(false); app.setDisplayStatView(false);. Some input keys are pre-configured by default: You quit the application by pressing the Escape key, and you can control the camera using the mouse, the arrow keys, and WASD keys. (More details below.) Additional to what Application offers, SimpleApplication offers:

SimpleApplication FeaturePurpose
getRootNode()
rootNode
The root node of the scene graph. A Spatial that you attach to the rootNode appears in the 3D scene.
getGuiNode()
guiNode
Attach flat GUI elements (such as HUD images and text) to this orthogonal GUI node.
loadStatsView()Call this method to print live statistic information to the screen, such as current frames-per-second and triangles/vertices counts. Use this info during the development phase.
setDisplayFps(false);
setDisplayStatView(false);
Call these method to remove the statistic information from the screen, for example, before releases.
getFlyByCamera()
flyCam
The default fly-by camera object, controlled by the WASD and arrow keys.
setShowSettings(true)Whether the user should be presented with a splashscreen and display settings dialog when starting the game. Set this boolean before calling start() on the SimpleApplication.
simpleInitApp()Override this method to initialize the game scene. Here you load and create objects, attach Spatials to the rootNode, and bring everything in its starts position.
simpleUpdate(float tpf)Override this method to have access to the main event loop. Use this loop to poll the current game state and respond to changes, or to initiate state changes and to generate encounters. For advanced info how to hook into the update loop, see also Application States and Custom Controls.
simpleRender()Optionally, override this method to do advanced modifications to the frameBuffer and scene graph.

Input Defaults

The following default actions are available for a running game:

KeyAction
KEY_ESCAPEQuits the game by calling app.stop()
KEY_CPrints camera position, rotation, and direction
KEY_MPrints memory usage stats

If useInput() is true, the default Flyby Cam is active. Then the following so-called "WASD" inputs are additionally available:

Camera MotionKey or Mouse Input
Move ForwardKEY_W
Move Left (Strafe)KEY_A
Move BackwardKEY_S
Move Right (Strafe)KEY_D
Move Vertical UpwardKEY_Q
Move Vertical DownwardKEY_Z
Rotate LeftKEY_LEFT, or move mouse horizontally left (-x)
Rotate RightKEY_RIGHT, or move mouse horizontally right (+x)
Rotate UpKEY_UP, or move mouse vertically forward (+y)
Rotate DownKEY_DOWN, or move mouse vertically backward (-y)
Zoom InScroll mouse wheel backward
Zoom OutScroll mouse wheel forward
Rotate dragHold left mouse button and move
display, basegame, documentation, intro, intermediate, init, input, game, loop, rootnode

view online version