Attempting to make my game prototype take screen shots via LIBGDX.

So, I’m in need of assistance with regards to this prototype I’m trying to build, and I’m having difficulty with regards to getting my game to screenshot. As far as organization, I have two classes: the main game class, and my “ScreenshotFactory”, which was built using the example on the LibGDX github.

Here’s my code:

The Main Game Class
http://pastebin.java-gaming.org/2046d79032019

The ScreenshotFactory class
http://pastebin.java-gaming.org/120466d092310

Question 1: Those of you willing to test the code, does it work for you? If so then…

Question 2: Where is it saving your screenshots?

I’m not at a place where I can test that, but can you try http://pastebin.java-gaming.org/6d930091a291e?

I tried your code, but unfortunately I can’t call the ScreenshotFactory class to the main class because the “takeScreenshot” function is set to private. It’s also giving me issues when I try to make the function public. It tries to make ScreenshotFactory static. =\

I appreciate your help!

How about this? http://pastebin.java-gaming.org/d93091a192e17

I’m assuming the static errors were because I was setting the width and height in the class, but outside of a method. Also added a stub Constructor for you to instantiate in the Game Class.

Same issue. I tried making it public just as you did here before, but it wouldn’t run unless I made the function static, & that causes the whole function to have issues.

EDIT: Maybe not. I got the program running, and I THINK the screenshot function is working, but I don’t know where it’s saving my screenshots to.

you have to make a new instance of the class.


ScreenRecorder screenRecorder = new ScreenRecorder();

screenRecorder.takeScreenshot();

Should be saving in your home directory I think?
So on Windows… C:\Users\YourUsername\

If not use, Gdx.files.absolute(“C:\Users\YourUsername” + index++ + “.png”); instead

EDIT: https://github.com/libgdx/libgdx/wiki/File-handling

…D’oh! Silly. As you can probably tell, I’m still new to this. =P

You guys are the greatest. I got it working. Thanks for all your help! How do I mark this thread as solved?