SetContext()?

What does the setcontext() function do?

It allows all drawing to take place on an image set by setContext(). To get a better answer, look up setContext() in the Reference that can be accessed at the top of the forum.

rect(...) would draw a rectangle on screen.

But the fallowing code draws a rectangle into an image, which is not visible to you, until you draw it on screen with sprite(img).

local img = image(width, height)
setContext(img)
rect(...)

```


This technique is especially useful when you have to draw a lot static stuff. Then you can dump it into an image and instead of drawing each part separately, you draw them in one image as a whole.

Basically `setContext()` says: »Draw all stuff onto the screen«, while TARGET (`setContext(TARGET)`) lets you specify a target place to draw the stuff onto.