jedierikb jedierikb - 1 year ago 181
ActionScript Question

erasing sprite graphics?

If I have a sprite, with which I have drawn some stuff, how do I erase part of what I have drawn? Preferably I could use

with some "alpha=0" paint.

However, I don't believe the
method lets you set an RGBA color (like you can in
). Setting
alpha = 0
in the graphics method of
doesn't really do anything -- it just draws nothing.

In my particular use case, masking isn't an option.

Also, calling
isn't a good solution, since it clears away everything.

Answer Source

Unfortunately, you cannot do exactly what you're hoping to do with the Graphics class. Though erasing could mean that you draw over something you've already drawn with the background color, I'm guessing you're hoping to "draw transparency" back onto the Graphics object. Drawing with an alpha of 0 is not drawing "nothing" - you just don't see what you draw because it is fully transparent.

This is what you get for working with vectors as opposed to bitmaps. To "erase" part of a vector means that you are creating an entirely new vector, something that's going to take some computation rather than just setting some pixel to a certain color value. Graphics doesn't provide such advanced functionality, though you could certainly write your own functions to do it. :P

One workaround is to use bitmaps instead:

Another is to consider whether you could implement what you're trying to do in a different way; one that would lend itself to using clear().

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download