Little tip to some people: If some of your objects are appearing over the shadow layer, and you've made sure the shadow layer is at the highest layer order. You can set the shadow draw event to be Draw End instead of a Draw event. Learned it works better to help fit everything under!
Hey amazing job!! You can really play around with this and get amazing results. I had been struggling to make my own cut outs using your method but I figured it out. I made them in different sizes giving them a high quality look. For those interested to have them, let me know.
I've never used surfaces before, don't know how I lived without these for an entire game lol. This tutorial did a great job explaining how they work and how to set them up. Although, wouldn't it be better at ~ 8:20 to set and reset the blendmode outside of the loop? Switching the blendmode 16 times a frame doesn't seem optimal. Using separate loops for subtracting and adding.
OMG THANK YOU SM FOR THIS TUTORIAL! Something I forgot to do (which I'm not sure if you mentioned or not. I was sleepy while doing this) Is to make the cutout invisible when rendering or else it's just look like a bright white light and you can't see the effects. Once I did that, it was like was a huge sigh of relief.
This is a good straightforward tutorial, though you really should only make the surface the size of your camera, if you have a large room making it the size of it could lead to performance problems.
Absolutely amazing, right what my indie game needed. I was working with a similar system, just was missing some things in the configuration of the canva and with that when adding coding it would not take the canva countable and messed it all up, it only showed the subtracted cuttouts out when paused, this fixes all my issues.
Thats great ! The only problem is that I want the surface_create to be the camera, could you do a tutorial base on the camera and not on the room_width, room_height ?
use these variables instead of the room width and height: cameraHeight = camera_get_view_height(view_camera[0]); cameraWidth = camera_get_view_width(view_camera[0]); just put them in the create event and use them when you create the layer in the draw event important: the cords in a surface are not equal to the cords in your room, so in the draw_surface event, you must find a way to translate the cords of your camera to the same cords but in the surface
Hey, I know this is an old video, but still. Is there a way to exclude background layers from being lit up? I don't really want to switch to more complex lighting, but I don't want candles illuminating the sky :)
hey! this is such a great tutorial, but the rooms i have in my game are relatively big and its starting to lag from the lighting. how would i do this in the Draw GUI event?
Thanks, looking at the code I wrote there if your room is huge, yeah lag. You can use the camera to get the width,height,x,y position of it and draw it that way. (camera_get_view_width/height, camera_get_view_x/y) should get your started.
@@GameMakerCasts this works to draw the surface on only the camera, but when the player moves and the camera follows it the light sources stick to the camera. how do i stop this?
@@professorpicklesphd.8312 use this to draw the sprite of the light: (Draw event) Draw_sprite(light_sprite, 0, x - camera_get_view_camera_x(view_camera[0], same for y... Then draw the surface to viewcamera_get_view_camera_x(view_camera[0], and same for y
If you aren't getting a black screen , you might of screwed up like I did by making the lighting render object invisible. I'm a newb but I'm guessing ticking that box means the draw step never happens so all that code is ignored?
ive started using this and i noticed that overlapping light will create a dark area where they intersect. Did i do something wrong? Is there a way to make overlapping lights add their brightness values together to make a much stronger light source?
@@jaredgc8423 its not fixable. If you put the sprites in an art program together overlapped you get the same effect. The only thing you can do to remove it without shifting towards a more advanced lighting system is use a cell shaded light sprite instead of a gradient
Hey downloaded aseprite and if i do the same like you my picture becomes black if i go on the left top corner. I can draw the white circle but there is black background and its not transparent. Could you help me
I keep asking this on tutorials of this nature but when I use the subtract blend mode all things under the sprite are not drawn, including objects and tiles. It actually just makes a black square the shape of which is not consistent with the sprite drawn under the subtract or the sprites collision mask. Super confused as to how no one else has this issue. Worth noting I have my lighting object at a very low depth so all the lighting effects can effect everything in my game. Not sure why I can't cut out the dark surface.
for some reason my light cutout is not cutting the dark, can anyone explain what is wrong. if(surface_exists(lighting_surface) == false) { lighting_surface = surface_create(view_get_wport(0), view_get_hport(0)) } surface_set_target(lighting_surface) draw_clear_alpha(c_black, 0.3) with(light_cutout) {
gpu_set_blendmode(bm_subtract) draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1)
It is called Aseprite, and you can grab it from the humble bundle store at www.humblebundle.com/store/aseprite?partner=gamemakercasts You can also get it from steam as well at store.steampowered.com/app/431730/Aseprite/
Hey, man. I followed your tutorial correctly but, for some reason, my screen goes fully black except for the heart HUD, I'd like to know if it can be fixed
you would need to add a timer that goes up and down until it reaches a maximum / minimum where it flips, think of sin(timer) where that result is between -1 and 1 constantly going up and down.
@@GameMakerCasts I'm not quite sure how to implement the timer, should it affect var wobble_amount_x/y or should it be its own variable that is implemented after draw_sprite_ext()? Thanks for the help!
You will need to play with the lighting at the end. So you subtract the circle, but instead of a regular "add" use "bm_src_color" or at least I have found that worked for me
You would probably need to run a shader to do that afterwards. In the latest GameMaker version they do have some shaders that might help with this, but I haven't tried them
Hey dude, I'm sorry for the dumb question, I am still not a pro with surfaces, but how could I make this work with different shades of darkness? For example, instead of black darkness I want it to be kinda blue tinted. I remember trying to change the color in draw_clear_alpha() but that made the lights themselves look weird, I assume I'd probably have to do some modifications in the sprite of the lights or the way they're drawn. Thanks in advance if you see this!
@@GameMakerCasts Sorry if I understood you wrong, but is that for changing the colors of the lights? In case it is, don't worry, I understood that part- what I want is to change the color of the darkness to i.e. blue, so the lights would be cutouts in a semi transparent blue foreground instead of a black one. I tried simply changing the color in draw_clear_alpha() but that gave me weird results with the lights (If you want I could try again and show). Do you reckon using draw_circle_colour() for the lights instead of sprites would get me a different result? Thanks for the response btw
I know you posted this a year ago, but I thibk I know what the issue is if you didn't manage to figure it out. Surfaces use their own coordinate system thats seperate from the rooms, so you have to subtract the cameras position from the coordinates in the draw_sprite_ext section
What software did you use when u made the light? I remember when you can do glow effects and more in the game maker sprite editor and now it's nowhere to be found. Now it's all done in codes and Im not in the advanced or intermediate levels of code
You can try creating a new oLight or simply setting the (whichever) Light object to be x = player.x y = player.y inside the step event. Something like that.
what if i have 2 of the same instances but only want 1 of them to light up? EDIT: 2 of my braincells just connected, i figured it out We are using a WITH statement here, i just need to put the variables in the object... facepalm
Now THIS....This this this THIS.... is a solid WORKING lighting tutorial. Well done, i love it. Clap!
Little tip to some people:
If some of your objects are appearing over the shadow layer, and you've made sure the shadow layer is at the highest layer order. You can set the shadow draw event to be Draw End instead of a Draw event. Learned it works better to help fit everything under!
Bro thank u so much
Amazing! Thank you for share this!
helps a ton, been looking for a good lighting system tutorial for a while now
Great tutorial! Perfect for the game I'm currently working on, thank you!
Hey amazing job!! You can really play around with this and get amazing results. I had been struggling to make my own cut outs using your method but I figured it out. I made them in different sizes giving them a high quality look. For those interested to have them, let me know.
This short guide is priceless! Bravo!
Glad it was helpful!
Excellent tutorial. Short and sweet but with awesome lighting method. Thanks!!
I've never used surfaces before, don't know how I lived without these for an entire game lol. This tutorial did a great job explaining how they work and how to set them up.
Although, wouldn't it be better at ~ 8:20 to set and reset the blendmode outside of the loop? Switching the blendmode 16 times a frame doesn't seem optimal. Using separate loops for subtracting and adding.
100%, if you don't need to add/sub anything else then yeah totally outside of that loop you are correct :)
@@GameMakerCasts Thanks for the reply, and thanks for enlightening me to surfaces!
This is the DOPEST tutorial on lighting! 100%!
If you also have weird edges when two lights cross each other just tick the "Premultiply Alpha" box for the Simple_Light_Cutout sprite.
Thank you so much bro, made my hour!
@@masterjohn3126 glad to hear my weird discovery did eventually help someone haha
Holy crap I was ripping my hair out because of this you are an angel
what an amazing tutorial, very clear and practical
OMG THANK YOU SM FOR THIS TUTORIAL! Something I forgot to do (which I'm not sure if you mentioned or not. I was sleepy while doing this) Is to make the cutout invisible when rendering or else it's just look like a bright white light and you can't see the effects. Once I did that, it was like was a huge sigh of relief.
This is the best lighting tutorial on youtube how does it only have 2,000 views
AND YOU DID LIKE 2 GIVEAWAYS WTF
Thanks :) I do what I can
You're amazing bro, it worked very well.
This was super easy to follow. Great video!
thanks, you saved my game jam.
That's incredible,you did all with codes,I would draw all lights 😂
This is a good straightforward tutorial, though you really should only make the surface the size of your camera, if you have a large room making it the size of it could lead to performance problems.
Absolutely amazing, right what my indie game needed. I was working with a similar system, just was missing some things in the configuration of the canva and with that when adding coding it would not take the canva countable and messed it all up, it only showed the subtracted cuttouts out when paused, this fixes all my issues.
for some reason I can't create a colored light. I did everything as in the video
Thank you so much, man!
Looking forward to trying to get this to work in a game I'm making. I'd like to attach the lighting to the player too, if it's not too tricky.
100% not tricky at all! you basically end up looking for the play object and drawing the cutout around them. Does that make sense?
@@GameMakerCasts how do you do that plssss?
Awesome! Thats really really cool!
Thanks so much! This was just the info I needed :)
Nice and Simple Lighting system, I like it. Do you know how to make specific background layers not be affected by the light / darkness?
Thats great ! The only problem is that I want the surface_create to be the camera, could you do a tutorial base on the camera and not on the room_width, room_height ?
use these variables instead of the room width and height:
cameraHeight = camera_get_view_height(view_camera[0]);
cameraWidth = camera_get_view_width(view_camera[0]);
just put them in the create event and use them when you create the layer in the draw event
important: the cords in a surface are not equal to the cords in your room, so in the draw_surface event, you must find a way to translate the cords of your camera to the same cords but in the surface
Hey, I know this is an old video, but still. Is there a way to exclude background layers from being lit up? I don't really want to switch to more complex lighting, but I don't want candles illuminating the sky :)
Brilliant, easy to follow...
Glad it was helpful! :)
What do I do If instead of black its a very white surface even though i just set c_black?
hey nice video. How did you setup this „skin“ for gamemaker?
hey! this is such a great tutorial, but the rooms i have in my game are relatively big and its starting to lag from the lighting. how would i do this in the Draw GUI event?
Thanks, looking at the code I wrote there if your room is huge, yeah lag. You can use the camera to get the width,height,x,y position of it and draw it that way. (camera_get_view_width/height, camera_get_view_x/y) should get your started.
@@GameMakerCasts this works to draw the surface on only the camera, but when the player moves and the camera follows it the light sources stick to the camera. how do i stop this?
@@professorpicklesphd.8312 use this to draw the sprite of the light:
(Draw event)
Draw_sprite(light_sprite, 0, x - camera_get_view_camera_x(view_camera[0], same for y...
Then draw the surface to viewcamera_get_view_camera_x(view_camera[0], and same for y
@@TheCivildecay thank you so much! this worked perfectly! ive been looking around for something to do this for a while but i couldnt find anything
Yeess! thank you very much! this got me out of a dead end
If you aren't getting a black screen , you might of screwed up like I did by making the lighting render object invisible. I'm a newb but I'm guessing ticking that box means the draw step never happens so all that code is ignored?
awesome video! thanks a lot!
ive started using this and i noticed that overlapping light will create a dark area where they intersect. Did i do something wrong? Is there a way to make overlapping lights add their brightness values together to make a much stronger light source?
I had this issue, can fix by lowering the intensity variable.
I am having this issue too! Any chance you fixed it?
@@jaredgc8423 its not fixable. If you put the sprites in an art program together overlapped you get the same effect. The only thing you can do to remove it without shifting towards a more advanced lighting system is use a cell shaded light sprite instead of a gradient
If surface stays black without the lights: you need to add " camera_apply(_camera); " after " draw_clear_alpha(c_black,0.6); ". That fixed it for me!
Hey downloaded aseprite and if i do the same like you my picture becomes black if i go on the left top corner. I can draw the white circle but there is black background and its not transparent. Could you help me
Make sure the circle isn't touching the edges. If you are still having troubles hit me up in discord discord.gg/HAAW2w2F
I keep asking this on tutorials of this nature but when I use the subtract blend mode all things under the sprite are not drawn, including objects and tiles. It actually just makes a black square the shape of which is not consistent with the sprite drawn under the subtract or the sprites collision mask. Super confused as to how no one else has this issue. Worth noting I have my lighting object at a very low depth so all the lighting effects can effect everything in my game. Not sure why I can't cut out the dark surface.
If you have discord join the channel at discord.gg/hXaMWuwp and I can have a look for you
for some reason my light cutout is not cutting the dark, can anyone explain what is wrong.
if(surface_exists(lighting_surface) == false)
{
lighting_surface = surface_create(view_get_wport(0), view_get_hport(0))
}
surface_set_target(lighting_surface)
draw_clear_alpha(c_black, 0.3)
with(light_cutout) {
gpu_set_blendmode(bm_subtract)
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, 0, c_white, 1)
gpu_set_blendmode(bm_normal)
}
surface_reset_target()
draw_surface(lighting_surface, camera_get_view_x(view_camera[0]), camera_get_view_y(view_camera[0]))
Do you have a link to the paint program you use for this?
It is called Aseprite, and you can grab it from the humble bundle store at www.humblebundle.com/store/aseprite?partner=gamemakercasts You can also get it from steam as well at store.steampowered.com/app/431730/Aseprite/
So awsome tutorial
Glad you liked it
Hey, man. I followed your tutorial correctly but, for some reason, my screen goes fully black except for the heart HUD, I'd like to know if it can be fixed
Sounds like a drawing issue, are you able to send me your project or code and I can look at it?
@@GameMakerCasts sure, let me get a Drive for it
did it but as soon as i added the wobble thing my entire project turned black. for a sec i see the outlines. :(
Hey! Great video. Super simple and really effective. By any chance, do you know a way to make the wobble slower? Thanks again
you would need to add a timer that goes up and down until it reaches a maximum / minimum where it flips, think of sin(timer) where that result is between -1 and 1 constantly going up and down.
@@GameMakerCasts I'm not quite sure how to implement the timer, should it affect var wobble_amount_x/y or should it be its own variable that is implemented after draw_sprite_ext()? Thanks for the help!
Hey, can I do that with another size? Like a triangle? (I wanna do a flashlight in my game)
You can do this by replacing the light sprite with another one (say a triangle)
How do you handle overlapping colours? Mine are producing dark edges in awkward places!
You will need to play with the lighting at the end. So you subtract the circle, but instead of a regular "add" use "bm_src_color" or at least I have found that worked for me
Subscribed 🎉
any way to make the lights not desaturate
You would probably need to run a shader to do that afterwards. In the latest GameMaker version they do have some shaders that might help with this, but I haven't tried them
Hey dude, I'm sorry for the dumb question, I am still not a pro with surfaces, but how could I make this work with different shades of darkness? For example, instead of black darkness I want it to be kinda blue tinted. I remember trying to change the color in draw_clear_alpha() but that made the lights themselves look weird, I assume I'd probably have to do some modifications in the sprite of the lights or the way they're drawn. Thanks in advance if you see this!
I mean instead of drawing the lights at "c_white" or "c_yellow" or whatever I had, you could use "c_blue" and try that first
@@GameMakerCasts Sorry if I understood you wrong, but is that for changing the colors of the lights? In case it is, don't worry, I understood that part- what I want is to change the color of the darkness to i.e. blue, so the lights would be cutouts in a semi transparent blue foreground instead of a black one. I tried simply changing the color in draw_clear_alpha() but that gave me weird results with the lights (If you want I could try again and show). Do you reckon using draw_circle_colour() for the lights instead of sprites would get me a different result? Thanks for the response btw
I have made it so the surface follows the view and now it is not cutting any circles out? Please help.
I know you posted this a year ago, but I thibk I know what the issue is if you didn't manage to figure it out.
Surfaces use their own coordinate system thats seperate from the rooms, so you have to subtract the cameras position from the coordinates in the draw_sprite_ext section
What software did you use when u made the light? I remember when you can do glow effects and more in the game maker sprite editor and now it's nowhere to be found. Now it's all done in codes and Im not in the advanced or intermediate levels of code
I usually load up Aseprite (bit.ly/37GKELk) and create the sprites in there, then just copy and paste them over :)
@@GameMakerCasts ok thanks. Now i can make gradiants and all the extra features that game maker somehow removed for some odd reason
amazing tutorial! question though, how do i attach the lighting to the player? Edit: While keeping other lights normal.
You can try creating a new oLight or simply setting the (whichever) Light object to be
x = player.x
y = player.y
inside the step event. Something like that.
**** EVENT CREATE ****
lighting_surface = -1;
***** EVENT DRAW ******
draw_self();
if (surface_exists(lighting_surface) == false)
{
lighting_surface = surface_create(room_width, room_height);
}
surface_set_target(lighting_surface);
draw_clear_alpha(c_black, 0.6);
{
shakeX = random_range(1.2, 1);
shakeY = random_range(1.2, 1);
draw_set_blend_mode(bm_subtract);
draw_sprite_ext(sprite7, 0, player.x, player.y , shakeX, shakeY, 0, c_white, 1);
draw_sprite_ext(sprite7, 0, player.x, player.y, shakeX, shakeY, 0, c_red, 0.5);
draw_set_blend_mode(bm_normal);
surface_reset_target();
draw_surface(lighting_surface, 0, 0);
What is the game maker skin you're using ? it looks great !
Huge thanks for the tutorial :)
Thanks :) I am using the dark dracula theme found at github.com/dracula/gamemaker-studio
@@GameMakerCasts Oh ! I have it but I don't got the light blue menu names in the asset browser, did you change anything to get that ?
a lot of thnks
when i run this code on mac my whole screen will just be black
it does work on windows
That's really weird as there isn't anything super specific happening. I don't have a mac to test it on :(
noice!!!
I like how your gamemaker looks like Godot :D
Thanks, if you want the theme you can grab it at github.com/dracula/gamemaker-studio :)
W
what if i have 2 of the same instances but only want 1 of them to light up?
EDIT: 2 of my braincells just connected, i figured it out
We are using a WITH statement here, i just need to put the variables in the object... facepalm
the light looks ugly. But thanks for the tutorial
The sliding words at the bottom of the screen are very distracting...
Thanks for your input, I'll see what I can change up here :)