1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. NOTICE: We will be applying a Xenforo update on Tuesday 25th of February. This means that from approximately 10:00 to 14:00 BST the forums will be offline (or possibly longer). Sorry for the inconvenience! Official Announcement here.

GMS 2 Have light source's glow only tint the player under certain conditions?

Discussion in 'Programming' started by OblivionSkull21, Sep 20, 2019.

  1. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    Sorry if this seems like it belongs in the Advanced Programming section.
    I have a concept that I'm wanting to try to accomplish, but I'm lost on how to do it.

    I currently have a day/night cycle that involves a black "darkness" moving across the screen from left to right to represent sunrise/sunset and covering the room in darkness to simulate "night time".

    When the darkness reaches the light source, the light's glow gradually gets drawn from left to the right, following the movement of the darkness until the whole glow is visible, like so:
    [​IMG]
    I am using a surface and some very complex code to do all this. Right now I have it so that the player is subtracted from the surface and not covered by darkness at any point, though I think I want to get rid of that.

    What I would like is for the player to only get light if they approach a light source, but I want that light source to change the player's color. For example, if they're standing next to the orange glow, I would want the glow to be drawn on top of them. This is all fine and dandy, because all I have to do is get rid of the player's subtraction from the surface and voila, the glow is covering the player, like so:
    [​IMG]
    HOWEVER, to be more realistic, I don't want the glow to effect the player unless they are behind/above the light, or any part of their body is visibly facing the light. What I mean is, I wouldn't want the player's back to turn orange because their back isn't facing the light, their front is... make sense?
    So, I wouldn't want something like this:
    [​IMG]
    The problem is, I have no idea how to accomplish this. All the glows and the darkness are drawn on one surface, with the actual light source (the fire) being subtracted (cut out) from that surface. I guess I would want the player to be subtracted as well, but only if they're in the glow and behind the light source, as I would still want the darkness to cover them elsewhere.

    What are your ideas? Perhaps I could try separating the glows and the darkness into two surfaces and just subtract the player from the glow surface, only if they're behind it?? But I'm not sure...

    OR, a bigger question... am I being too nitpicky with the realism? Does this whole issue really matter????
     
    RichHopefulComposer likes this.
  2. Kahrabaa

    Kahrabaa Member

    Joined:
    Sep 1, 2016
    Posts:
    126
    I would make the player sprite be drawn into its own small surface, then draw each light source on that player surface. Now you have more control over wich lights shine on the player or not.

    In the players surface, were you draw the light sources
    Code:
    var xx=x;
    var yy=y; //Send in the player coordinates to the light sources
    
    with ( objLightSources){
      //Draw the light if the player is above the sources center y
      if(yy<y){
      draw_self();
      }
    }
    Dont know if this is the most efficient way.
    Good luck!

    I would say, in general its worth trying and see if you like the result. Sometimes a small detail adds alot to the experience.
    But if it causes you to get stuck or makes the code inefficent, I would skip it and try to make other features in the game extraordinary.
    Players don't normally pay attention to EVERY detail as the developer does.
     
    Last edited: Sep 20, 2019
  3. RichHopefulComposer

    RichHopefulComposer Member

    Joined:
    Jun 20, 2016
    Posts:
    1,418
    For this game, players won't care at all, I don't think, just because the graphics in general aren't pro quality. I'd go all out in the gameplay, because tiny details like this aren't going to be appreciated unless the rest of your game is crazy good looking already.

    Players usually forgive indie devs for lackluster graphics if the gameplay is great, but poor gameplay is always unforgivable. I'd focus on great gameplay over these little graphical flourishes. I honestly don't think most players will notice. Good luck with the game!
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    I'd say a bigger immersion break is how the player's shadow faces the wrong way here... shadows always face AWAY from light sources. I'd say you could solve this easily: draw one shadow per light source, with an alpha and image_yscale based on distance to it, and with image_angle equal to the direction from lightsource to shadow-casting object. If alpha is 0 or smaller due to great distance, just don't draw the shadow at all.

    upload_2019-9-21_9-20-18.png
     
  5. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    Yeah, that's a complete separate mechanic I haven't touched on yet. Right now, that's the shadow the sun would cast. Eventually, I want a full-day shadow cycle (shadows moving from right to left as the sun moves across the sky, and increasing length depending on the time of day). Then at night, I would like to do what you've suggested, just didn't know how yet, so thanks!
     
    Last edited: Sep 21, 2019
  6. OblivionSkull21

    OblivionSkull21 Member

    Joined:
    Sep 26, 2017
    Posts:
    318
    Sorry for the bump a week later, but I actually started working on this problem. I've got the shadow to correctly match the angle that the player is facing the light source, but I'm not sure how to incorporate the scaling of the shadow because I am using draw_sprite_pos, which doesn't have a spot for image_yscale. Right now, the shadow is actually getting bigger as the player moves away from the light, which is the opposite of what I want.

    Here's what I have so far, with the working shadow angles and alpha, but not the scaling:
    Code:
        if instance_exists(obj_fire){
         
        with(obj_fire){
        if instance_exists(obj_player_parent) && (global.night || (other.day_timer == 6 && other.start_x < obj_player_parent.x - 50) || other.day_timer == 20 && other.end_x > obj_player_parent.x - 50){
     
        with(obj_player_parent){
        gpu_set_fog(true,c_black,0,1);
        var alpha = 1.2 - (distance_to_object(obj_fire)/.01);
        var sx = x - other.x;
        var sy = y - other.y;
    
        draw_sprite_pos(sprite_index,image_index,
    
        bbox_left + sx,
        bbox_bottom  + sy,
        bbox_right + sx,
        bbox_bottom + sy,
        bbox_right,
        bbox_bottom -4,
        bbox_left,
        bbox_bottom -4,
        alpha)
        gpu_set_fog(false,c_white,0,0); 
        draw_self();
        }
        }
        }
        }
    [​IMG]
     
    Last edited: Sep 29, 2019

Share This Page