image.clear() ?

Is there any way that I’ve missed to clear an image? I need to update an image every frame, and it contains transparent areas so I can’t just draw over the top. I’d ideally like to be able to blank it down and start again, much the way the main draw loop works.

If not, is there any chance this could be added in a future update?

That’s a very useful suggestion. Perhaps image.fill( r,g,b,a ). I’ll look at adding it as soon as possible.

Have you tried using the background() with setContext()

Or just make a new image.

@Bortels I tried that, but it had a rather negative effect on performance :frowning:

And then my game crashed.

lol. then my work here is done. :slight_smile:

I had the same issue, need to restore transparency of a buffer image during draw. So clear the image with no background and no color.
The solution using setcontext(image) and then background(0,0,0,0) works fine.
Note that a rect with alpha 0 does nothing so you must use background.

store the original image that is blanked, and when you need it bak, copy it to the buffer you are using.

Image:fill() would still be helpful, but it’s likely not faster than this suggestion.

That’s a good suggestion, @aciolino. And you’re right that it probably won’t be any slower than a dedicated fill.

FYI, the crash bug when creating an image every frame will be fixed in the next release.

On the subjects of setContext(img) whlie draw(): i have come to the conclusion that setCotext works fine when in the setup() phase but has a lot of problems (doesn’t work at all, or only when some kind of pause occurs, like a print() ). Am i the only who experienced it? I cannot be sure whether the bug is in my code or in codea. If i am the only one, I’ll assume it’s my code that fails.

We’ve fixed several issues with setContext, and it can now be used reliably during the draw loop without any significant slowdown and during video recording without issue.

Thank you @John.

I should have mentioned that these fixes are coming in 1.5