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

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

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

Kahrabaa

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

OR, a bigger question... am I being too nitpicky with the realism? Does this whole issue really matter????
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:
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!
 

Yal

šŸ§ *penguin noises*
GMC Elder
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
 
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.

View attachment 26858
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:
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.

View attachment 26858
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();
    }
    }
    }
    }
 
Last edited:
Top