Jump to content


Photo

Easy Lighting V7.0.2 | Last Updated: 06/07/11


  • Please log in to reply
465 replies to this topic

#41 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 02 December 2008 - 12:39 AM

Ok, I think I found the source of the some of the problems, and it is really odd and so far I can only find 1 work around! Ok, the object calling the light_init() event must be placed in the room FIRST! It would give an error if you didn't, I fixed it so it doesn't give an error, but now it just doesn't draw the lights unless THAT OBJECT says to create them. Changing depths and such didn't do anything at all, so it must be something else which I can't put my finger on...

Anyway, as long as you place the object calling light_init() in the room first (depth doesn't matter) then it should work fine. Also, I found out that what I did with the light_set_step() etc, it messed everything up so I added a new function light_update() in it's place. So basically instead of having light_set_step() and light_colorset_step() just put light_update!();

I hope this works for you guys until I find out why the lighting is acting up if not placed first.

P.S. Grats on your 100'th most mate. :whistle:

EDIT: Oh yeah, don't place the light_update() under the draw event, that WILL make the lights be drawn out of place including other random images.

Edited by Scyler_27, 02 December 2008 - 12:49 AM.

  • 0

#42 bocochoco

bocochoco

    GMC Member

  • New Member
  • 140 posts

Posted 02 December 2008 - 12:59 AM

Works fine. No errors that I could find. I'm not too sure why you would have to enable colorlights that way, but it works.
  • 0

#43 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 02 December 2008 - 01:07 AM

Well, I thought it would be nice to be able to turn colored lights on and off if you want, and plus, this way avoids unnecessary loops. So it should speed things up slightly when you have a large number of lights. :whistle:

Anyway, glad to hear that it works again.

Edited by Scyler_27, 02 December 2008 - 01:07 AM.

  • 0

#44 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 02 December 2008 - 03:20 AM

My time to test :whistle:

Wow I like what you've added :GM122:

Hehe works better for me =]

Few odd glitches like random lights, and in my game a gfx mix up until i create a new light =P
Im getting all kinds of coordinate problems this is so odd

Edited by Krisando, 02 December 2008 - 07:17 AM.

  • 0

#45 bocochoco

bocochoco

    GMC Member

  • New Member
  • 140 posts

Posted 02 December 2008 - 07:13 AM

Feature request: flickering lights (think candles). Perhaps you could add multicolor lights? Like a light that fades from color1 to color2.

Kris: I have no idea what is going wrong for you, the lights aren't off center for me. I am using over 100 lights currently and every one of them is exactly where it should be.

Edited by bocochoco, 02 December 2008 - 07:14 AM.

  • 0

#46 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 02 December 2008 - 07:32 AM

[IMG Edited]
Fine in example though =/

For flickering I make the side get bigegr with random(); looks quite nice.

Im wondering if the change of room size or anything changed the lighting,
I think they ahve correct positions bit it is being placed incorrectly

Try this, it gives an error on game end. and a no lighting bug which may be causing incorrect coordinates
Download Error

Edited by Krisando, 02 December 2008 - 09:19 PM.

  • 0

#47 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 02 December 2008 - 06:01 PM

Wow... I think most of the problems came from your programing instead of the lighting engine. ;)

1. It started up and switched rooms before the other object could even initialize the lighting engine, this caused the error, AND the problem with drawing no lights.
2. You were calling light_update() in multiple objects per step which caused serious lag and problems with drawing the lights. You only need it called once per step, you don't need to update the lights more than that. ^^
3. The view you put was really weird, (Though I assume that you did that on purpose) which made things look strange, but no biggie.
4. The fact you placed light_init() in a different room adjusted the lighting settings to that room. This is ok if the rooms are the same sizes, but if not that causes problems.

So once I fixed these few things, everything worked smoothly again. Here are some things to remember:
1. Make sure that light_init() is always placed FIRST, before any other object creating lights or changing rooms etc. (It is best just to place it first in the room)
2. Never call light_update() more than once per step. Placing it in other objects in the same room can cause drawing problems and lag.
3. A good rule is to place light_init() at the beginning of each room you want lights, and light_end() at the end of each room. Though this isn't NECESSARY depending on room sizes, and such it could cause problems and lag because it sets the settings of the light for the room it is initialized on and it resets variables to avoid drawing (or attempting to draw) lights created from the previous level.

Hope that helps!

EDIT: For the flickering, instead of putting lt_normal you can put lt_flash. If you don't like that effect then under light_set_light() you can use a random() for the size/alpha or use light_set_on() and use choose(0,1,1) for on or off. I might update some effects later on, but right now I am just trying to make the lighting system work steadily. :)

EDIT2: @Krisando, I know it is a hassle having to put it at the beginning of each room. Especially if you have the room designed already. If that is the case, try this, open the room editor and find the object with the lowest id number. (If you don't know, the id of the object your mouse is over is displayed in the bottom bar of the room.) hold ctrl+right mouse a menu should appear. At the bottom of the menu there is "Creation Code" click that and inside place the light_init() and it should work. That is one way to avoid having to re-do the entire level.

Edited by Scyler_27, 02 December 2008 - 06:09 PM.

  • 0

#48 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 02 December 2008 - 08:24 PM

Sorry for bothering you so much, the cause for all my problems was the room been to large oddly enough.
10100 in size xD
It works great now =]

This has got to be my favourite extension essential, Im happy with the results =]
Posted Image

Edited by Krisando, 02 December 2008 - 09:19 PM.

  • 0

#49 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 02 December 2008 - 09:50 PM

Ooh I see. Well I am glad it is working well for you now! :)

Your game looks really nice by the way, do you have a demo of it out yet? I would love to try it out!

P.S. I am still open for suggestions, so feel free to say if you want anything added! I am possibly planning on adding gradient surround light, or even textured. But that is iffy.

@bocochoco, about the multi-colored lights, I don't know a way to make it gradient (though I CAN make it possible to color certain portians of light, but that could cause lag) You could always make 2 lights of different colors and merge them together slightly. Since colors mix (if you put a red and blue light, the outcome will be purple) it should work quite nicely.
  • 0

#50 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 02 December 2008 - 09:59 PM

(Game had been released but will release soon ;P got alot of work to do though =] online part of game is complete though)
Suggestion.. well something which may be handy depending on how easy it'd be for you to implement.
Possibly a code light_object_visible(); checks to see if an object has been hidden by darkness/non visable due to lighting.
It'd probably be very hard for you so iuno up to you =P

Also maybe been able to add a fade to
light_set_on(my_light,ef_fade,false);
or something like that =].

Edited by Krisando, 02 December 2008 - 10:21 PM.

  • 0

#51 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 02 December 2008 - 11:21 PM

Hm... good ideas... I like it. :) With the light_object_visible() I can see how that would be an extremely useful function, I will have to look into how hard it would be to make. I think I might also make some others for check if a light is on and such. Thanks. ;)

As for your second, what do you mean "fade"? Like, I light fades out or something? That would be easy to make yourself actually, but as said I will see if I can add it. (Since light effects can easily be made manualy, they are of a lowest priority for me)
  • 0

#52 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 03 December 2008 - 12:42 AM

When there is a large amount of light say and the visible is set to false it just dissapears.
Adding a fade would save alot of coding on each single object ;P
  • 0

#53 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 03 December 2008 - 07:18 PM

Ok, I am in need of an opinion. I have found and tested a way to see if a point is located in the light or not. The problem is is that is would be considered a "slow" function, and there is no way for me to speed it up. In other words, you can't place it in the step, draw, or any fast event like that. Would you still want it? It works great under key-presses and such, you just cant use it too much without huge lag.

I tested on a computer with 1ghz and 512mb ram by placing it in the draw event. It brought the fps down to about 5. Tested also on a 2.4ghz with 2gb ram at 30fps. So... you can place it in step even if you are aiming at higher-end computers with no probs, but for the average computer it lags like crazy.

Give me your oppinion and depending on that, I will add it or remove it.
  • 0

#54 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 03 December 2008 - 08:10 PM

My adverage comp has to have a Quad core with 4gb ram min xD.

Umm, well it could run abit faster if you placed it into a reoccuring alarm say every 5 steps.
But that is very bad framerate, may have to skip =/

Edited by Krisando, 03 December 2008 - 08:15 PM.

  • 0

#55 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 03 December 2008 - 08:16 PM

Dang, nice computer.. :(

Yeah, that is what I was thinking... tis a bummer, but I can't find any other method because of the custom images. (If I didn't have to support custom images it would be a piece of cake, but I am not going to do that)

Edited by Scyler_27, 03 December 2008 - 08:17 PM.

  • 0

#56 Krisando

Krisando

    GMC Member

  • New Member
  • 1351 posts

Posted 04 December 2008 - 01:15 AM

Maybe you could check each part of a sprite "if possible" to see if it is the colour black e.g. if the whole sprite is then return visible is false. Could be faster if possible.
  • 0

#57 frog

frog

    GMC Member

  • New Member
  • 228 posts

Posted 04 December 2008 - 10:00 AM

how can you set the depth?

i mean.. i want to use the lights.. but i dont want the black rectangle on my screen.. or just a little bit...

i got some alarm lights in my game but its outside and its in the afternoon... how do i make the lights go flash without the black rectangle?
so everything within the light becomes whiter...
and for other room with the rectangle?
  • 0

#58 motormann

motormann

    GMC Member

  • GMC Member
  • 23 posts

Posted 04 December 2008 - 04:15 PM

I am making a 2d platformer which requires a day to night cycle, and multiple light sources which light up dark areas. I have a working method that I like, but it's just too slow, dragging my fps below 60, which the game needs to maintain. My method was to use a layer of square objects covering the view, each of these objects changes its alpha value based on proximity to the light source object. The effect is a lighted area around the light source while everything else is in darkness. This method has a bit of a "grid" look to it since the darkness objects are squares, but I didn't find this to be much of a drawback. I think the speed loss comes from all the distance_to_object() calculations that are being made by each of the squares (the grid I'm using is 34x19 which is 646 objects). I tried some methods for cutting down the number of objects that needed to make calculations, but still could not maintain the 60fps, and that was with just 1 light source object.

Anyway, since my method doesn't seem viable, I searched the forums and came across your extension package. I haven't had a chance to try it out yet, but it looks like exactly what I need, and if it does work as I think, I'll be very appreciative.

One thing that I'm wondering though is an aspect of the lighting that I was wanting, but even my own method could not produce. I'm wondering now if you have any ideas on how you could add this feature to your package. What I wanted to do was have the "darkness" ignore certain background layers. The reason I want this is that my game is a 2d side scrolling type of game with outdoor environments as well as indoor, and if you think about it, the sky layer shouldn't be affected by the "darkness". If it is, the problem becomes that your sky will light up around your light source (unless its 100% black), when it should remain the same. What would be ideal is to have certain backgrounds ignore the darkness completely. I would prefer to handle the light/dark effect of the sky background layer in some other method. Well, if you think this could be done, I'd love to see it. If not, I may be able to work around it. One thought I had was to create a mask in the shape of the sky, perhaps it would even work to create a light in the shape of this "sky mask", though it would have to have a sharply defined edge, rather than a soft one (I can't tell yet if that's supported but I think it is).

Anyway, I'll let you know how this works for me, looks good from what I can tell so far. Thanks.
  • 0

#59 Scyler_27

Scyler_27

    -Insane Kid-

  • GMC Member
  • 2746 posts
  • Version:GM:Studio

Posted 04 December 2008 - 07:13 PM

@Krisando, I can't think of a way to do that because the objects are drawn on the screen while the lights are drawn on a layer. So if anything, it would make it slower.

@frog, Your post was sort of hard to understand... But with the function light_main_set() you can change the blackness to any color you want, and also make it more or less intense. (if you put the alpha to 0 then it disables the lights altogether) As for the flashing or whatnot, I don't quite get what you mean. :P
As for setting depth, you cannot do that, I did it to avoid problems. If you want to draw a HUD or something place it right after the function light_draw(). Another way is using the "if (view_current==0)" so it only draws lights in view 0, then you can draw stuff in the other views without lights.

@motormann, Well, there are actually 2 ways to draw a background above the lighting source currently. (1) In the room editor, under the background tab, select the background you want and check the box saying "Foreground Image." And it should draw it in front of everything. (2) simply draw a background directly after calling light_draw() and it will be drawn in front.

Though both you and frog have given me an idea, I think next update I will be adding a way to remove chunks of background light, that way you could have it dark inside a cave while light outside or something. Would that solve your problems?

Edited by Scyler_27, 04 December 2008 - 08:18 PM.

  • 0

#60 motormann

motormann

    GMC Member

  • GMC Member
  • 23 posts

Posted 04 December 2008 - 10:06 PM

Thanks for the info, but the background can't be drawn on top of the "darkness" layer otherwise it wouldn't be a background, meaning characters and other objects would be covered over by it when they're supposed to be drawn in front of it (I had already thought of that). What is needed is for either entire background layers to be somehow ignored completely by the "darkness" layer, which I'm not sure is possible, though maybe there is some way to do it with advanced blending options that I haven't explored yet. Or else a mask is needed that is the exact shape of the area to be ignored. I think this may be already supported by your extension package, simply need to create a custom light shape that is entirely white (rather than shades of gray for the blending of a normal light) in the shape of the sky. That should in effect keep the darkness from being drawn on top of that part of the background. Another use for it would be if you're inside a dark room, and you want a window from outside to be brightly lit. You would want to mask the window so it's not going to get darkened.

Anyway, I'll know more once I get a chance to use this. Knowing it's possible though I may decide to try and create my own code to do what I need. I had the idea for this method as my "backup" plan when my other method proved too slow. But I had missed some key functionality in GM that was making me think this wouldn't be possible. The ability to properly blend a sprite with levels of gray to indicate various levels of transparency was what I was missing. I thought the image_alpha setting was all we had. After browsing around the forums today I see that there are a number of blending functions that I had missed.

And maybe I can clarify what I think frog was after. He wants the light to actually add brightness/color to the environment rather than what it currently does which is add darkness to everywhere there isn't light. I think this might be pretty easy using a sprite and the blending functions (though I need to read up on them to know what all can be done). I think it would be a good feature to add this to your extension package, since it's definitely related.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users