ScreenshotAppState doesn't create image

I want my game to have screenshot functionality from the pause menu, so I decided to use ScreenshotAppState to do just that. However, it doesn’t seem to be working.

I put this code inside a loop that checks if the screenshot button is pressed:

ScreenshotAppState screenShotState = new ScreenshotAppState();
this.stateManager.attach(screenShotState);
screenShotState.onAction(null,true,0);

However, nothing happens. I quit and refresh my file system, but nothing shows up. I also made sure that the code was being reached. So why won’t this work? Am I implementing it wrong? Is it because I’m attaching the state on the same frame as when I print?

You can just create a PauseMenuAppState, and pause the GameplayAppState. This way, the GameplayAppState will not update the scene and you dont need to detach it.

And by the way, what is the code of the onAction() method you’re using? And just looping that is kind of a dirty way to do it…

You have to call “takeScreenshot” method.
http://javadoc.jmonkeyengine.org/com/jme3/app/state/ScreenshotAppState.html

I used this AppState several times and mapped it to the print key.

1 Like