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
ConstructorsConstructorDescriptionUsing 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 TypeMethodDescriptionvoidcleanup()Clean up this AppState during the first update after it gets detached.voidinitialize(AppStateManager stateManager, Application app) Called byAppStateManagerwhen transitioning thisAppStatefrom initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)was called.voidinitialize(RenderManager rm, ViewPort vp) Called in the render thread to initialize the scene processor.booleanvoidCalled when an input to which this listener is registered to is invoked.voidpostFrame(FrameBuffer out) Called after a frame has been rendered and the queue flushed.voidpostQueue(RenderQueue rq) Called after the scene graph has been queued, but before it is flushed.voidpreFrame(float tpf) Called before a framevoidCalled when the resolution of the viewport has been changed.voidsetFileName(String fileName) Set the file name of the screenshot.voidsetFilePath(String filePath) Set the file path to store the screenshot.voidsetIsNumbered(boolean numberedWanted) Sets if the filename should be appended with a number representing the current sequence.voidsetProfiler(AppProfiler profiler) Sets a profiler Instance for this processor.voidsetShotIndex(long index) Sets the base index that will used for subsequent screenshots.voidprotected voidwriteImageFile(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, updateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:AppStateCalled byAppStateManagerwhen transitioning thisAppStatefrom initializing to running.
This will happen on the next iteration through the update loop afterAppStateManager.attach(com.jme3.app.state.AppState)was called.AppStateManagerwill 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:
initializein interfaceAppState- Overrides:
initializein 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:
cleanupin interfaceAppState- Specified by:
cleanupin interfaceSceneProcessor- Overrides:
cleanupin classAbstractAppState
-
onAction
Description copied from interface:ActionListenerCalled when an input to which this listener is registered to is invoked.- Specified by:
onActionin 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:SceneProcessorCalled in the render thread to initialize the scene processor.- Specified by:
initializein 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:
isInitializedin interfaceAppState- Specified by:
isInitializedin interfaceSceneProcessor- Overrides:
isInitializedin classAbstractAppState- Returns:
- True if
initialize()was called on the state, false otherwise.
-
reshape
Description copied from interface:SceneProcessorCalled when the resolution of the viewport has been changed.- Specified by:
reshapein 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:SceneProcessorCalled before a frame- Specified by:
preFramein interfaceSceneProcessor- Parameters:
tpf- Time per frame
-
postQueue
Description copied from interface:SceneProcessorCalled after the scene graph has been queued, but before it is flushed.- Specified by:
postQueuein interfaceSceneProcessor- Parameters:
rq- The render queue
-
postFrame
Description copied from interface:SceneProcessorCalled after a frame has been rendered and the queue flushed.- Specified by:
postFramein interfaceSceneProcessor- Parameters:
out- The FB to which the scene was rendered.
-
setProfiler
Description copied from interface:SceneProcessorSets a profiler Instance for this processor.- Specified by:
setProfilerin 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
-