Sprite mask reduces opacity

Hi, I’m using the sprite masking extension for the first time. I have an object that will have a shadow but I only want the shadow to be visible on the platform, not in the air.

I know there’s shadow clone and reflection extensions but I need to be able to adjust the angle of the shadow to match the angle of the platform so I’m making my own shadow.




The next pic shows the scene editor with a yellow platform with a green fake platform behind it acting as the object mask. It’s not in alignment for the pic to make sense.

When I have the object mask on, the shadow object goes to about 50% opacity as shown in the bottom left. Is this meant to happen?

Then on the bottom right there’s a pic of the shadow object without the mask. Because it’s a shadow the reduced opacity is okay but I’d rather be able to control it myself.

So, is this reduced opacity expected behavior or is there something wrong? The ball is a physics object but I got the same opacity thing with a top down movement object.

image

Hi Bubble,

It seems the color of the sprite is the reason for that.

This is my setup: a yellow rectangle with a red and a blue circle:
red and blue

This is what happens when I use the blue sprite:
blue_masking

and this, when I use the red sprite:
red_masking

2 Likes

Hi!
The color of the mask sprite should be red.

1 Like

Wow, red works! But I don’t understand how you could know that. It’s not mentioned in the documentation or the configuration. And in an example from a while back, @MrMen used a white mask with, I assume, no problems.

I just noticed that while reading through the forum, for example in Silver-Streak’s reply here:

When you opened this topic I thought the problem may occur because of the color of the sprite and checked it.

I did a bit of searching to get more info on masks needing to be red and now I’m even more confused. A year after that post, there was this one that I think I understand from the author of the extension:

And later on in the same thread:

Has something changed? If it does need to be red, then can that instruction be put in the extension description?

There is nothing more precise than an experiment :wink:
Options:

Result:

2 Likes

I was wondering the exact same thing and did a little research. GDevelop uses the PIXI renderer. The documentation says the following about it: For sprite mask both alpha and red channel are used. Black mask is the same as transparent mask. (PixiJS API Documentation)
So the red channel can be used to make an image transparent or partially transparent.
Here is an example:
The following mask is used on the sprite. I used five rectangles with the following values in RGBA: (255,0,0,255), gradient (255,0,0,255) to (0,0,0,255), gradient with the color blue and gradient with the color red to alpha 0 and as comparison a rectangle with the color magenta.
And this is how the result looks like.


So you can use white or also magenta, because both have the red channel with the value 255! It is always about the red channel.
I hope this hint was helpful and also helps others who deal with this extension.

5 Likes