distorted_butterfly
Member
I am trying to make a game in GameMaker 2 where objects become transparent depending on the object behind them. I currently have it so I am just checking each step (within the object to become transparent) whether in contact with the background object and then setting alpha to 0.5 if true.
Here is what I mean, the object changes from:
Opaque To Half Alpha
The problem is that I want the object to transition to being transparent, not just jump between the two states when it touches the edge of the yellow section (e.g. Any part of the ball in the yellow is transparent and any part in the blue is opaque).
I tried to achieve this using shaders but I don't have a lot of experience with them, I tried achieving the affect by creating a shader where I passed in the center of the yellow box, its width and its height to check whether any pixel was inside the rectangle and then set it to transparent but this method used a lot of nested if statements which I understand to be bad form and also will not work if there are more than two different coloured sections in a room. Is there any way to achieve the effect I want (where only the parts of the ball inside the yellow section become transparent) of do I have to deal with it just jumping from completely opaque to completely transparent.
Here is what I mean, the object changes from:
Opaque To Half Alpha
The problem is that I want the object to transition to being transparent, not just jump between the two states when it touches the edge of the yellow section (e.g. Any part of the ball in the yellow is transparent and any part in the blue is opaque).
I tried to achieve this using shaders but I don't have a lot of experience with them, I tried achieving the affect by creating a shader where I passed in the center of the yellow box, its width and its height to check whether any pixel was inside the rectangle and then set it to transparent but this method used a lot of nested if statements which I understand to be bad form and also will not work if there are more than two different coloured sections in a room. Is there any way to achieve the effect I want (where only the parts of the ball inside the yellow section become transparent) of do I have to deal with it just jumping from completely opaque to completely transparent.