Package com.jme3.app.state
Class ScreenshotAppState
java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.app.state.ScreenshotAppState
- All Implemented Interfaces:
AppState
,ActionListener
,InputListener
,SceneProcessor
-
Field Summary
Fields inherited from class com.jme3.app.state.AbstractAppState
initialized
-
Constructor Summary
ConstructorDescriptionUsing this constructor, the screenshot files will be written sequentially to the system default storage folder.ScreenshotAppState
(String filePath) This constructor allows you to specify the output file path of the screenshot.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.ScreenshotAppState
(String filePath, String fileName) This constructor allows you to specify the output file path of the screenshot.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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Clean up this AppState during the first update after it gets detached.void
initialize
(AppStateManager stateManager, Application app) Called byAppStateManager
when transitioning thisAppState
from initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)
was called.void
initialize
(RenderManager rm, ViewPort vp) Called in the render thread to initialize the scene processor.boolean
void
Called when an input to which this listener is registered to is invoked.void
postFrame
(FrameBuffer out) Called after a frame has been rendered and the queue flushed.void
postQueue
(RenderQueue rq) Called after the scene graph has been queued, but before it is flushed.void
preFrame
(float tpf) Called before a framevoid
Called when the resolution of the viewport has been changed.void
setFileName
(String fileName) Set the file name of the screenshot.void
setFilePath
(String filePath) Set the file path to store the screenshot.void
setIsNumbered
(boolean numberedWanted) Sets if the filename should be appended with a number representing the current sequence.void
setProfiler
(AppProfiler profiler) Sets a profiler Instance for this processor.void
setShotIndex
(long index) Sets the base index that will used for subsequent screenshots.void
protected void
writeImageFile
(File file) Called by postFrame() once the screen has been captured to outBuf.Methods inherited from class com.jme3.app.state.AbstractAppState
getId, isEnabled, postRender, render, setEnabled, setId, stateAttached, stateDetached, update
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jme3.post.SceneProcessor
rescale
-
Constructor Details
-
ScreenshotAppState
public ScreenshotAppState()Using this constructor, the screenshot files will be written sequentially to the system default storage folder. -
ScreenshotAppState
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
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
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
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
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
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
Description copied from interface:AppState
Called byAppStateManager
when transitioning thisAppState
from initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.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 interfaceAppState
- Overrides:
initialize
in classAbstractAppState
- Parameters:
stateManager
- The state managerapp
- 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:
- AppStateManager invokes ScreenshotAppState.cleanup()
- cleanup() invokes ViewPort.removeProcessor()
- removeProcessor() invokes ScreenshotAppState.cleanup()
- ... 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 interfaceAppState
- Specified by:
cleanup
in interfaceSceneProcessor
- Overrides:
cleanup
in classAbstractAppState
-
onAction
Description copied from interface:ActionListener
Called when an input to which this listener is registered to is invoked.- Specified by:
onAction
in interfaceActionListener
- Parameters:
name
- The name of the mapping that was invokedvalue
- True if the action is "pressed", false otherwisetpf
- The time per frame value.
-
takeScreenshot
public void takeScreenshot() -
initialize
Description copied from interface:SceneProcessor
Called in the render thread to initialize the scene processor.- Specified by:
initialize
in interfaceSceneProcessor
- Parameters:
rm
- The render manager to which the SP was added tovp
- The viewport to which the SP is assigned
-
isInitialized
public boolean isInitialized()- Specified by:
isInitialized
in interfaceAppState
- Specified by:
isInitialized
in interfaceSceneProcessor
- Overrides:
isInitialized
in classAbstractAppState
- Returns:
- True if
initialize()
was called on the state, false otherwise.
-
reshape
Description copied from interface:SceneProcessor
Called when the resolution of the viewport has been changed.- Specified by:
reshape
in interfaceSceneProcessor
- Parameters:
vp
- the affected ViewPortw
- 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 interfaceSceneProcessor
- Parameters:
tpf
- Time per frame
-
postQueue
Description copied from interface:SceneProcessor
Called after the scene graph has been queued, but before it is flushed.- Specified by:
postQueue
in interfaceSceneProcessor
- Parameters:
rq
- The render queue
-
postFrame
Description copied from interface:SceneProcessor
Called after a frame has been rendered and the queue flushed.- Specified by:
postFrame
in interfaceSceneProcessor
- Parameters:
out
- The FB to which the scene was rendered.
-
setProfiler
Description copied from interface:SceneProcessor
Sets a profiler Instance for this processor.- Specified by:
setProfiler
in interfaceSceneProcessor
- Parameters:
profiler
- the profiler instance.
-
writeImageFile
Called by postFrame() once the screen has been captured to outBuf.- Parameters:
file
- the output file- Throws:
IOException
- if an I/O error occurs
-