Hi everyone, I have an object I call "oLighting" it's an accumulation of code that I've picked up on tutorials and forums, and it creates a light source that affects all my objects under my parent object. It works great, however I'm having troubles with the "with" function, as I already have all the code under a "with".
Here's my code:
// if `distance` is below `min_distance` then the instance is fully visible
with(oParent)
{
//variables for shadows
var min_distance = 2;
var max_distance = 150;
var distance = point_distance(oLamp.x, oLamp.y, x, y);
var shadow_alpha = 0.8 - clamp((distance - min_distance) / (max_distance - min_distance), 0, 0.8);
var sx = oLamp.x - x;
var sy = oLamp.y - y;
//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 / 3,
y,
x - sprite_width / 2,
y,
shadow_alpha + global.shadow_flicker);
//draw_sprite_ext(sprite_index,image_index,x-5,y-5,image_xscale,image_yscale,0,c_black,0.5);
//This sets fog to disable,white is default.
gpu_set_fog(false,c_white,0,0);
}
So essentially this code gives everything a shadow, it works really nice, but it only works with one light. As of right now I made the origin of the lightsource come from an object called "oLamp" but again, given that I already have a with, I cant seem to make this affect all "oLamp" objects/instances. I've read the manual on "withs" and cant seem to figure out the whole "other.object" stuff, sorry I still have alot to learn, appreciate any help.
Here's my code:
// if `distance` is below `min_distance` then the instance is fully visible
with(oParent)
{
//variables for shadows
var min_distance = 2;
var max_distance = 150;
var distance = point_distance(oLamp.x, oLamp.y, x, y);
var shadow_alpha = 0.8 - clamp((distance - min_distance) / (max_distance - min_distance), 0, 0.8);
var sx = oLamp.x - x;
var sy = oLamp.y - y;
//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 / 3,
y,
x - sprite_width / 2,
y,
shadow_alpha + global.shadow_flicker);
//draw_sprite_ext(sprite_index,image_index,x-5,y-5,image_xscale,image_yscale,0,c_black,0.5);
//This sets fog to disable,white is default.
gpu_set_fog(false,c_white,0,0);
}
So essentially this code gives everything a shadow, it works really nice, but it only works with one light. As of right now I made the origin of the lightsource come from an object called "oLamp" but again, given that I already have a with, I cant seem to make this affect all "oLamp" objects/instances. I've read the manual on "withs" and cant seem to figure out the whole "other.object" stuff, sorry I still have alot to learn, appreciate any help.