Class ScreenshotAppState

java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.app.state.ScreenshotAppState
All Implemented Interfaces:
AppState, ActionListener, InputListener, SceneProcessor

public class ScreenshotAppState extends AbstractAppState implements ActionListener, SceneProcessor
  • Constructor Details

    • ScreenshotAppState

      public ScreenshotAppState()
      Using this constructor, the screenshot files will be written sequentially to the system default storage folder.
    • ScreenshotAppState

      public ScreenshotAppState(String filePath)
      This constructor allows you to specify the output file path of the screenshot. Include the separator at the end of the path. Use an empty string to use the application folder. Use NULL to use the system default storage folder.
      Parameters:
      filePath - The screenshot file path to use. Include the separator at the end of the path.
    • ScreenshotAppState

      public ScreenshotAppState(String filePath, String fileName)
      This constructor allows you to specify the output file path of the screenshot. Include the separator at the end of the path. Use an empty string to use the application folder. Use NULL to use the system default storage folder.
      Parameters:
      filePath - The screenshot file path to use. Include the separator at the end of the path.
      fileName - The name of the file to save the screenshot as.
    • ScreenshotAppState

      public ScreenshotAppState(String filePath, long shotIndex)
      This constructor allows you to specify the output file path of the screenshot and a base index for the shot index. Include the separator at the end of the path. Use an empty string to use the application folder. Use NULL to use the system default storage folder.
      Parameters:
      filePath - The screenshot file path to use. Include the separator at the end of the path.
      shotIndex - The base index for screenshots. The first screenshot will have shotIndex + 1 appended, the next shotIndex + 2, and so on.
    • ScreenshotAppState

      public ScreenshotAppState(String filePath, String fileName, long shotIndex)
      This constructor allows you to specify the output file path of the screenshot and a base index for the shot index. Include the separator at the end of the path. Use an empty string to use the application folder. Use NULL to use the system default storage folder.
      Parameters:
      filePath - The screenshot file path to use. Include the separator at the end of the path.
      fileName - The name of the file to save the screenshot as.
      shotIndex - The base index for screenshots. The first screenshot will have shotIndex + 1 appended, the next shotIndex + 2, and so on.
  • Method Details

    • setFilePath

      public void setFilePath(String filePath)
      Set the file path to store the screenshot. Include the separator at the end of the path. Use an empty string to use the application folder. Use NULL to use the system default storage folder.
      Parameters:
      filePath - File path to use to store the screenshot. Include the separator at the end of the path.
    • setFileName

      public void setFileName(String fileName)
      Set the file name of the screenshot.
      Parameters:
      fileName - File name to save the screenshot as.
    • setShotIndex

      public void setShotIndex(long index)
      Sets the base index that will used for subsequent screenshots.
      Parameters:
      index - the desired base index
    • setIsNumbered

      public void setIsNumbered(boolean numberedWanted)
      Sets if the filename should be appended with a number representing the current sequence.
      Parameters:
      numberedWanted - If numbering is wanted.
    • initialize

      public void initialize(AppStateManager stateManager, Application app)
      Description copied from interface: AppState
      Called by AppStateManager when transitioning this AppState from initializing to running.
      This will happen on the next iteration through the update loop after AppStateManager.attach(com.jme3.app.state.AppState) was called.

      AppStateManager will call this only from the update loop inside the rendering thread. This means is it safe to modify the scene graph from this method.

      Specified by:
      initialize in interface AppState
      Overrides:
      initialize in class AbstractAppState
      Parameters:
      stateManager - The state manager
      app - The application
    • cleanup

      public void cleanup()
      Clean up this AppState during the first update after it gets detached.

      Because each ScreenshotAppState is also a SceneProcessor (in addition to being an AppState) this method is also invoked when the SceneProcessor get removed from its ViewPort, leading to an indirect recursion:

      1. AppStateManager invokes ScreenshotAppState.cleanup()
      2. cleanup() invokes ViewPort.removeProcessor()
      3. removeProcessor() invokes ScreenshotAppState.cleanup()
      4. ... and so on.

      In order to break this recursion, this method only removes the SceneProcessor if it has not previously been removed.

      A better design would have the AppState and SceneProcessor be 2 distinct objects, but doing so now might break applications that rely on them being a single object.

      Specified by:
      cleanup in interface AppState
      Specified by:
      cleanup in interface SceneProcessor
      Overrides:
      cleanup in class AbstractAppState
    • onAction

      public void onAction(String name, boolean value, float tpf)
      Description copied from interface: ActionListener
      Called when an input to which this listener is registered to is invoked.
      Specified by:
      onAction in interface ActionListener
      Parameters:
      name - The name of the mapping that was invoked
      value - True if the action is "pressed", false otherwise
      tpf - The time per frame value.
    • takeScreenshot

      public void takeScreenshot()
    • initialize

      public void initialize(RenderManager rm, ViewPort vp)
      Description copied from interface: SceneProcessor
      Called in the render thread to initialize the scene processor.
      Specified by:
      initialize in interface SceneProcessor
      Parameters:
      rm - The render manager to which the SP was added to
      vp - The viewport to which the SP is assigned
    • isInitialized

      public boolean isInitialized()
      Specified by:
      isInitialized in interface AppState
      Specified by:
      isInitialized in interface SceneProcessor
      Overrides:
      isInitialized in class AbstractAppState
      Returns:
      True if initialize() was called on the state, false otherwise.
    • reshape

      public void reshape(ViewPort vp, int w, int h)
      Description copied from interface: SceneProcessor
      Called when the resolution of the viewport has been changed.
      Specified by:
      reshape in interface SceneProcessor
      Parameters:
      vp - the affected ViewPort
      w - the new width (in pixels)
      h - the new height (in pixels)
    • preFrame

      public void preFrame(float tpf)
      Description copied from interface: SceneProcessor
      Called before a frame
      Specified by:
      preFrame in interface SceneProcessor
      Parameters:
      tpf - Time per frame
    • postQueue

      public void postQueue(RenderQueue rq)
      Description copied from interface: SceneProcessor
      Called after the scene graph has been queued, but before it is flushed.
      Specified by:
      postQueue in interface SceneProcessor
      Parameters:
      rq - The render queue
    • postFrame

      public void postFrame(FrameBuffer out)
      Description copied from interface: SceneProcessor
      Called after a frame has been rendered and the queue flushed.
      Specified by:
      postFrame in interface SceneProcessor
      Parameters:
      out - The FB to which the scene was rendered.
    • setProfiler

      public void setProfiler(AppProfiler profiler)
      Description copied from interface: SceneProcessor
      Sets a profiler Instance for this processor.
      Specified by:
      setProfiler in interface SceneProcessor
      Parameters:
      profiler - the profiler instance.
    • writeImageFile

      protected void writeImageFile(File file) throws IOException
      Called by postFrame() once the screen has been captured to outBuf.
      Parameters:
      file - the output file
      Throws:
      IOException - if an I/O error occurs