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 drawRect()
with some "alpha=0" paint.
However, I don't believe the beginFill()
method lets you set an RGBA color (like you can in bitmapData
). Setting alpha = 0
in the graphics method of beginFill()
doesn't really do anything -- it just draws nothing.
In my particular use case, masking isn't an option.
Also, calling clear()
isn't a good solution, since it clears away everything.
You can achieve this nicely if you don't need to be able to interact with any elements underneath your Sprite.
To do this
cacheAsBitmap
property to true
cacheAsBitmap
property to true
blendMode
property of your Shape to BlendMode.ERASE
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:
http://www.actionscript.org/forums/showthread.php3?t=187857
http://www.actionscripts.org/forums/showthread.php3?t=149021
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With