Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

image.clear() ?

edited April 2012 in Questions Posts: 159

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?

Tagged:

Comments

  • SimeonSimeon Admin Mod
    Posts: 4,893

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

  • JohnJohn Admin Mod
    Posts: 572

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

  • BortelsBortels Mod
    Posts: 1,557

    Or just make a new image.

  • Posts: 159

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

    And then my game crashed.

  • BortelsBortels Mod
    Posts: 1,557

    lol. then my work here is done. :-)

  • patpat
    Posts: 4

    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.

  • SimeonSimeon Admin Mod
    Posts: 4,893

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

  • DylanDylan Admin Mod
    Posts: 121

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

  • Jmv38Jmv38 Mod
    Posts: 3,295

    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.

  • JohnJohn Admin Mod
    Posts: 572

    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.

  • Jmv38Jmv38 Mod
    Posts: 3,295

    Thank you @John.

  • JohnJohn Admin Mod
    Posts: 572

    I should have mentioned that these fixes are coming in 1.5

Sign In or Register to comment.