How to make some Shape
or Bitmap
to became unmovable mask, which cut all graphics above mask.
(they laying in different containers with different coordinate spaces)
Some explanation:
I have some vector Shape
in one class, some Bitmap
images in another. I want to make shape acting like "mask", cutting images which above Shape
.
I has two ideas, but they does not work:
1)I tryed BlendMode
, but they works another way - if i want to erase some image, this image must be parent of masking image, which is not acceptable in my case: images could move, but mask should be unmovable. Also i can't move mask to a child container of image, because they in different coordinate spaces.
I made explanation diagram: https://i.sstatic.net/Spbx4.png
2)Use .mask
property with masking layer. But mask and bitmap in different coordinate spaces, so this don't work too.
Mask is solution! I made black mask, in which i draw my shape with BlendMode.Erase
property. So i get in this mask transparent shape-formed hole.
Then i set it to the .mask
property of my image and set to image and mask .cacheAsBitmap = true
. Mask and image must be added to stage (and mask .visibility = false
).
This way mask start working and zones with transparency "cut" my image.