Package com.jme3.app
Class SimpleApplication
java.lang.Object
com.jme3.app.LegacyApplication
com.jme3.app.SimpleApplication
- All Implemented Interfaces:
Application,SystemListener
`SimpleApplication` is the foundational base class for all jMonkeyEngine 3 (jME3) applications.
It provides a streamlined setup for common game development tasks, including scene management,
camera controls, and performance monitoring.
By default, `SimpleApplication` attaches several essential AppState instances:
StatsAppState: Displays real-time frames-per-second (FPS) and detailed performance statistics on-screen.FlyCamAppState: Provides a convenient first-person fly-by camera controller, allowing easy navigation within the scene.AudioListenerState: Manages the audio listener, essential for 3D sound.DebugKeysAppState: Enables debug functionalities like displaying camera position and memory usage in the console.ConstantVerifierState: A utility state for verifying constant values, primarily for internal engine debugging.
Default Key Bindings:
- Esc: Closes and exits the application.
- F5: Toggles the visibility of the statistics view (FPS and debug stats).
- C: Prints the current camera position and rotation to the console.
- M: Prints memory usage statistics to the console.
Applications extending `SimpleApplication` should implement the
simpleInitApp() method to set up their initial scene and game logic.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FlyByCameraprotected BitmapTextprotected BitmapFontprotected Nodestatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected static final Loggerprotected Nodeprotected booleanFields inherited from class com.jme3.app.LegacyApplication
assetManager, audioRenderer, cam, context, guiViewPort, inputEnabled, inputManager, joyInput, keyInput, listener, lostFocusBehavior, mouseInput, paused, prof, renderer, renderManager, settings, speed, stateManager, timer, touchInput, viewPort -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a `SimpleApplication` with a predefined set of defaultAppStateinstances.SimpleApplication(AppState... initialStates) Constructs a `SimpleApplication` with a custom array of initialAppStateinstances. -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the `FlyByCamera` instance associated with this application.Retrieves the `Node` dedicated to 2D graphical user interface (GUI) elements.Retrieves the root `Node` of the 3D scene graph.floatgetSpeed()Returns the current speed multiplier of the application.voidDo not call manually.booleanChecks whether the settings dialog is configured to be shown at application startup.protected BitmapFontCreates the font that will be set to the guiFont field and subsequently set as the font for the stats text.voidsetDisplayFps(boolean show) Controls the visibility of the frames-per-second (FPS) display on the screen.voidsetDisplayStatView(boolean show) Controls the visibility of the comprehensive statistics view on the screen.voidsetShowSettings(boolean showSettings) Sets whether the jME3 settings dialog should be displayed before the application starts.voidsetSpeed(float speed) Changes the application's speed multiplier.abstract voidvoidAn optional method that can be overridden by subclasses for custom rendering logic.voidsimpleUpdate(float tpf) An optional method that can be overridden by subclasses for per-frame update logic.voidstart()Starts the application indisplaymode.voidstop(boolean waitFor) Requests the context to close, shutting down the main loop and making necessary cleanup operations.voidupdate()Do not call manually.Methods inherited from class com.jme3.app.LegacyApplication
createCanvas, destroy, destroyInput, enqueue, enqueue, gainFocus, getAppProfiler, getAssetManager, getAudioRenderer, getCamera, getContext, getDisplays, getGuiViewPort, getInputManager, getListener, getLostFocusBehavior, getPrimaryDisplay, getRenderer, getRenderManager, getStateManager, getTimer, getViewPort, handleError, isPauseOnLostFocus, loseFocus, requestClose, rescale, reshape, restart, runQueuedTasks, setAppProfiler, setAssetManager, setLostFocusBehavior, setPauseOnLostFocus, setSettings, setTimer, start, start, start, startCanvas, startCanvas, stop
-
Field Details
-
logger
-
INPUT_MAPPING_EXIT
- See Also:
-
INPUT_MAPPING_CAMERA_POS
- See Also:
-
INPUT_MAPPING_MEMORY
- See Also:
-
INPUT_MAPPING_HIDE_STATS
- See Also:
-
rootNode
-
guiNode
-
fpsText
-
guiFont
-
flyCam
-
showSettings
protected boolean showSettings
-
-
Constructor Details
-
SimpleApplication
public SimpleApplication()Constructs a `SimpleApplication` with a predefined set of defaultAppStateinstances. These states provide common functionalities like statistics display, fly camera control, audio listener, debug keys, and constant verification. -
SimpleApplication
Constructs a `SimpleApplication` with a custom array of initialAppStateinstances.- Parameters:
initialStates- An array of `AppState` instances to be attached to the `stateManager` upon initialization.
-
-
Method Details
-
start
public void start()Description copied from class:LegacyApplicationStarts the application indisplaymode.- Specified by:
startin interfaceApplication- Overrides:
startin classLegacyApplication- See Also:
-
getSpeed
public float getSpeed()Returns the current speed multiplier of the application. This value affects how quickly the game world updates relative to real time. A value of 1.0f means normal speed, 0.5f means half speed, 2.0f means double speed.- Returns:
- The current speed of the application.
-
setSpeed
public void setSpeed(float speed) Changes the application's speed multiplier. A `speed` of 0.0f effectively pauses the application's update cycle.- Parameters:
speed- The desired speed multiplier. A value of 1.0f is normal speed. Must be non-negative.
-
getFlyByCamera
Retrieves the `FlyByCamera` instance associated with this application. This camera allows free-form navigation within the 3D scene.- Returns:
- The `FlyByCamera` object, or `null` if `FlyCamAppState` is not attached or has not yet initialized the camera.
-
getGuiNode
Retrieves the `Node` dedicated to 2D graphical user interface (GUI) elements. Objects attached to this node are rendered on top of the 3D scene, typically without perspective effects, suitable for HUDs and UI.- Returns:
- The `Node` object representing the GUI root.
-
getRootNode
Retrieves the root `Node` of the 3D scene graph. All main 3D spatial objects and models should be attached to this node to be part of the rendered scene.- Returns:
- The `Node` object representing the 3D scene root.
-
isShowSettings
public boolean isShowSettings()Checks whether the settings dialog is configured to be shown at application startup.- Returns:
- `true` if the settings dialog will be displayed, `false` otherwise.
-
setShowSettings
public void setShowSettings(boolean showSettings) Sets whether the jME3 settings dialog should be displayed before the application starts.- Parameters:
showSettings- `true` to show the settings dialog, `false` to suppress it.
-
loadGuiFont
Creates the font that will be set to the guiFont field and subsequently set as the font for the stats text.- Returns:
- the loaded BitmapFont
-
initialize
public void initialize()Description copied from class:LegacyApplicationDo not call manually. Callback from ContextListener.Initializes the
Application, by creating a display and default camera. If display settings are not specified, a default 640x480 display is created. Default values are used for the camera; perspective projection with 45° field of view, with near and far values 1 and 1000 units respectively.- Specified by:
initializein interfaceSystemListener- Overrides:
initializein classLegacyApplication
-
stop
public void stop(boolean waitFor) Description copied from class:LegacyApplicationRequests the context to close, shutting down the main loop and making necessary cleanup operations. After the application has stopped, it cannot be used anymore.- Specified by:
stopin interfaceApplication- Overrides:
stopin classLegacyApplication- Parameters:
waitFor- true→wait for the context to be fully destroyed, false→don't wait
-
update
public void update()Description copied from class:LegacyApplicationDo not call manually. Callback from ContextListener.- Specified by:
updatein interfaceSystemListener- Overrides:
updatein classLegacyApplication
-
setDisplayFps
public void setDisplayFps(boolean show) Controls the visibility of the frames-per-second (FPS) display on the screen.- Parameters:
show- `true` to display the FPS, `false` to hide it.
-
setDisplayStatView
public void setDisplayStatView(boolean show) Controls the visibility of the comprehensive statistics view on the screen. This view typically includes details about memory, triangles, and other performance metrics.- Parameters:
show- `true` to display the statistics view, `false` to hide it.
-
simpleInitApp
public abstract void simpleInitApp() -
simpleUpdate
public void simpleUpdate(float tpf) An optional method that can be overridden by subclasses for per-frame update logic. This method is called during the application's update loop, after AppStates are updated and before the scene graph's logical state is updated.- Parameters:
tpf- The time per frame (in seconds), adjusted by the application's speed.
-
simpleRender
An optional method that can be overridden by subclasses for custom rendering logic. This method is called during the application's render loop, after the main scene has been rendered and before post-rendering for states. Useful for drawing overlays or specific rendering tasks outside the main scene graph.- Parameters:
rm- The `RenderManager` instance, which provides access to rendering functionalities.
-