# 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 method | Purpose
--- | ---
context | The 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.
viewPort | The view object for the default camera.
guiViewPort | The 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.
timer | Internal update loop timer. Users have access to the tpf float variable in the simpleUpdate() loop to time actions.
cam | The 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.
inputEnabled | Set 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.
paused | Set 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:

- Display – jME application runs in a window of its own. This is the Default.
- Canvas – jME application is embedded in a Swing Canvas)
- Headless – jME application runs its event loop without calculating any view and without opening any window. Can be used for a Headless Server application.
- OffscreenSurface – jME application view is not shown, but calculated and cached as bitmap (back buffer).

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 Feature | Purpose
--- | ---
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:

Key | Action
--- | ---
KEY_ESCAPE | Quits the game by calling `app.stop()`
KEY_C | Prints camera position, rotation, and direction
KEY_M | Prints memory usage stats

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

Camera Motion | Key or Mouse Input
--- | ---
Move Forward | KEY_W
Move Left (Strafe) | KEY_A
Move Backward | KEY_S
Move Right (Strafe) | KEY_D
Move Vertical Upward | KEY_Q
Move Vertical Downward | KEY_Z
Rotate Left | KEY_LEFT, or move mouse horizontally left (-x)
Rotate Right | KEY_RIGHT, or move mouse horizontally right (+x)
Rotate Up | KEY_UP, or move mouse vertically forward (+y)
Rotate Down | KEY_DOWN, or move mouse vertically backward (-y)
Zoom In | Scroll mouse wheel backward
Zoom Out | Scroll mouse wheel forward
Rotate drag | Hold left mouse button and move

display, basegame, documentation, intro, intermediate, init, input, game, loop, rootnode

view online version