Simple Lighting System in GameMaker Studio 2

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ • 105

  • @WilliamGarrisonArts
    @WilliamGarrisonArts 4 роки тому +25

    Now THIS....This this this THIS.... is a solid WORKING lighting tutorial. Well done, i love it. Clap!

  • @arcticsmp-officialchannel6180
    @arcticsmp-officialchannel6180 2 роки тому +8

    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!

    • @d4rkk452
      @d4rkk452 Рік тому

      Bro thank u so much

  • @super_bits
    @super_bits Рік тому +2

    Amazing! Thank you for share this!

  • @chooby4405
    @chooby4405 4 роки тому +5

    helps a ton, been looking for a good lighting system tutorial for a while now

  • @ohpahn
    @ohpahn 3 роки тому +1

    Great tutorial! Perfect for the game I'm currently working on, thank you!

  • @ShamelezzSkillzz
    @ShamelezzSkillzz 4 роки тому +2

    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.

  • @Diver13666
    @Diver13666 2 роки тому

    This short guide is priceless! Bravo!

  • @gamemaker4217
    @gamemaker4217 4 роки тому +1

    Excellent tutorial. Short and sweet but with awesome lighting method. Thanks!!

  • @RaidSpinel
    @RaidSpinel 2 роки тому +4

    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.

    • @GameMakerCasts
      @GameMakerCasts  2 роки тому +1

      100%, if you don't need to add/sub anything else then yeah totally outside of that loop you are correct :)

    • @RaidSpinel
      @RaidSpinel 2 роки тому

      @@GameMakerCasts Thanks for the reply, and thanks for enlightening me to surfaces!

  • @dustinfinamore9801
    @dustinfinamore9801 3 роки тому

    This is the DOPEST tutorial on lighting! 100%!

  • @NickDerMitHut
    @NickDerMitHut 3 роки тому +11

    If you also have weird edges when two lights cross each other just tick the "Premultiply Alpha" box for the Simple_Light_Cutout sprite.

    • @masterjohn3126
      @masterjohn3126 Рік тому +2

      Thank you so much bro, made my hour!

    • @NickDerMitHut
      @NickDerMitHut Рік тому

      @@masterjohn3126 glad to hear my weird discovery did eventually help someone haha

    • @djthicc1507
      @djthicc1507 Рік тому +1

      Holy crap I was ripping my hair out because of this you are an angel

  • @NaikoArt
    @NaikoArt 3 роки тому +2

    what an amazing tutorial, very clear and practical

  • @BloodMarket
    @BloodMarket 2 роки тому +1

    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.

  • @rosscondit8090
    @rosscondit8090 4 роки тому

    This is the best lighting tutorial on youtube how does it only have 2,000 views
    AND YOU DID LIKE 2 GIVEAWAYS WTF

  • @mrnobody7600
    @mrnobody7600 3 роки тому +1

    You're amazing bro, it worked very well.

  • @nopetynope
    @nopetynope 4 роки тому +1

    This was super easy to follow. Great video!

  • @pedroamaral1750
    @pedroamaral1750 3 роки тому

    thanks, you saved my game jam.

  • @ro_drigo
    @ro_drigo 2 роки тому

    That's incredible,you did all with codes,I would draw all lights 😂

  • @larryinc64
    @larryinc64 Рік тому

    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.

  • @MetaHootOriginals
    @MetaHootOriginals 4 роки тому +1

    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.

  • @zombimana9518
    @zombimana9518 2 роки тому +1

    for some reason I can't create a colored light. I did everything as in the video

  • @nikolay-tsys
    @nikolay-tsys 2 роки тому

    Thank you so much, man!

  • @fabbbydoo
    @fabbbydoo 4 роки тому +2

    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.

    • @GameMakerCasts
      @GameMakerCasts  4 роки тому +3

      100% not tricky at all! you basically end up looking for the play object and drawing the cutout around them. Does that make sense?

    • @countingsunflowers
      @countingsunflowers Рік тому

      @@GameMakerCasts how do you do that plssss?

  • @pipi7928
    @pipi7928 3 роки тому

    Awesome! Thats really really cool!

  • @heikkiaho6605
    @heikkiaho6605 2 роки тому

    Thanks so much! This was just the info I needed :)

  • @NickDerMitHut
    @NickDerMitHut 3 роки тому +1

    Nice and Simple Lighting system, I like it. Do you know how to make specific background layers not be affected by the light / darkness?

  • @Timeline08
    @Timeline08 3 роки тому +2

    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 ?

    • @sigmagamedev
      @sigmagamedev 2 роки тому +1

      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

  • @Pernesjr
    @Pernesjr 4 місяці тому

    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 :)

  • @scotsparaman
    @scotsparaman 4 роки тому

    Brilliant, easy to follow...

  • @einaryt6972
    @einaryt6972 11 місяців тому

    What do I do If instead of black its a very white surface even though i just set c_black?

  • @dergeilste7926
    @dergeilste7926 2 роки тому

    hey nice video. How did you setup this „skin“ for gamemaker?

  • @professorpicklesphd.8312
    @professorpicklesphd.8312 3 роки тому +2

    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?

    • @GameMakerCasts
      @GameMakerCasts  3 роки тому +1

      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.

    • @professorpicklesphd.8312
      @professorpicklesphd.8312 3 роки тому +1

      @@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?

    • @TheCivildecay
      @TheCivildecay 3 роки тому +5

      @@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

    • @professorpicklesphd.8312
      @professorpicklesphd.8312 3 роки тому +3

      @@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

    • @heikkiaho6605
      @heikkiaho6605 2 роки тому +1

      Yeess! thank you very much! this got me out of a dead end

  • @wierdbob
    @wierdbob 2 роки тому

    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?

  • @itaisinger1360
    @itaisinger1360 3 роки тому

    awesome video! thanks a lot!

  • @guy3480
    @guy3480 4 роки тому +2

    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?

    • @wangsoft
      @wangsoft 4 роки тому

      I had this issue, can fix by lowering the intensity variable.

    • @jaredgc8423
      @jaredgc8423 3 роки тому

      I am having this issue too! Any chance you fixed it?

    • @guy3480
      @guy3480 3 роки тому +1

      @@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

  • @Broelbrak
    @Broelbrak 2 місяці тому

    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!

  • @Robin-rb6qu
    @Robin-rb6qu 2 роки тому

    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

    • @GameMakerCasts
      @GameMakerCasts  2 роки тому

      Make sure the circle isn't touching the edges. If you are still having troubles hit me up in discord discord.gg/HAAW2w2F

  • @siennas254
    @siennas254 5 місяців тому

    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.

    • @GameMakerCasts
      @GameMakerCasts  4 місяці тому

      If you have discord join the channel at discord.gg/hXaMWuwp and I can have a look for you

  • @cameronbrady7304
    @cameronbrady7304 Місяць тому

    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]))

  • @superzilla784
    @superzilla784 4 роки тому +1

    Do you have a link to the paint program you use for this?

    • @GameMakerCasts
      @GameMakerCasts  4 роки тому

      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/

  • @Kaaarrr
    @Kaaarrr 3 роки тому +1

    So awsome tutorial

  • @-breakdancepopcorn-498
    @-breakdancepopcorn-498 2 роки тому

    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

    • @GameMakerCasts
      @GameMakerCasts  2 роки тому

      Sounds like a drawing issue, are you able to send me your project or code and I can look at it?

    • @-breakdancepopcorn-498
      @-breakdancepopcorn-498 2 роки тому

      @@GameMakerCasts sure, let me get a Drive for it

  • @paradoxechogames
    @paradoxechogames 4 місяці тому

    did it but as soon as i added the wobble thing my entire project turned black. for a sec i see the outlines. :(

  • @christophergraf5929
    @christophergraf5929 4 роки тому

    Hey! Great video. Super simple and really effective. By any chance, do you know a way to make the wobble slower? Thanks again

    • @GameMakerCasts
      @GameMakerCasts  4 роки тому

      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.

    • @emmalogue1166
      @emmalogue1166 4 роки тому

      @@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!

  • @Lil_GreeD
    @Lil_GreeD 3 роки тому

    Hey, can I do that with another size? Like a triangle? (I wanna do a flashlight in my game)

    • @GameMakerCasts
      @GameMakerCasts  3 роки тому +1

      You can do this by replacing the light sprite with another one (say a triangle)

  • @jaredgc8423
    @jaredgc8423 3 роки тому

    How do you handle overlapping colours? Mine are producing dark edges in awkward places!

    • @GameMakerCasts
      @GameMakerCasts  3 роки тому +1

      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

  • @ajinkyax
    @ajinkyax 11 місяців тому

    Subscribed 🎉

  • @cosmic5244
    @cosmic5244 2 роки тому

    any way to make the lights not desaturate

    • @GameMakerCasts
      @GameMakerCasts  2 роки тому

      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

  • @Andresalex4
    @Andresalex4 2 роки тому

    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
      @GameMakerCasts  2 роки тому

      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

    • @Andresalex4
      @Andresalex4 2 роки тому

      @@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

  • @squidge147
    @squidge147 4 роки тому

    I have made it so the surface follows the view and now it is not cutting any circles out? Please help.

    • @williambolls1819
      @williambolls1819 2 роки тому +2

      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

  • @eunit08
    @eunit08 4 роки тому

    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

    • @GameMakerCasts
      @GameMakerCasts  4 роки тому

      I usually load up Aseprite (bit.ly/37GKELk) and create the sprites in there, then just copy and paste them over :)

    • @eunit08
      @eunit08 4 роки тому +1

      @@GameMakerCasts ok thanks. Now i can make gradiants and all the extra features that game maker somehow removed for some odd reason

  • @gamerpros413
    @gamerpros413 4 роки тому +1

    amazing tutorial! question though, how do i attach the lighting to the player? Edit: While keeping other lights normal.

    • @WilliamGarrisonArts
      @WilliamGarrisonArts 4 роки тому

      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.

    • @martinzilloxd2111
      @martinzilloxd2111 4 роки тому +1

      **** 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);

  • @MatteoBenaissa
    @MatteoBenaissa 3 роки тому

    What is the game maker skin you're using ? it looks great !
    Huge thanks for the tutorial :)

    • @GameMakerCasts
      @GameMakerCasts  3 роки тому

      Thanks :) I am using the dark dracula theme found at github.com/dracula/gamemaker-studio

    • @MatteoBenaissa
      @MatteoBenaissa 3 роки тому

      @@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 ?

  • @peruano9187
    @peruano9187 4 роки тому +1

    a lot of thnks

  • @Jalecko
    @Jalecko 2 роки тому

    when i run this code on mac my whole screen will just be black

    • @Jalecko
      @Jalecko 2 роки тому

      it does work on windows

    • @GameMakerCasts
      @GameMakerCasts  2 роки тому

      That's really weird as there isn't anything super specific happening. I don't have a mac to test it on :(

  • @bioyado
    @bioyado Рік тому

    noice!!!

  • @TheCivildecay
    @TheCivildecay 3 роки тому

    I like how your gamemaker looks like Godot :D

    • @GameMakerCasts
      @GameMakerCasts  3 роки тому +1

      Thanks, if you want the theme you can grab it at github.com/dracula/gamemaker-studio :)

  • @intensity67
    @intensity67 Рік тому

    W

  • @masterjohn3126
    @masterjohn3126 Рік тому +1

    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

  • @tanura5830
    @tanura5830 2 роки тому +1

    the light looks ugly. But thanks for the tutorial

  • @Silknight
    @Silknight 3 роки тому

    The sliding words at the bottom of the screen are very distracting...

    • @GameMakerCasts
      @GameMakerCasts  3 роки тому

      Thanks for your input, I'll see what I can change up here :)