I Wanna Be The Forums!

Please login or register.

Login with username, password and session length
Advanced search  

News:

Gaiden 1.2 patch released. Click here to download!

Author Topic: How to make a simple "lighting" system?  (Read 3010 times)

Benxamix2

  • Sr. Member
  • ****
  • Posts: 387
  • INACTIVE
    • View Profile
How to make a simple "lighting" system?
« on: November 10, 2011, 03:02:08 pm »

What I want, is to make something like this:



But without using a big sprite with a hole that represents the light of the player.
I'm not asking for whole code, just some idea or functions I could use for it.
YES, in Game Maker 8.

Thanks beforehand.
Logged

[redacted]

  • Sr. Member
  • ****
  • Posts: 440
    • View Profile
Re: How to make a simple "lighting" system?
« Reply #1 on: November 10, 2011, 03:10:55 pm »

Make a object, call it, Darkness

Put this in Create:

Code: (Create) [Select]
if instance_exists(player){
surf=surface_create(room_width,room_height)
surface_set_target(dark)
draw_set_color(c_white)
draw_rectangle(0,0,room_width,room_height,0)
draw_sprite(sprSight,0,player.x,player.y) //Copy and edit this line if you want it to apply to more than the player
surface_reset_target()
}

For Step put this:

Code: (Step) [Select]
if instance_exists(player){
surface_set_target(dark)
draw_set_color(c_white)
draw_rectangle(0,0,room_width,room_height,0)
draw_sprite(sprSight,0,player.x,player.y) //Copy and edit this line again.
surface_reset_target()
}

For Draw put this:

Code: (Draw) [Select]
draw_set_blend_mode(bm_subtract)
draw_surface(dark,0,0)
draw_set_blend_mode(bm_normal)

Make a gradient circle like this:
: Gradient Circle • show

Call it sprSight.

This should work. If you have any problems with the code, tell me.
Logged

Benxamix2

  • Sr. Member
  • ****
  • Posts: 387
  • INACTIVE
    • View Profile
Re: How to make a simple "lighting" system?
« Reply #2 on: November 10, 2011, 03:25:28 pm »

Ty, I'll try it.

EDIT: What is "dark"? Darkness obj?
« Last Edit: November 10, 2011, 03:30:08 pm by Benxamix2 »
Logged

tijit

  • IWBTG Champion
  • Hero Member
  • *****
  • Posts: 591
  • yatta
    • View Profile
    • tijital-games.com
Re: How to make a simple "lighting" system?
« Reply #3 on: November 10, 2011, 03:30:44 pm »

Make sure you call surface_free(dark) when you are finished with it, otherwise it sits around in memory.

The way you're doing it you can only actually have one light source at a time. There a whole bunch of little tweaks you'll have to do if you want to draw multiple light sources. Just copying the line he posted won't be sufficient. You'd have to make an alpha map for your circle, or draw the circle onto the surface using a fancy blend mode, unfortunately drawing subtractive blended stuff onto a surface doesn't work on some graphics cards so you'll have to do some funny stuff with addition blending + inverting the colours on the surface.

(ninja'd) "dark" is a surface. He called it "surf" when he instantiated it, for some reason
Logged

I had insomnia before it was cool

Benxamix2

  • Sr. Member
  • ****
  • Posts: 387
  • INACTIVE
    • View Profile
Re: How to make a simple "lighting" system?
« Reply #4 on: November 10, 2011, 03:36:40 pm »

Yeah, but now it works. Ty for info tijit, and ty for code Nyan Catz0r
Logged