• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Easiest Way to create "Light Piercing Shadow" effect

YoSniper

Member
Hello everyone!

I've been programming in Game Maker Studio for about a decade now, but when it comes to lighting effects, I tend to be at a loss. I am aware of certain features in GMS like "blend modes" and I understand the difference between bm_add and bm_normal. However, I am aware of the blend mode bm_subtract, also, but I've never understood how to use it. My gut tells me this is the way to go for what I want, but that's what I'm here to ask you about.

Let's say I want shadow to cover the entire view, like a black rectangle with alpha = 0.5. But I also want to have light sources like lampposts throughout the stage that cast beams of light down. Where those beams of light are, I want the shadow to disappear completely. So something overlapped by the beam of light is completely visible, as opposed to being halfway obscured by the shadow that otherwise encompasses the entire view.

Any help with this matter is appreciated.
 

YoSniper

Member
Does it have to be a surface, though? Can't it just be a foreground object with this kind of code in the Draw Event? I'm a little uncomfortable with surfaces, to be honest.
 

obscene

Member
You're always drawing to a surface, whether you know it or not. If you set the blend mode to subtract, you're subtracting from the default application_surface, not the sprite. The point of using a surface is to isolate what you want to be affected. You set the new surface, draw a sprite to it, subtract some part, and then draw the surface onto the application_surface. It's really much simpler than you think.

surface_set_target(your surface name);
//draw stuff on it
surface_reset_target();
draw_surface(etc)

You just need to create it in the create event and then free it in the cleanup event.
 
Top