Jump to content


Photo

Lighting Effects!


  • Please log in to reply
21 replies to this topic

#1 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 30 July 2008 - 05:28 AM

Here are 2 lighting effect scripts I made.

Posted Image

I think the picture says enough.

But in case you want more info:

Contains 2 scripts: circle lighting effects and ellipse lighting effects.
Both can be used to create a cast light or a light at a single place.
Circular light does not require 3D mode.
Elliptical light does require 3D mode.
In the picture above, the car headlights and taillights are elliptical lights, all other lights are circular.
Adjustable quality v. performance.

Download the Scripts! (.gmk file for GM7)

Edited by ninja_x, 30 July 2008 - 03:01 PM.

  • 0

#2 posva

posva

    GMC Member

  • New Member
  • 610 posts
  • Version:GM8

Posted 21 August 2008 - 01:01 PM

these scripts are veary great, i don't know what noone has already posted
  • 0

#3 LuisYX

LuisYX

    GMC Member

  • New Member
  • 1 posts

Posted 10 September 2008 - 12:32 AM

Thank, for this scirpts, give you credits in my game (for this scirpts). :)
  • 0

#4 dhuyd

dhuyd

    GMC Member

  • GMC Member
  • 257 posts

Posted 10 September 2008 - 01:30 AM

the only problem I found with the script is that when you shine the light on itself it creates a full circle around itself no matter which way it's pointed, but besides that awesome scripts.
  • 0

#5 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 16 September 2008 - 12:09 PM

The circle script is for raised lamps or spotlights, I'm sure it was meant to do just that. Nice scripts :)
  • 0

#6 Caniac

Caniac

    The #1 Caniac

  • New Member
  • 2622 posts

Posted 17 September 2008 - 01:51 PM

yes, thease are very cool, I might just use them some day...
  • 0

#7 PickleMan

PickleMan

    Programmer

  • New Member
  • 995 posts
  • Version:Unknown

Posted 19 September 2008 - 12:29 AM

Wow!
  • 0

#8 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 19 October 2008 - 08:22 PM

the only problem I found with the script is that when you shine the light on itself it creates a full circle around itself no matter which way it's pointed, but besides that awesome scripts.


If you want a more realistic spotlight, maybe you could try the ellipse light effect and make the length of the ellipse increase as the light is shined farther from the origin of the spotlight? I haven't looked at this script for a while so I don't know how hard it would be, but it's definitely possible. The circle light is a little faster and simpler to use and doesn't require 3D mode, but if you want the more realistic spotlight effect that becomes more elliptical the farther it gets from the spotlight origin you would have to use the ellipse light effect.
  • 0

#9 2d_games

2d_games

    GMC Member

  • GMC Member
  • 1495 posts
  • Version:GM8

Posted 24 October 2008 - 12:30 AM

Excellent scripts. I could really use the draw_light_circle script.

A question though, is there a special way to use it because I made an object, no sprite, 0 depth, using your light script and changed spotbrightness to one and it made the entire room black and no light was present. How exactly do I use it for my game?
  • 0

#10 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 24 October 2008 - 02:19 AM

Excellent scripts. I could really use the draw_light_circle script.

A question though, is there a special way to use it because I made an object, no sprite, 0 depth, using your light script and changed spotbrightness to one and it made the entire room black and no light was present. How exactly do I use it for my game?



The variable I made called spotbrightness is just a small number that would get smaller as the cursor goes farther from the spotlight.
Though I passed this value into the script (so that the spotlight's "spot" would get dimmer the farther it was from the spotlight's origin), there usually is no need for this kind of variable.

In order to use the script, go into the object's drawing event and enter
draw_light_circle(x1,y1,r1,c1,a1,x2,y2,r2,c2,a2,quantity)

This function draws a light by creating a bunch of overlapping semi-transparent circles from position (x1,y1) to (x2,y2)
The number of circles from (x1,y1) to (x2,y2) will be equal to the last argument passed ("quantity"). Increasing quantity can make the light look nicer but takes more power to draw. Also be aware of how changing quantity will change the apparent transparency if you happen to be drawing the circles such that they overlap.
The circles will vary in size from having radius r1 at (x1,y1) to having radius r2 at (x2,y2)
The circles will vary in color from having color c1 at (x1,y1) to having color c2 at (x2,y2)
The circles will vary in transparency from having alpha a1 at (x1,y1) to having alpha a2 at (x2,y2)

Be aware that the transparency of the center of the light will depend also on the number of circles that overlap at a particular point.
The transparency of the light at a point is equal to
(a + a^2 + a^3 + ... + a^n)
where a is the alpha value for each circle and n is the number of overlapping circles at the point of interest


For example, the game I'm working on now has a simple circular light that is coded by
draw_light_circle(x,y,3,c_white,0.1,x,y,9+random(7),c_red,0.3,5);

This draws 5 circles at position (x,y) (note that in this case x1=x2=x and y1=y2=y, so all the circles are drawn at (x,y)). The first circle has radius 3, is colored white, and has a transparency of 0.1. the last circle has a radius of 9+random(7), is colored red, and has a transparency of 0.3. The 3 circles between the first and last ones have values in between these. 0.1 and 0.3 may seem like very low transparencies, but keep in mind that in this case the circles are being drawn over each other, so it should appear reasonably visible. Try experimenting with this example, since it's more basic.
  • 0

#11 2d_games

2d_games

    GMC Member

  • GMC Member
  • 1495 posts
  • Version:GM8

Posted 24 October 2008 - 06:03 PM

Thanks it works perfect now. Looks great, I'll be using this and you will be credited.
  • 0

#12 Jandagames

Jandagames

    GMC Member

  • New Member
  • 119 posts

Posted 16 November 2008 - 04:57 PM

Wow. Thats really great! I've been looking for a good 2d lighting engine for a while and now I've found it. My game's called Hazard and I think this will be great to add to the atmosphere. Currently, I'm planning on selling it as a commercial game, do you mind? I'm going to give you credit.

Also, I'm terrible with scripting so can you tell me how I could modify it so that the mouse doesn't aim the spotlight. So I can have fixed lights like say, going down a hallway or something.

Thanks so much!

Edited by Jandagames, 16 November 2008 - 05:02 PM.

  • 0

#13 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 16 November 2008 - 06:51 PM

Wow. Thats really great! I've been looking for a good 2d lighting engine for a while and now I've found it. My game's called Hazard and I think this will be great to add to the atmosphere. Currently, I'm planning on selling it as a commercial game, do you mind? I'm going to give you credit.

Also, I'm terrible with scripting so can you tell me how I could modify it so that the mouse doesn't aim the spotlight. So I can have fixed lights like say, going down a hallway or something.

Thanks so much!



I don't mind at all if you use this in a commercial game. Look at my posted reply to gamemakernooby on this thread for a basic explanation how the script takes its parameters (It's 3 posts ago.) To have fixed lights you would just use constant values for x1, y1, x2, and y2.
  • 0

#14 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 18 November 2008 - 12:09 AM

While I still like my scripts for glowing lights, I thought I'd post here a great lighting engine I found on YoYo Games: http://www.yoyogames...ames/show/59972. It works much better for spotlights, and casts shadows.
  • 0

#15 Jandagames

Jandagames

    GMC Member

  • New Member
  • 119 posts

Posted 18 November 2008 - 12:14 AM

Thanks! It works perfectly!
  • 0

#16 erick1294

erick1294

    GMC Member

  • New Member
  • 7 posts

Posted 05 July 2010 - 06:02 AM

thanks for the awesome script i'll be giving you credit if i release mi game, im going to use it as flashlight for mi characters.
  • 0

#17 Bitzer42

Bitzer42

    GMC Member

  • New Member
  • 36 posts

Posted 11 October 2010 - 07:29 AM

I am a complete noob to this game and i want to know how to make everything around the spotlight black so all you can see is whats under the light. also i would like to know how to stop it going through walls.
  • 0

#18 ninja_x

ninja_x

    GMC Member

  • GMC Member
  • 276 posts

Posted 11 October 2010 - 11:21 PM

I am a complete noob to this game and i want to know how to make everything around the spotlight black so all you can see is whats under the light. also i would like to know how to stop it going through walls.


Keeping it from going through walls would be extremely difficult, if not impossible, with this method. I don't know how you'd do that off the top of my head, but earlier in this thread I posted a link to an effect somebody made on the YoYoGames website that does what your looking. Check that out. May not be the easiest way to start learning Game Maker, but hey, it's worth a look at least.

Edited by ninja_x, 11 October 2010 - 11:27 PM.

  • 0

#19 Bitzer42

Bitzer42

    GMC Member

  • New Member
  • 36 posts

Posted 12 October 2010 - 09:12 AM

THANKS A HEAP FOR THAT LINK! i will give you credits in my game! :lol:
  • 0

#20 crazybob

crazybob

    GMC Member

  • New Member
  • 10 posts

Posted 05 March 2011 - 04:10 PM

Hello, First off id like to say that your spotlight engine here is amazing. Im having a strange problem with it though...(sorry if this issue is due to my noobyness) When I have the spotlights in the room, my healthbar (drawn by rectangle,) disappears... any idea why this may occur?
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users