Hi everyone, as you can see from my image I have a simple light source. It's effective in drawing my shadow based on the placement of the light object. However, given my code I can't figure out how to properly fade the image_alpha out as I walk further from the light source. Here's the code I use:
var sx = oLighting.x - x;
var sy = oLighting.y - y;
//var light_xy = sx + sy;
//Draw Shadow
gpu_set_fog(true,c_black,0,1);
draw_sprite_pos(sprite_index,image_index,
x-(sprite_width/2)-sx,
y-sy,
x+(sprite_width/2)-sx,
y-sy,
x+(sprite_width/2),
y,
x-(sprite_width/2),
y,
image_alpha);
I've come close with some equations that update the alpha based on the x/y coordinates of the light source, but I'm too noobish in GML to figure this one out. Also, I've looked into the "clamp" function, this was on YoYo's website:
image_alpha = clamp(image_alpha - 0.01, 0, 1);
The above code will slowly reduce the image_alpha until it reaches 0.
Surely there must be a way to do this with clamp?
EDIT: Now I've got it working, HOWEVER I'm trying to make it so everywhere I place this "oLighting" object, I'd like it to cast a separate "shadow" and I can't seem to accomplish this.
var sx = oLighting.x - x;
var sy = oLighting.y - y;
//var light_xy = sx + sy;
//Draw Shadow
gpu_set_fog(true,c_black,0,1);
draw_sprite_pos(sprite_index,image_index,
x-(sprite_width/2)-sx,
y-sy,
x+(sprite_width/2)-sx,
y-sy,
x+(sprite_width/2),
y,
x-(sprite_width/2),
y,
image_alpha);
I've come close with some equations that update the alpha based on the x/y coordinates of the light source, but I'm too noobish in GML to figure this one out. Also, I've looked into the "clamp" function, this was on YoYo's website:
image_alpha = clamp(image_alpha - 0.01, 0, 1);
The above code will slowly reduce the image_alpha until it reaches 0.
Surely there must be a way to do this with clamp?
EDIT: Now I've got it working, HOWEVER I'm trying to make it so everywhere I place this "oLighting" object, I'd like it to cast a separate "shadow" and I can't seem to accomplish this.
Attachments
-
68.4 KB Views: 13
Last edited: