How to use the sprite mask?

Can someone help me understand how to use the sprite mask?


I have two rectangles, one black and one white, and I would like to make what is underneath appear by scrolling.


The sprite masking works by masking 1 sprite with another sprite or a shape painter.

If you mask with a sprite then the value of the color determines the masking. The brighter the color the higher the opacity.

In this example the image object (blue) is masked with the mask object (black, grey, white) . On the bottom, both objects are in the same position and size. I added copies of the images on the top.

The area that is aligned with the black colors isn’t visible. The grey area is semi-transparent. The white area is completely visible.

You only need to set the mask once.

If you moved the mask then it would make the image become visible. If you moved the image, the image would slide into view and become less or more visible as it aligned with the different colors.

In your example, the mask should be white if it’s currently black. A black mask wouldn’t show anything. If the mask pixels don’t share the same space as the image object then it doesn’t matter what the color is, the masked object won’t be visible.

The Z-order of the objects doesn’t matter. The mask can be above or below the object being masked.

1 Like

I would like that releasing the space key adds a +5 to the x value of one of the two objects and that the one underneath is gradually unmarked but I can’t do it

What do you mean by unmasked? Do you want it to gradually appear from 1 side? If so, the mask needs to be all white and start to one side of the other object. Then you could move the mask object towards the other object. The image would remain stationery.

If you had the mask object in the destination position and moved the image then as the image moved more of it would become visible.

1 Like

XRecorder_21032022_191338_1_1_1

this is what I would like to achieve so give a value to the masked object and decrease the mask depending on the bullets fired

You cannot selectively mask an object (i.e. only target the outline but leave the inside). But you could have two objects, one object that has the outline, with another object underneath it (without the outline). Then have a third object that is a solid rectangle sprite on top of it that acts as the mask, which makes it visible.

Then as ammo depletes, move the sprite mask left (or reduce its width) so less of the outlined object is visible, this will make the non-outlined object visible underneath.

1 Like

Alternatively, you could make the image a tiled sprite and slowly decrease the width. It’s sort of like a resource bar. You could use a formula connected to a variable or just reduce the width.

2 Likes