• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 draw surface over sprite

zendraw

Member
i want to draw a surface over a sprite in a way that the sprite`s alphas are applied to the surface so the surface is like cut based on the sprite. i have some code from before that doesnt work now for some reason.
GML:
draw_self();

if (surface_exists(surf))
{
    draw_surface_ext(surf,
    x,//+lengthdir_x(coordx, coorddir+image_angle),
    y,//+lengthdir_y(coordx, coorddir+image_angle),
    1, 1, image_angle, -1, 1);
} else
{
    gpu_set_colorwriteenable(true, true, true, false);

    surf=surface_create(320, 320);
    surface_set_target(surf);
    draw_clear_alpha(c_black, 0);
    
    draw_sprite(surface, 0, coordx, coordy);
    
    surface_reset_target();
    
    gpu_set_colorwriteenable(true, true, true, true);
}
 
Try setting the gpu_set_blendmode to subtract and then draw the player sprite at the player's location.
Haven't worked with surfaces in a while, so I'm not sure if this will work.
 

rytan451

Member
Here's an idea:

GML:
gpu_color_write_enable(false, false, false, true);
gpu_set_blendmode_ext_sepalpha(bm_zero, bm_one, bm_one, bm_zero);
draw_sprite(spr_something, 0, coordx, coordy);
gpu_set_blendmode(bm_normal)
gpu_color_write_enable(true, true, true, true);
 
Top