GameMaker [HELP] Blending Mode Masking - How to Change Transparency

T

TheOakNuggins

Guest
Hello! I'm trying to clip one sprite over another (which I've done thanks to a blog post on YoYo), but now I would like to be able to change the transparency of the sprite that's being clipped.

Here's the code:
Code:
draw_sprite_stretched(sSolid, 0, self.x, self.y, solidxScale, solidyScale);    //draws sprite going to mask

gpu_set_blendenable(false)           
gpu_set_colorwriteenable(false,false,false,true);    //turns colors off

draw_set_alpha(0);
draw_rectangle(0,0, room_width,room_height, false);    //draw a large rectangle to be drawn on
   
draw_set_alpha(1);    //draw masking alpha
draw_sprite_stretched(sSolid, -1, self.x, self.y, solidxScale, solidyScale);

gpu_set_blendenable(true);
gpu_set_colorwriteenable(true,true,true,true); //colors back on

gpu_set_blendmode_ext(bm_dest_alpha,bm_inv_dest_alpha);    //bm_inv_dest_alpha is what masks it down.
gpu_set_alphatestenable(true);

draw_sprite_ext(sPlayer,0, mouse_x,mouse_y, 1, 1, 0, c_white, .2);    //draws covering mask
gpu_set_alphatestenable(false);
gpu_set_blendmode(bm_normal);
Here's what it looks like now:
Screen Shot 2018-03-18 at 1.18.42 AM.png
I should be able to adjust the transparency so that you can see through the pink some.
 
Last edited by a moderator:
T

TheOakNuggins

Guest
what exactly isn't working for you? The fact that it's pink means the transparency works right?
The sprite I'm overlaying is pink. If it were blue, I'd like to be able to set it to 50% and then the shaded area turns purple.
 
T

TheOakNuggins

Guest
Code:
///oPlayer Object Draw Event
while (!place_meeting(shadowx, shadowy, oSolid)) and  (shadowy < room_height)  {
  shadowy++;
}

shadowxScale = 1 + (1 / abs((oPlayer.y) - (shadowy)));

if  shadowxScale < 2 {
    draw_shadowxScale = lerp(draw_shadowxScale, shadowxScale, .2); 
    } else {
        draw_shadowxScale = lerp(draw_shadowxScale, shadowxScale, .5); 
}

surfShadowx = oPlayer.shadowx;
surfShadowy = round(oPlayer.shadowy);
surfShadowxScale = oPlayer.draw_shadowxScale/1;


draw_self();
Code:
///oShadow Object Draw Event

//Shadow Perspective Scaling
gpu_set_fog(true, c_black, 0, 1);

with(oParent) {

if (!surface_exists(shadowSurf)) {        //if there's no surface, create one
    shadowSurf = surface_create(sprite_width, sprite_height);
}

draw_set_alpha(.5);
draw_rectangle(0, 0, sprite_width, sprite_height, false);
draw_set_alpha(1);


surface_set_target(shadowSurf);
draw_clear_alpha(c_black, 0);

draw_sprite_ext(spr_shadow, -1, oPlayer.surfShadowx - x, oPlayer.surfShadowy + 2 - y, oPlayer.surfShadowxScale , 1, 0, 0, .8);
surface_reset_target();

draw_set_alpha(.5);
draw_surface(shadowSurf, x, y - 2);
draw_set_alpha(1);

}

gpu_set_fog(false, c_white, 0, 0);
I've figured it out!! Here's the code ^
 

Attachments

Top