This system does use shaders, or did you mean some completely different approach?I'm surprised how well this runs. Better than the shader based lights, I've never had a good experience with shaders in GMS.
Hey Oliver,Hello...
I feel kinda stupid for asking this but i need to know..
I really love this asset and stuff... and i have been trying to get the lighting to follow my character in my game. Guess you can imagine what im talking about.
I been trying for hours know without luck. I feel like a dumb **** for not know how to code it. hope i could get a little help here?
Hello Nedenir,I have a problem with shader, that in the android compilation works without any problem on two devices, which have completely different resolutions but for some reason shader flickers and loses objects on the third device Asus Zenfone Go.
Shows alternately either tilesets or draws objects never together, sometimes it goes normally but flickers again after a while.
Hey nigmatech,Excellent script. Are you planning on adapting it to GMS 2?
Also a question - is there a way to get object status (is it in light or not)?
var _light_inside = rectangle_in_rectangle(_light_left, _light_top, _light_right, _light_bottom, argument0, argument1, argument0 + global._light_width, argument1 + global._light_height) > 0
This is actually how bright the world is, with the shadow overlay gone. The best way to control how dark the shadow overlay is with the color value set with light_set_ambient_color. If you want to keep it dark, set this to a dark color.Also another question - when I use your day-night cycle (which works excellent, thank you very much) during the day I get overly bright colors of everything, is there any way to gradually lower alpha together with the raising color?
Hi SmokinLettuce,Absolutely love this extension! I don't have a gigantic amount of the GML, but I've been able to do dynamic shadows and updates and all the good stuff fairly easily. I am curious, and lost, on how to create lighting only on the surface of my world. I'm making a game similar to Terraria and want the surface of the world to be lit up with everything below it being blacked out. Could you help me in anyway in doing this? I can email you or dropbox the project file to you and you can take a closer look at it if you'd like, thank you!
Hey username,Hello, Buff! Agree with others, its a wonderful lighting/shadowing system. And it looks fantastic! Well... In your demo at least.
Now to the point. I am trying to make a flashlight for the player and am trying to figure out how lights work (I'm a newbie) and managed to figure out by now how to attach light source to the player, but... When I try to make light follow the mouse, it just doesn't work how I want it to.
Game starts, light is being created (pointing from the player (source of light) to the mouse' onscreen position) and then freezes in this position.
I want to allow player to use flashlight freely in any direction with "mouse_x" and "mouse_y" so that "x1" and "y1" are the player's position (light source) and "x2" and "y2" are position of the mouse pointer (to where light is pointing). I hope you understand what I mean. And yes, I looked through your example project. And no, still can't understand how it works. "Light Angle" value doesn't really help me much.
Thanks in advance!
EDIT: OK, it seems like the light rotation parameters are kept somewhere in the "light_draw" script. Apparently in the "draw lights" section, because changing script "light_set_rotation" doesn't give me much. Well, actually it gives nothing. LoL. I tried to replace "= argument0" to "= point_direction(x,y,mouse_x,mouse_y). Damn. I guess the original creator of the script will help me (and others as well) to better read the code. Any help?
light_set_rotation(point_direction(x, y, mouse_x, mouse_y))
Hah! I think my mind got blurred back then. I did everything exactly like you said BUT I was doing it in the "begin step" lol. That's why nothing worked for me. Thank you for your help, man! It's a really helpful advice!Hey username,
You almost have the right idea but you're not using GM scripts correctly. The script, light_set_rotation, has to be called in an object event in order to work. In the step event of your light object put:
This will update the rotation of the light every step.Code:light_set_rotation(point_direction(x, y, mouse_x, mouse_y)
Be sure to check out the example and the documentation on the first post which describes how to use the scripts.
Hello,I've been playing around with this system for a while now, and as I said above, it's amazing. However, I have one question. Why are the primary colours red, green, and blue? And not red, yellow, and blue? Wouldn't it make more sense to have yellow instead of green? As you can easily get any colour from these three? yellow + blue = green.
Edit: Okej, after looking around in other places r, g, b seems like some kind of standard. No need for an answer.
Yes, I am currently using this script with GMS 2. I have implemented it quite a long time ago, but I seem to recall that it did not take any significant tinkering. Try to import it in its entirety in GMS 2 as a new project and go from thereI'm trying to get this asset to work in GMS2 but it is constantly complaining that global._lights and global._light_casters is not defined. Although I've checked and can see that they are set up in the main_objects instance - which I added to the test_room.
After importing the demo project into GMS2 I reorganised the Layers so that the controller (main_objects) was on a layer on its own. The Lights were on a layer called 'Lights' and likewise moved all the casters to their own layer.
Is it possible to use this asset in GMS2?
light_init(room_width, room_height, 256, c_black, 0.5, room_speed);
light_create(sp_light_point, 1, c_white, 1, 0, false);
light_create_caster();
Hello Seryal,I'm happy that I found this. I was able to create the shadow map, create the light around my player object and turn my wall blocks into casters; but the wall blocks do not cast.
I had my own lighting system that I removed because I thought it was interfering but it still does not create shadows for the wall blocks.
I've looked at the example project and my coding for the block caster is identical except for the physics, which I doubt make a difference since it's just a stationary block.
I'm initializing withI'm creating light around my player withCode:light_init(room_width, room_height, 256, c_black, 0.5, room_speed);
And in my block object's creation code I haveCode:light_create(sp_light_point, 1, c_white, 1, 0, false);
And I'm using the destroy for the lights and casters as well.Code:light_create_caster();
Any ideas what I might be doing wrong or need to change/add?
Hey,Hey, I'm working on a project using Fastlights, and so far it's very good. I am having an issue, though, and was wondering if you knew of any way to fix it. Whenever the camera or view moves, there's a noticeable delay before the lighting catches up to the new view angle. I'm just sorta looking to remove that effect. If you know any way of patching it out, I'd really like to know. I've been trying to do it on my own for a bit now, but due to general inexperience on my end, I haven't really gotten anywhere.
This would be challenging, but I have seen games use surfaces for collisions. In theory you could you could save the shadow surface as a sprite and collide with the black parts because the rest is transparent. I don't know how to do this off the top of my head, but there are lots of games that have "destroyable terrain" that is drawn by a surface.That's some fine work you did there Buff! And even free! You are insane
I wanted to ask if there is a possible way to check shadows for collision/ make them solid, because I can't find a way to make a drawn thing to a collision mask/ point perfect collision..
Would be cool if you had an idea and thanks in advance!
Witzler
Yes I was, I think it was a depth issue between certain objects. I got someone else to help me and now it's working, thank you!Hello Seryal,
Are you calling light_draw() in the draw event of your main object?
Unfortunately that didn't really do anything. I already have both the room speed and the iterations set to 120. Just to clarify a bit, it's not a constant stuttering, just whenever the camera moves. It's also slightly noticeable in the example project.Hey,
What is your update iterations in light_init? You might be seeing that if your iterations are too small. Try setting it to room_speed.
Same here for when I got it working. It's not a huge problem for me but if there's a fix for that that'd be great to know about!Unfortunately that didn't really do anything. I already have both the room speed and the iterations set to 120. Just to clarify a bit, it's not a constant stuttering, just whenever the camera moves. It's also slightly noticeable in the example project.
Hmm, I've only seen the stuttering you describe when running with a low iteration rate.Unfortunately that didn't really do anything. I already have both the room speed and the iterations set to 120. Just to clarify a bit, it's not a constant stuttering, just whenever the camera moves. It's also slightly noticeable in the example project.
Yes, I'm curious. What changes did you have to make to stop the lights from shaking when the camera moves?Sorry for the late response! I was rooting around, and it turns out it was something on my end actually. Couple of things were conflicting. I can provide a bit more detailed reasoning @Seryal is still having issues, but it was really nothing interesting.
I had a similar problem. My solution was to create a separate object to just be the light and then always draw it at the offset location of the lamp. This isn't too bad if you create the light in the lamp's create event:Is there a way to adjust the x/y offsets of light_create without adjusting the offset of the sprite? I have a streetlight object as the light source but it appears from the base (since that's where the offset is).
It has to be created from the streetlight object otherwise placing/removing the streetlight in game would be buggy.
xoffset = 0
yoffset = 16
light = instance_create(x + xoffset, y + yoffset, Light)
with light {
x = other.x + other.xoffset
y = other.y + other.yoffset
}
with light {
instance_destroy()
}
Yeah. What instance_create does is creates an "instance" of an object, which is essentially a copy of an object , that can be acted upon independently from other instances. Using instance_create is equivalent to placing an object in the room editor, this is just how you do it with code.Would this work with several instances of the streetlight object without interfering with eachother's lighting? Is that what the light variable does?
And thanks for the help by the way. Really appreciate it!
I would like to know this as well.This wonderful asset assumes that the entire room or view is in a state of perpetual light or darkness.
Is there a way to render the darkness only to a select area?
For example: day time outdoors in the hills; there stands a house upon which we enter, to find it dark inside. (the darkness must stop at the walls, not continuing outside into the day light)
Also, as it is, (circumstances depending) lights still shine through walls.
Hmm, the shadow casters are based on a set of points, not the content of the sprite. You'd have to create a caster from a set of points and then change those points with the animation. There's no way to do that with the system right now, but it's not impossible. Alternatively if the animation is just a rotation or a translation, the caster points will move with the object based on the x, y location and image_angle. You could change your animation to be procedural instead of baked into a animated pixels or you could create a dummy caster object that mimics your existing animation.Hey, I'm back again. This time I'd like to know if there's a way to create a caster that takes the sprites transparency into consideration. Right now, I have a door object with a sprite that has animation to open it, and I'd really like for just the non-transparent part to block light as the door opens. I'm not quite sure if that makes any sense, but I'd really appreciate it if anyone knew a way to do something like that.
Would also love this for gms2Excellent script. Are you planning on adapting it to GMS 2?
Also a question - is there a way to get object status (is it in light or not)?
Hey Nephalen,Hello Buff.
I'm sorry for reviving such an old thread but I really love your light system but I am having trouble understanding a specific part of the code.
In the script called "Light_draw" you say that I can change X,Y to change the location to draw the shadowmap. I have tried switching around the code some but I'm not getting any real results.
What I am after is to have (for example) only the bottom half of the screen using the light and shadow system while the top part works normally. I want to make it like a cave but I am having no luck. If you have the time I'd love to know what exactly to change to achieve this effect.
light_init(500, 500, 1024, color, 0.35, -1)
light_draw(512, 512, true, true, blur)
Hello Killuado,i didn't understand the point caster so, have some way to make an real-time shadow of a animated player?
// Create two lists of lists for storing points.
pointsx = ds_list_create();
pointsy = ds_list_create();
// Create each frame as a list of points.
// Frame zero...
var pointsx_frame = ds_list_create();
var pointsy_frame = ds_list_create();
ds_list_add(pointsx_frame, 0);
ds_list_add(pointsy_frame, 0);
ds_list_add(pointsx_frame, 128);
ds_list_add(pointsy_frame, 0);
ds_list_add(pointsx_frame, 128);
ds_list_add(pointsy_frame, 128);
ds_list_add(pointsx_frame, 0);
ds_list_add(pointsy_frame, 128);
// Add the frame to the list.
ds_list_add(pointsx, pointsx_frame);
ds_list_add(pointsy, pointsy_frame);
// Now create the caster from the first frame.
var first_frame_x = ds_list_find_value(pointsx, 0);
var first_frame_y = ds_list_find_value(pointsy, 0);
for (var i = 0; i < ds_list_size(first_frame_x); i++)
{
_light_points_x[i] = ds_list_find_value(first_frame_x, i);
_light_points_y[i] = ds_list_find_value(first_frame_y, i);
}
ds_list_add(global._light_casters, id);
// The image_index and the point frame index are the same.
// Get the current point frame from the list.
var current_frame_x = ds_list_find_value(pointsx, image_index);
var current_frame_y = ds_list_find_value(pointsy, image_index);
// Clear out the existing points since there may be more than this frame has.
_light_points_x = 0;
_light_points_y = 0;
// Set the caster points to the new points list.
for (var i = 0; i < ds_list_size(current_frame_x); i++)
{
_light_points_x[i] = ds_list_find_value(current_frame_x, i);
_light_points_y[i] = ds_list_find_value(current_frame_y, i);
}