Capturing screen, drawing something else, then returning the captured screen

I’ve not been able to find documentation about how to capture a screen besides this: FAQ:ScreenCapture
and unfortunately I’m unsure what to do with the code.

Specifically I have a game which uses backingMode(RETAINED). Two questions.

(1) How do I save the current screen (to temporary memory), draw things on top of current screen, but later redraw the old screen (from temporary memory)?

(2) If I then draw the captured screen in the draw() function (draw it 60 times per second) with a few few lines on top, will that slow down my fps?

@yboris For your first question, look at setContext(image). For the second, it won’t slow down until you draw 1,000’s of lines.

EDIT: For the second question, the number of lines before it slows down will depend on the device your using.

You can draw into an image using the setContext function, and then later sprite that image to draw it contents back to the screen (or inside another image). Drawing the saved image won’t slow down your FPS any more than a normal sprite would, because technically, the saved image IS a normal sprite. If you drew a lot of lines, it might slow it down, but then again, you could always just create an image in setup and use setContext to draw the lines into there, then sprite that image whenever you need the lines.

Thank you both for the helpful advice; I was able to create a program that creates a blank image, draws stuff to it, and then I can display the image using sprite.

Unfortunately this approach doesn’t seem to work for my game: if I setContext(screenCap) throughout my code, my draw() function balks when I ask it to then draw the resulting sprite(screenCap,WIDTH/2,HEIGHT/2). I may be to blame for not properly coding it all, but at the moment I’m perplexed - it seems like this approach would be an overly-complex way to solve my (simple?) problem.

What I want is to simply capture all the currently displayed pixels on screen into a blank image (let’s call it screenCap), display some menu above my current screen, allow the user to click some option, and then overwrite the whole screen with the contents of screenCap. Can I do this?

@yboris Are you making sure you’re calling setContext with no parameters to return drawing to the screen before you sprite the image? And did you call resetMatrix() to ensure it wasn’t just being translated off the screen? What happens when you try to draw it now? If all else fails, can you post some example that demonstrates the problem, or better yet, the code that originally caused the problem?

You are a hero! I forgot to setContext() before trying to draw to the screen :slight_smile:

Will return with updates if I fail again. Thank you :slight_smile: