Package com.jme3.app

Class SimpleApplication

java.lang.Object
com.jme3.app.LegacyApplication
com.jme3.app.SimpleApplication
All Implemented Interfaces:
Application, SystemListener

public abstract class SimpleApplication extends LegacyApplication
`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 Details

  • Constructor Details

    • SimpleApplication

      public SimpleApplication()
      Constructs a `SimpleApplication` with a predefined set of default AppState instances. These states provide common functionalities like statistics display, fly camera control, audio listener, debug keys, and constant verification.
    • SimpleApplication

      public SimpleApplication(AppState... initialStates)
      Constructs a `SimpleApplication` with a custom array of initial AppState instances.
      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: LegacyApplication
      Starts the application in display mode.
      Specified by:
      start in interface Application
      Overrides:
      start in class LegacyApplication
      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

      public FlyByCamera 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

      public Node 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

      public Node 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

      protected BitmapFont 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: LegacyApplication
      Do 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:
      initialize in interface SystemListener
      Overrides:
      initialize in class LegacyApplication
    • stop

      public void stop(boolean waitFor)
      Description copied from class: LegacyApplication
      Requests 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:
      stop in interface Application
      Overrides:
      stop in class LegacyApplication
      Parameters:
      waitFor - true→wait for the context to be fully destroyed, false→don't wait
    • update

      public void update()
      Description copied from class: LegacyApplication
      Do not call manually. Callback from ContextListener.
      Specified by:
      update in interface SystemListener
      Overrides:
      update in class LegacyApplication
    • 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

      public void simpleRender(RenderManager rm)
      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.