Erase sprites?

If I have a sprite with which I drew some material, how can I remove part of what I drew? Preferably I could use drawRect() with some paint "alpha = 0".

However, I do not believe that the beginFill() method allows you to set the RGBA color (for example, you can in bitmapData ). Setting alpha = 0 in the graphical beginFill() method actually does nothing - it draws nothing.

In my particular use case, disguise is not an option.

Also, calling clear() not a good solution, since it clears everything.

+4
source share
3 answers

Unfortunately, you cannot do exactly what you hope to do with the Graphics class. Although deleting may mean that you will draw something that you have already painted with the background color, I assume that you are hoping to "draw transparency" back to the Graphics object. Drawing with alpha 0 does not draw “nothing” - you just don’t see what you are painting, because it is completely transparent.

This is what you get for working with vectors, not bitmaps. To “erase” part of a vector means that you are creating a completely new vector, something that takes some calculation, and not just sets some pixel for a specific color value. Graphics does not provide such advanced functionality, although you can certainly write your own functions for this .: P

One way is to use bitmap images:
http://www.actionscript.org/forums/showthread.php3?t=187857
http://www.actionscripts.org/forums/showthread.php3?t=149021

Another is to consider whether you can realize what you are trying to do differently; one that could use clear ().

+5
source

You can achieve this if you do not need to interact with any elements under your Sprite.

For this

  • create a Shape object in the desired shape and set its cacheAsBitmap property to true
  • set the Sprite cacheAsBitmap to true
  • set the blendMode property of your Shape to BlendMode.ERASE
  • add the form to the sprite display list
+10
source

If you want to keep part of your drawing while erasing some other parts, then the only possible route would be to draw using several sprites. Create a sprite for each part of the drawing, then you can select the sprite you want to erase and leave the rest.

In addition, all that remains for you is to use the bitmap to copy partitions, then explicitly extract the copied partitions back. (this is difficult to implement in a complex estate, try copying only a complex curved area!)

0
source

All Articles