Shadows Tutorial: Game Maker Studio 2

Поделиться
HTML-код
  • Опубликовано: 18 дек 2024

Комментарии • 186

  • @sixthsurge
    @sixthsurge 6 лет назад +23

    This really improved my game's visuals. Thanks a lot! I also made the day/night cycle affect the shadows, which looks awesome.

  • @windproxy4362
    @windproxy4362 6 месяцев назад +1

    I came for the shadows and stayed to learn about surfaces. Also, I love your style of explaining things. Thank you!

  • @Person5385-w4s
    @Person5385-w4s 4 года назад +37

    if you want to make the shadow scale to the sprite use this
    var sx = sprite_width/2
    var sy = sprite_height/2
    instead of
    var sx = 5
    var sy = 10

    • @Person5385-w4s
      @Person5385-w4s 3 года назад

      @Colby Brian um... ok? but what does this have to do with anything?

    • @sujuzoqedpfqw1996
      @sujuzoqedpfqw1996 3 года назад +7

      @@Person5385-w4s It does have to do with the tutorial. He's just trying to be helpful for people who have that specific problem.

    • @saxenart
      @saxenart 2 года назад

      What does ‘var’ stand for?

    • @Person5385-w4s
      @Person5385-w4s 2 года назад

      @@saxenart It makes the variable a local variable that gets destroyed after the function/event is over. In addition, you can't access the variable outside of the function/event. You technically never need to use them, but did it here anyways.
      If you have anymore questions, or need me to clarify something, I'd be happy to answer!

  • @UliTroyo
    @UliTroyo 7 лет назад +5

    It's hard to believe you're a new channel; your content is on-par with some of the best GM tutorials out there. Not a knock on them; on the contrary-you're just really good.

  • @queenskadi4163
    @queenskadi4163 6 лет назад +7

    this looks amazing, I had never thought of doing something like this, ill keep this in mind when I am ready to add extra flair to my existing project.

    • @lildgamedev6885
      @lildgamedev6885 4 года назад

      me too i've been playing with adding *image_xscale to the sx var but nothing so far

    • @lildgamedev6885
      @lildgamedev6885 4 года назад

      sorry mate wrong person

  • @chlbrn
    @chlbrn 5 лет назад +6

    OMG, you are so awesome. I am trying to make a top-down 2d game similar to early pokemon games on game boy advanced. I am thinking of making dynamic day and night system which requires constant changing shadows and your tutorial definitely helps me on that. Thanks a lot.

  • @brandenfc9601
    @brandenfc9601 7 лет назад +1

    This is a great video for sure! However, if there's anyone out there who doesn't want to hard code a system like this you can use Construct 2 for this kind of effect. To achieve it, Construct 2 comes with objects that do this sort of thing automatically. Instead of typing lines of code (which doesn't look like much here) you can just add the behavior to specific objects with just drag and drop features in C2, and adjust the settings accordingly.
    I hope this helped! Again, wonderful video! I've been trying to learn this myself and this is a rare tutorial to find. Most of the time I found something like this was just simply demos with no instruction. You're great!

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      Thanks Branden! Construct 2 is a great engine for beginners too. Little features like this can add a lot of depth to a game.

    • @brandenfc9601
      @brandenfc9601 7 лет назад +1

      You're most welcome! I love Game Maker Studio 2 and Construct 2 since I've used them both. They're great for their own reasons. :D I also agree that it adds a lot of depth to a game.

  • @SwowChowsk
    @SwowChowsk 7 лет назад +1

    This tutorial is worth it's weight in gold! Thank you!

  • @andreseungyeobsong4899
    @andreseungyeobsong4899 4 года назад

    The ultimate and the best shadow tutorial indeed. Thank you 3000.

  • @denisevans213
    @denisevans213 6 лет назад +1

    Superb tutorial, thank you! - I was trying to get my head around using surfaces for shadows, and this was really easy to follow - sorted! - thanks again!

  • @simonjakobsson1004
    @simonjakobsson1004 6 лет назад +10

    If anyone is experiencing the shadows jittering when using a camera object, it's because the x and y values for drawing the sprite are being set as decimal values (I think!). To fix this try using the 'round' function, like this: var viewX = round(camera_get_view_x(view_camera[0])); And the same goes for the viewY.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +4

      Yes this could cause a jitter, especially for low rez games that might have already set up their own camera functionality. Thanks for posting this and your solution :)

    • @videowavecrayon2274
      @videowavecrayon2274 3 года назад

      @@FriendlyCosmonaut Your videos are incredible and have helped me so much to learn about programming, thank you!

    • @videowavecrayon2274
      @videowavecrayon2274 3 года назад

      Thank you so much for posting this, today when I tested my room in full screen I realized I had some jittering in the shadows while moving my character around, I was the whole day trying to figure out what was it and this fixed it. Thanks!

  • @prowokator
    @prowokator 3 года назад

    This is such a good tutorial! You present excellently the topic and dive just deep enough to get things going!

  • @LostTalent
    @LostTalent 7 лет назад +13

    You are amazing! Thank you for this

  • @Stanislav_Belyaev
    @Stanislav_Belyaev Год назад

    You're the best! It is clearly all that I need! Thank you.

  • @HenrikoMagnifico
    @HenrikoMagnifico 5 лет назад +4

    I noticed the shadows don't transform depending on the xscale / yscale of the object. Is there a way to fix this?

    • @lildgamedev6885
      @lildgamedev6885 4 года назад

      me too i've been playing with adding *image_xscale to the sx var but nothing so far

  • @diederikwillems6782
    @diederikwillems6782 5 лет назад

    Found your channel by it being recommended after watching Heartbeast and Shaun Spalding. Amazing stuff you've got here. Thanks for the explanation! No more elliptical shadows for me! ;)

  • @Essencerater
    @Essencerater 6 лет назад +3

    Thank you for showing me this! I do have one question though: If I want to make the height/length of the shadow relative to the height of the object like in real life (taller tree, taller shadow). Can I still use this same method or do I have to make the shadows manually as part of the sprite as I have always done before?
    Thought it looked kind of funky how the small bushes had the same size shadow as the buildings etc.

    • @coreywest9597
      @coreywest9597 4 года назад +2

      This is probably way too late but if you wanted to keep things simple you could probably just have multiple parents for different height groups (short, medium, tall, extra tall) and adjusted the variable accordingly, then set the objects' parents to whatever one you felt fit best.
      edit: Now that I think about it you could probably also just do some simple maths when setting the shadows length/height by doing something along the lines of, say, var sx = sprite_width
      * n where n is any random number you feel like putting there (experiment with it). Keep in mind I haven't tested this out so you may need to delve a little deeper into it to get it working, but you get the idea.

  • @FrozenFlameInt
    @FrozenFlameInt 7 лет назад

    Another great tutorial. Thanks for making these. (your other GMS2 tutorials are very well done too!)

  • @patriciaduffy2479
    @patriciaduffy2479 3 года назад

    I love your tutorials! Thank you so much.

  • @prod.n8te
    @prod.n8te 2 года назад +1

    Awesome tutorial! I’m having a problem, though.
    I want the shadows to face away from an object as if it was casting light. However, I haven’t really been able to get my head around it. Any help?

  • @PooWhistle
    @PooWhistle 5 лет назад +1

    This was invaluable!

  • @Banex01gosha
    @Banex01gosha 3 года назад

    Thank you so much! For some reason, I haven't thought about "with" statement. I was trying to forse every object to draw in the shadow surface, after which obj_shadow draws the surface, but because the room in my game is giant and there's a lot of objects game was lagging. But using "with" it doesn't lag!

  • @GlennThomasJr
    @GlennThomasJr 6 лет назад

    Beautiful description

  • @andrewweller5119
    @andrewweller5119 6 лет назад

    What a fantastic tutorial. Thank you.

  • @Xzaryo
    @Xzaryo Год назад

    I'm not sure if @friendlyCosmonaut you are following the comments at all but I have a few questions.
    1. If I draw the shadow on a character,npc, player object etc. the shadow will change depending in which direction my toon is facing. So the shadow falls left if my character or NPC looks left or it falls right when I or the NPC looks left. Of course the simplest workaround is to use a different shadow ( for example the simple eclipse shadow under the character ) but I am wondering if this can be fixed with code ?
    2. I would like for the shadows to cast shadows also on object "below" the shadow. If my character walks under a tree where the shadow falls I would him to also get the same color as the shadow, the same for the stone which is under tree and has a shadow on its own. Is that possible ? Please keep in mind that I do not use priority to determine the depth, I use a simple line of code in the step event in the parent object : depth = -bbox_bottom; . So I already tried to move the instance layer above the player but it doesn't really work.
    Do you maybe know or have had similar issues ? :

  • @connorhagerty537
    @connorhagerty537 7 лет назад +3

    If your sprite's canvas is larger than your sprite itself, it'll give you a much larger number than you'll want. In that case, ,use (sprite_get_width(mask_index) * image_xscale)/2 instead. It'll give you the collision mask of the sprite instead.

  • @Erzyl
    @Erzyl 6 лет назад +1

    Thanks for the tutorial! Do you know if there is any way to get this method to work using vector images (swf files) as draw-pos does not support them?
    Draw-ext doesn't look nearly as good and it would be a bit tedious to create a shadow version (non swf) of each image with animation.

  • @oldmanmike9658
    @oldmanmike9658 7 лет назад +1

    Nice tutorial, done something similar in the lighting system I have. I am currently trying to work out how to change the shadow skew when the shadow hits a "vertical" surface, ie the shadow stretches across the "horizontal" surface and skews when it hits the "vertical" all dependant on "light" position. Currently thinking about using another surface to draw the altered shadow, but currently struggling to conceptualise how to detect when this should happen, any pointers or ideas welcome.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      Ah, this probably won't be the easiest thing to do. I'd suggest taking a look at primitives or vertex shaders for this, as you'll want to control the "vertices" of how the shadow sprite gets drawn. Unfortunately I don't know of any tutorials that cover this sort of thing so I can't point you anywhere other than the documentation for primitives/shaders!

  • @maspolyfilho4893
    @maspolyfilho4893 3 года назад

    Ajudou muito! Estava procurando um tutorial assim há muito tempo.

  • @andrehockaday8855
    @andrehockaday8855 3 года назад

    This was very helpful and easy to understand thanks to you 5 out 5

  • @sunnysparkgames
    @sunnysparkgames 3 года назад

    Awesome video. I'm currently working through your farming tutorial as well. I've just finished the day night cycle. Everything is working fine. You started to go into how to add this to a day night cycle, but I'm wondering how would you add this to your day night cycle?

  • @andreyin
    @andreyin 7 лет назад

    Thanks for these! I have a question, why doesn't it work with a single object instead of two? I mean, at 13:50 you create a shadow object with the code from the parent object, then set them to the layer. Why doesn't it work if you only have the obj_parent with the code itself and assigned it to a layer?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      This is a great question! The short story is: you don't "have" to create the second object... but doing so means the system does a lot less work then it has to.
      Longer story: if we put all the code in the parent object, that means every single child would be running every single line of code. That means we'd be having to check that the surface exists in every child, having to turn on the fog, and then drawing the surface multiple times. As we create more and more instances in the room (tens, perhaps over a hundred), you can see how costly this would all get!
      I know that it may seem a little excessive to have two abstract-seeming objects for this system, but having lots of object parents is very much the norm, and an essential part of object management/hierarchies/organisation. It helps to think of this in the context of a larger, established game. Let's pretend we have dozens of objects. NPCs, dogs, cats, trees, chairs, fires, stars, food, health, potions, plants... the list goes on and on. In such a case, it will make sense to have various parents for those objects (enemies, friendlies, furniture, light sources). So this "obj_parent" in the video would just be something at the top of the hierarchy, that links together everything with a shadow. Whereas, obj_shadows is not a "parent" object, it's an object that does work - it draws all the shadows.
      I hope that makes sense and puts things into perspective!

  • @dannytalk8902
    @dannytalk8902 4 года назад +3

    The shadow is a little bit jittery for me is there any way to make it more solid?

    • @videowavecrayon2274
      @videowavecrayon2274 3 года назад

      I'm having this same issue, I managed to create a "static" ellipse shadow for my objects, although when I move it looks a bit jittery. I'm guessing this is because every time I move the shadow is being erased and redrawn in the same position, which makes it look jittery. I'm unsure if something can be done.
      *Edit* : Don't think you'll need it anymore but the solution to fix it is in the comments below, you have to use this variables instead: var ViewX = round(camera_get_view_x(view_camera[0]));
      var ViewY = round(camera_get_view_y(view_camera[0]));
      The reason is because the x and y values for drawing the sprite are being set as decimal values.

  • @jimcoganvids
    @jimcoganvids 7 лет назад

    Really liking your tutorials and your measured, clear explanations of the principles. Only think I'd really like is that when you typing out or going through lines of code, even on full screen the text is pretty small. I can just about read it if I get close enough to the screen (apologies, I'm short sighted), but would love it if you could figure out a way of zooming in a little so it's clearer from a regular distance.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Thank you! Yes in my latest videos I've taken up the habit of increasing the text size in the videos, but unfortunately a few of the older ones are like this.

  • @adamskvorak6865
    @adamskvorak6865 7 лет назад +3

    Could you make a tutorial about how to make an inventory system like the ones in Pokemon or Final Fantasy? It's really hard to find nice, well-explained videos on it. Keep up the great work on the videos!

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +2

      Yes! This is definitely on the to-do list for future videos.

    • @YourBuddyDinec
      @YourBuddyDinec 7 лет назад

      Were you able to find any tutorials on that? I've been looking for one for a little while now. While i love Coamonauts videos on menus those are mostly for start menu types.

  • @spacerobotTR
    @spacerobotTR 7 лет назад +3

    This is awesome! Question: How would you apply this to tilemap layers instead of child objects? Is that doable?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +5

      You mean apply shadows to tilemap "objects" like a house made of tiles? Ooh, that'd be tricky. I wouldn't say it's not doable -- everything is if you throw enough code at it -- but I'm not sure it'd be worth the hassle. Perhaps it's just beyond me; if anyone else has ideas, I'd love to hear them!

    • @spacerobotTR
      @spacerobotTR 7 лет назад

      Yeah I was thinking how cool it would be to have a tile layer and any tiles that were placed on that layer generated shadows in a similar way your system does. Instead of using actual objects under a parent. I'm doing all tile collisions and trying to reduce as many objects that I don't need.

  • @patrickkirkby102
    @patrickkirkby102 5 лет назад

    Great tutorial! I've got it working for the most part. I have a z-axis in my game, and I'm trying to make the shadow shrink as I jump. I have a zsp that determines my height. Any idea how I would implement an equation that could somehow use my zsp and shadow size to shrink/grow as I am in the air? I know it's asking alot, so don't feel pressured to answer that lol.

  • @IzanagiTheGod
    @IzanagiTheGod 6 лет назад

    Fantastic tutorial, allowed me to do simple ground shadows to add that little bit of graphical flavor, and I really appreciate you teaching what each line of code's purpose is, very informative.
    I know the video's a bit old at this point, but was wondering if there was a way to reverse the image_xscale of the shadow when the object's sprite_index's image_xscale is flipped. I feel like the answer is simple but I can't seem to figure it out. Thanks again, cheers.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад

      Actually this should be happening automatically with the function draw_self(). But you could use draw_sprite_ext(sprite_index, image_index, etc) and plug in all of the instance's variables to be sure.

    • @IzanagiTheGod
      @IzanagiTheGod 6 лет назад

      Unfortunately it didn't do it itself, I would have thought it would do it automatically as well but for an odd reason it always draws the xscale = 1 version. However I did find a solution, which was to interchange the x1 and x2 with each other if the obj's image_xscale = -1, so the sprite's specific corners are flipped therefore flipping the sprite. I appreciate the reply though, thank you.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад

      Oh, doh! I was mis-remembering this video. Of course, draw_sprite_pos was just stretching the co-ordinates to a scale of 1! You found the perfect solution, well done :)

    • @ras3275
      @ras3275 6 лет назад

      Everything works except this one! I just realized same problem too. Static objects are fine but with animated objects(like a player or enemy) it always shows xscale = 1 on shadows. I'm a beginner, How exactly do i fix it?
      Also, i'm using draw_sprite_ext(); because i don't need to skew or anything.

  • @oakbyte4580
    @oakbyte4580 3 года назад

    Great video!

  • @Д.Д-ж9ж
    @Д.Д-ж9ж 7 лет назад

    Great tutorial! Keep it up!

  • @jurreosinga4175
    @jurreosinga4175 7 лет назад +1

    Thank you for the amazing tutorial! i have one question tho. My sprites do not fill the entire width of the sprite (with this i mean, the guy i'm trying to draw the shadow of, has some empty space on each side to later animate sword animations etc). This makes the shadow of the person im drawing really wide, any ideas?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Hmm! As you probably know, this is happening because of our use of "sprite_width" (or sprite_width/2, anyway). Instead of using that, we could make up a variable called "shadow_width" and declare it in the create event of the parent. As it's default value, we'll make it shadow_width = sprite_width, and we can just leave it at that for objects and sprites that don't have this problem (the children will inherit this value). But for children that you want to tweak the shadow width, you can go to their create events and redefine the value as something else -- it will overwrite what it got from its parent.
      Note: if you have any objects that already have a create event, but you want them to inherit shadow_width, you'll have to put "event_inherited()" in their create event.

    • @jurreosinga4175
      @jurreosinga4175 7 лет назад

      Alright, thanks a lot! Just one other question, in my game i move the camera around with my mouse, and i have a zoom function as well. When zooming out, the shadows won'' draw the way i intend to. Is there maybe a way to contact you so i could show you?

    • @jurreosinga4175
      @jurreosinga4175 7 лет назад +1

      never mind, i fixed the problem!

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Haha, well done :)!

  • @TheCivildecay
    @TheCivildecay 7 лет назад

    awesome tutorial!
    but shouldn't image blend work for making the shadow black?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Not for the later section where we use draw_sprite_pos -- there's no way to set a "blend" for this, so we have to do it ourselves with the gpu_set_fog. You could also use a simple shader to accomplish the same thing.

  • @SerumTjmp
    @SerumTjmp 6 лет назад +1

    Hey friendlycosmonaut, amazing tutorial as usual, however how do i mix the shadows together with the depth system? I can't seem to get it to work, where do i put what etc.

    • @vimabo5570
      @vimabo5570 6 лет назад +1

      I figuered it out, lol xD
      So you set your objects as your children in your "obj_parent_xy", right? But you are NOT allowed to have multiple "obj_parents_xx" with the same "obj_children". Thats why you have to create only one "obj_parent" with your children-objects and replace the "obj_parent_shadow" and "obj_parent_depth" in your code with your new single obj_parent.
      i hope you understand me.

  • @VojBer
    @VojBer 6 лет назад

    Your tutorials are amazing

  • @LoggyDev
    @LoggyDev 4 года назад

    This helped with my mario maker type game :thumbsup:

  • @waxfreeointment2121
    @waxfreeointment2121 5 лет назад

    Lovely video, if there anyway to get this to work in GM 1.4? the gpu_set_fog doesn't exist, but I looked in the manual and there is a "gm_FogColour" and "gm_PS_FogEnabled." Also, how would I make a shadow for an object using a layered-sprite fake 3D?

  • @OneHewMan
    @OneHewMan 6 лет назад +3

    Those using GMS1.4 can substitute the function "gpu_set_fog" with "d3d_set_fog".

    • @Diegovz01
      @Diegovz01 6 лет назад

      and the camera_get_view_x()? how?

  • @MiguelAngelValdepenaDelgado
    @MiguelAngelValdepenaDelgado Год назад

    dudas se podra para GMstudio sip sip utilizo surface ... excelente sus videos son geniales siga haciendo mas videos en game maker ....

  • @TheRealZen00
    @TheRealZen00 7 лет назад

    Very nice, not perfect shadows, but then who needs perfect when good enough does. :)
    Though I am curious as to what kind of programming is needed for absolutely pixel perfect shadows, such that if they hit another object they'll climb up it properly and stuff like that.

  • @DarkMatterVisible
    @DarkMatterVisible 7 лет назад +1

    You're a wizard.

  • @kilomatter
    @kilomatter 4 года назад

    Thanks a bunch, this was a very helpful video. I managed to add a bit of code to allow the shadows to move realistically when the player jumps! Basically, I have two variables in my player object, one called 'z', which tracks the player's position above the ground, and one called 'yfloor' which tracks the point on the ground which the player is floating above when he jumps. So in the 8 arguments for the draw_sprite_pos function, I changed all mentions of 'y' to 'yfloor', and I subtracted 'z' from each argument. To make it more accurate, I subtracted '(z/2)' in the y position arguments instead of just 'z'. The main thing I had to change is that I had to add the 'z' and 'yfloor' variables to objects that didn't use them already.

  • @carles_roch_arnau
    @carles_roch_arnau 6 лет назад

    Another great tutorial, I am combining this with the depth system but once I set the children to the obj_shadow the obj_dpeth code stops working, I suppose that it overwrites it. Should I mix the two of them together in one object? The problem is that I may have an object with no shadow and depth system. Thanks

    • @carles_roch_arnau
      @carles_roch_arnau 6 лет назад

      Oh and also, I'm having problems with drawing shadows on sprites that are drawn in a canvas a bit bigger than them, I mean that there's a bit of leftover pixels in the sprite wich are transparent. An example is my main character, it's drawn in a 32 * 32 square but it logically doesent occupy the whole thing. The problem comes when drawing the shadow (I removed the X offset to solve this bug), it draws a shadow 32 * 32 shadow with the shape of the sprite, it deforms the sprite to fit the shape of the canvas wich is pretty annoying. I suppose that the function "sprite width" counts the width of the sprite as the canvas width, the sqare where the sprite is drawn, but the function you use to draw the deformed shadow counts the four points only where it is drawn. How could I fix that, do I relly have to make all rthe "canvases" fit the size of my sprite? Thanks a lot for your dedication

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад +2

      Hey Carles, sorry for the late reply - yes once you make the objects children of one object and not the other they'll stop inheriting from it. You might have to make the depth object a child of the shadow or vice versa. Then you could have a toggle for whether to draw the object as part of the depth/shadow, like "depthObject" and "shadowObject". These would be set in the parent as true by default (all the children will inherit this), and you can manually go into objects you don't want to have as part of either system and mark them as false. Then, have a check in the draw code to exclude any object that has those variables marked as false from the drawing process.
      As for the width issue - you could put in a special case for those objects but yeah the simplest thing to do here is to remove the "whitespace" from the sprite, as annoying as that is!
      Hope that makes sense!

  • @corpsenia8622
    @corpsenia8622 2 года назад

    I was using this in the game that I'm developing: Corpsenia. But that was a problem: the shaders, after going to other room, accumulated above the previous and them it consumed a lot of processing. I mannage to make a shadows script that don't uses shaders only draw_sprite_ext but this worked well only for the player instance. I'm trying right now to creat a shader script optimized. So I'm watching again your video haha. I hope that I'll have luck with this

  • @erikj.4595
    @erikj.4595 6 лет назад

    I've noticed that the draw_sprite_pos function defines the BOUNDING BOX of the sprite to draw. Because my sprites don't occupy the whole of the image size, my shadows ended up wider than they should have been. Modifying the points to have "bbox_left" rather than x-sprite_width/2, etc. fixed this issue.

  • @victoonix2802
    @victoonix2802 4 месяца назад

    this works, though the shadow won't invert its scale when the reference object does (and understandably so!)
    Problem is, I can't figure out how to invert its scale since all of the "drawing" part happens in a single function, so its abstracted from me

  • @mst3ksanta
    @mst3ksanta 7 лет назад

    fantastic videos btw!! you're sure to get lots of views and subscribers in the next few years

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Thank you! I can't seem to find your other comment so I will reply here:
      Yes you could have your sprites centred. In the parent object, setup a variable called y_offset = sprite_yoffset. That way, all the children will set this variable in their create event.
      Then in the draw object, instead of draw_self(), use draw_sprite(sprite_index, image_index, x, y+y_offset);

    • @mst3ksanta
      @mst3ksanta 7 лет назад

      thanks! i figured it out while tinkering which is why i deleted it ^_^

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      Ah no worries then. Thank you!! :)

    • @mst3ksanta
      @mst3ksanta 7 лет назад

      Is there any difference from using lengthdir_x and lengthdir_y instead of (room_width/2)-mouse_x and (room_height/2)-mouse_y. I threw in lengthdir just because i'm used to using it and got about the same results but does it put more stress on the game?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Huh, no, I didn't actually think of it at the time (I sort of just threw that line of code in there as an example). Vector stuff is probably the easier way to go, so feel free to use it! I don't think there'd be much of a difference to performance one way or the other.

  • @DriftyG
    @DriftyG 7 лет назад

    Keep up the good work FC. :)

  • @theharvestfloor1
    @theharvestfloor1 2 года назад

    Thanks for this.

  • @MasonYoungPlus
    @MasonYoungPlus 5 лет назад

    Hmm, does gpu_set_fog not work on HTML5 Targets? Great Video!

  • @EmoJoshSavesTheWorld
    @EmoJoshSavesTheWorld 5 лет назад

    This is cool, but there is still an issue. What if the shadow being casted needs to be drawn over the player or another object? For instance, if the player is standing under a tree, obviously the tree's shadow should be drawn over the player, but if the player is standing under a rock, then the player should not be affected because the rock's shadow is under them. Do I just have to draw those specific shadows on a separate layer?

  • @bjornegner5613
    @bjornegner5613 7 лет назад

    Hi! This was great, do you have any tips on how to do indoors lightning? I'm trying to make it so that I can have the shadows point away from an invisible object in my room, the way a ceiling lamp would make things cast a shadow in the opposite direction from it. I've played around to try and fix it on my own, but I can't get it to work. I want the skew of every object to be different depending on where they are in relation to my light source, but instead every object has the same skew as my player object. Also, I'm not sure how to make the skew of my shadow change every time my player moves.
    PS: I'm a complete noob.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Thank you! Ah, to be honest, this probably requires a lot of fiddling and a good deal of math (vectors). It sounds like instead of a set skew, you'll want to be getting the direction and distance objects are from the light source, and then change the skew accordingly. So, you'll want to be using the functions point_direction() and point_distance(). Definitely have a look at those in the documentation (you can type them in to a code block and then middle click to bring up the appropriate page). You'll also probably need the lengthdir_x and lengthdir_y functions, as you'll want to be creating vectors the shadow should follow, extending from the object.
      Essentially, what you'll need to do is get the point_distance and point_direction of the light source to an object. Then, you'll want to translate the "point_direction" into horizontal and vertical components with the lengthdir_x/y functions. The length of these components should depend on the point_distance. Once that's all calculated, you can use this information to form where the shadow should be located.
      This is a little "advanced" if you've never met with these concepts before, but to be honest, it would make a great beginner exercise if you can get your head around all the functions and vector concepts.

    • @bjornegner5613
      @bjornegner5613 6 лет назад

      Hi! Thanks for the helpful response, I messed around with it for a while and kind of got it to work, but I ended up scrapping it because I felt like It'd have to be far more complex and way beyond my skill level to get it to work the way it should. Here's a screenshot to explain the problem imgur.com/a/9Gfbm, it should have been obvious to me that this method wouldn't work when the shadow is in front of instead of behind the object, because you'd need the shadows to "extrude" from 3 points instead of just 2 (that's my best attempt to explain it in words, haha).
      Also, THANK YOU for the inventory system tutorial. I've had a literal massive headache trying to find a guide for that and yours is the only one that made any sense to my noob brain.

  • @kiu-dp
    @kiu-dp Год назад

    caramba, voce salvou minha vida

  • @AvSias
    @AvSias 3 года назад

    Brilliant, thanks! Could you please also do a tutorial on cameras and views. :D

  • @chrisrosa2781
    @chrisrosa2781 4 года назад

    i have one issue not about the surfaces itself but the way my game is set up i have a z axis and you can jump on stuff with a higher z and i have the shadow follow the players z_floor and since the surface for the shadows are drawn behind everything they arent seen when i jump on a platform because its behind the platform sprite. I hope i explained that right

  • @Diegovz01
    @Diegovz01 6 лет назад

    Hi, is there an equivalent function to camera_get_view_x(view_camera[0]); in order to make this work on Game Maker Studio 1.4? Thank you.

  • @BScotch
    @BScotch 7 лет назад

    Fantastic.

  • @EmoJoshSavesTheWorld
    @EmoJoshSavesTheWorld 5 лет назад

    Could you please make a follow up tutorial on the last part before the video ended, with the shadows rotating throughout a day cycle?? This is really what I want but I can't figure it out...

    • @Person5385-w4s
      @Person5385-w4s 4 года назад +1

      i know it a bit late and you figured it out, but this is for other people who see your comment. in a create event of an object write alarm[0] = 700; (this should change depending on the day speed). then in the alarm[0] event write obj_shadow.cx ++; obj_shadow.cx ++;. that should work, but i didnt test it

  • @Phenixio96
    @Phenixio96 7 лет назад

    Hey Friendly Cosmonaut! I love your tutorials and I get through them very quickly, but I get stuck after this one.
    I really want to make a day/night cycle with the shadows based on the time of the day like said it in your video.
    I made a simple time system(not optimized at all but working) and a surface darkening when dusk comes and lightening when dawn comes, but I am struggling with the shadows.
    Could you please help me a little with what maths I have to use for the skew?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Hey, thanks! It depends on what you want the shadows to do exactly. Could you describe what you are imagining happen to the shadows as the day progresses?

    • @Phenixio96
      @Phenixio96 7 лет назад

      I would like to have shadows following the path of the sun, with a dawn, were the shadows are long and going from the object to the east(room's right), at noon the shadows are inexistant (or not long at all and going to the north) and a dusk were the shadows are also long but going to the east.
      All of this dynamically and progressively, with a little shadow_height to have the impression of the sun being above the camera.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Ah okay. I might do a follow-up video and include something like this. For now, I've tossed together some images that should help you out: i.imgur.com/7pMGjrM.png
      The result of what it should look like is this: i.imgur.com/A3sWwyd.gif
      Obviously tweak variables as needed. Personally I liked the look of going south -> north, but you could just increase the skewX more to do it the other way around.

    • @Phenixio96
      @Phenixio96 7 лет назад

      Thank you a lot for your help. I am moving towards the CBNA Smart Light engine who manages lights, shadows and time way better than everything I can do but I will improve my code with your example to finish it, maybe if I want to change later.

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      No worries! Good luck.

  • @Robobermann.
    @Robobermann. 2 года назад

    very helpful

  • @rinkun6689
    @rinkun6689 4 года назад

    Does this work with 2.3 ? I downloaded your game file but it just shows a black screen .. it did had to convert a few things but not sure

  • @wangsoft
    @wangsoft 7 лет назад

    How could I make it so the shadows are relative to a light object? So the shadows move away from an object instead of the mouse? Great tutorials :)

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      So kind of like how I've done my mouse stuff, visible at 20:50, but instead of mouse_x and mouse_y, you'd grab obj_light.x and obj_light.y. Then you'd just flip the minuses to pluses so the shadows go away and not towards it.

    • @username91011
      @username91011 7 лет назад

      Hi there. Fantastic video. I've been trying something similar (using a light object).
      With the code below, I can get it to lock onto whatever the nearest light object is, and it adjusts to character position and looks great:
      var light = instance_nearest(obj_parent.x,obj_parent.y,obj_light);
      var sx = light.x - lerp(light.x, obj_parent.x, 5);
      var sy = light.y - lerp(light.y, obj_parent.y, 5);
      However... my main issue is that while it works... the shadows are doing the opposite of what they would in real life. The closer the parent gets to the light source, the smaller the shadows get and the further away, the bigger(times infinity). I'd love to flip it so that it is closer to reality, I figure it must have something to do with the y values in the 'draw_sprite_pos' but I've been banging my head and can't for the life of me figure it out. If you have any ideas, that'd rock! Regardless, love the channel, keep it up!

    • @wangsoft
      @wangsoft 7 лет назад

      Do you mean like this:
      var sx = room_width/2+instance_nearest(x, y, o_light);
      var sy = room_height/2+instance_nearest(x, y, o_light);
      still not working though lol
      Thanks for your help :)

    • @wangsoft
      @wangsoft 7 лет назад

      cool thanks, what is your obj_parent object reffering too?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      Thanks Hamish. The answer is: fiddly maths, where we make the shadows LARGER when the distance between the objects gets SMALLER. At the moment I'm using the reciprocal (1/distance) to do this, but it needs some other magic factors. I'm just madly finishing up a game for the low rez game jam (finishes in a few days), but after that, I'll probably make a video on this. I was playing around with it and got it working with multiple light sources too. But I'm not too happy with my "fiddly math" yet (the shadows not growing at a "rate" I would like), so still have to tweak it.

  • @kurdtcoben
    @kurdtcoben 6 лет назад

    Very nice tutorial. I tried it out myself, however the draw_sprite_pos( ); just won't work for me. I've tried everything that's to my knowledge and I also tested if other draw_ methods would work (they did) but draw_sprite_pos won't generate a sprite for me. Do you have any clue why this could be happening?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  6 лет назад

      Hmm, nothing comes to mind. If other functions are working but this one isn't, I can only guess that the co-ordinates that you're plugging in may not be right? You could be putting them in the wrong order. It should be top left (x,y), top right, bottom right, bottom left.

    • @kurdtcoben
      @kurdtcoben 6 лет назад +3

      Thanks for the reply. I think I messed up the order of the coordinates or something. Didn't catch that when I was testing most likely since I've tried it multiple times with different sprites and on different projects. It's working fine now, thank you for helping out!
      Love your content btw, been watching your videos for that past few days and it's been really helpful and (more important) insightful!

  • @TheLol771
    @TheLol771 7 лет назад

    Awesome! Thank you =)

  • @OrangYT
    @OrangYT 7 лет назад

    nice tutorial, however, i'm trying this on game-maker studio 1 and the function "gpu_set_fog" doesn't exists so i cant make my shadows black! Do you happen to know a workaround for this?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Yeah the function you'll want is d3d_set_fog. Here it is in the docs: docs.yoyogames.com/source/dadiospice/002_reference/drawing/drawing%203d/3d%20lighting%20and%20fog/d3d_set_fog.html

    • @OrangYT
      @OrangYT 7 лет назад

      thanks a lot! Your tutorials are super informative and well made for how new of a channel you are, keep up the great work!

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      No worries, thanks Harvey! :)

    • @Diegovz01
      @Diegovz01 6 лет назад

      @Harvey Rupp Hi, did you got it working on game maker studio?, can you tell wich function did you use to replace camera_get_view_x? Thanks

  • @hiauuu
    @hiauuu 7 лет назад

    Awesome! Thank you, thank you, thank you!!! =D

  • @IDontDoDrumCovers
    @IDontDoDrumCovers 7 лет назад +1

    what are they player things? theyre so cute? are they in a game youre making?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Haha no, they were just simple assets I threw together for these tutorials. But thank you!

    • @IDontDoDrumCovers
      @IDontDoDrumCovers 7 лет назад +1

      to bad, they look really cool. it should be a game ^.^

  • @flashjaysan1
    @flashjaysan1 7 лет назад

    Brilliant!

  • @MeMoMcOficial
    @MeMoMcOficial 4 года назад

    sos una geeniiiiaaa!! XD

  • @direwoofles9857
    @direwoofles9857 6 лет назад

    The finished project link doesn't work for me ;-;

  • @Etsa
    @Etsa 7 лет назад

    The shadows don't seem to play nice with the depth video that you did. I either have shadows or they don't change depths. Any idea what I could do?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      I'm away from my computer for a couple days so unfortunately can't test this. But I believe the problem is arising because we can't have an object have two parents. We can however do the next best thing: make one of those parents a child of the other parent. So, make the parent object from the shadow tutorial (obj_parent) a child of the parent object from the depth tutorial (obj_parent_depth).
      Let me know if this works -- otherwise, there's a couple more things I can test once I'm at my desktop.

    • @NoxComet
      @NoxComet 7 лет назад +1

      It does work :D Thank you!

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      Yay! :)

  • @breakmt
    @breakmt 7 лет назад

    Great tutorial! Thank you! I'm wondering why do you use gpu_set_fog instead of draw_set_colour?:)

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      The draw_set_colour wouldn't actually work in this case, as the draw_sprite_pos will ignore all those draw_set settings. It just draws the "raw" sprite. So we have to take a different tact - the gpu_set_fog changes how the GPU is renders the sprite.

  • @chrisrosa5382
    @chrisrosa5382 6 лет назад

    does this work with gamemaker studio 1.4

  • @fierorecensione5828
    @fierorecensione5828 Год назад

    top video!

  • @NgaeGameStudio
    @NgaeGameStudio 3 года назад

    What if the char jumps?

  • @elkkuthebaws1043
    @elkkuthebaws1043 7 лет назад

    So my sprite area is bigger than the sprite it self. When going vertically the shadow changes size and I think it is because the animation does something, but I don't know what. I already set new variables to replace the sprite_width. Does anybody know what is the problem?

    • @elkkuthebaws1043
      @elkkuthebaws1043 7 лет назад

      Well, my animation is first 4 pixels wide and it changes in walk animation to 6. And my sprite canvas (or whatever it is called) is 16 pixels. So should I change it so every time when it is at this certain animation and also every time when image_index is at the certain pictures then change the sprite_width. Or is there any easier way to do this?

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      I'm not 100% sure I'm understanding you. Could I see a gif/video/picture of what's happening?

    • @elkkuthebaws1043
      @elkkuthebaws1043 7 лет назад

      FriendlyCosmonaut Yes I will link it here later cause I can't be on my computer right now

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад

      I see the problem, I think -- when the player is on the side and the shadow's width appears greater than the player. I'm not entirely sure but I think it has to do with your sprite sizes, and drawing "empty space". Could you reduce the canvas size so that it's 6 pixels wide (so that the player picture "fits perfectly" inside it)?

  • @undercoveragent4446
    @undercoveragent4446 5 лет назад +1

    i am getting an error "trying to draw non-existant sprite" when Im using the second option (all shadows will be drawn with a single object)

    • @Big_Joe
      @Big_Joe 5 лет назад +1

      Joshua Auvia Patricia Pagcaliwangan I had the same issue but I worked it out, the object I was referring to with the ‘with’ statement didn’t have all the other objects as children. I’m trying to use this in conjunction with the depth tutorials.

  • @dmmr69
    @dmmr69 6 лет назад

    Thanks :3

  • @DarkMatterVisible
    @DarkMatterVisible 7 лет назад

    For some reason this caused a fatal error in the code from the updated depthgrird tutorial.

    • @DarkMatterVisible
      @DarkMatterVisible 7 лет назад

      Aaaaaand now it doesn't run at all after I removed this code, even though I didn't even touch the depthgrid code and this is the only code I added or even opened. Coding is "awesome".

    • @FriendlyCosmonaut
      @FriendlyCosmonaut  7 лет назад +1

      Yeah there are some pretty significant changes between the two videos... even the smallest change/mistake can mean the system doesn't work. I can't really guess the error without seeing your code -- I'd suggest having a look at the finished project's code (link is in the description) and comparing it with your own.
      Don't give up! Programming is fiddly work :)

  • @saxenart
    @saxenart 2 года назад

    Why si the NPC walking over the player character?

  • @Flamenc0
    @Flamenc0 Год назад

    Really should've used shaders for that, it's not optimal