Jump to content


Photo

Light Sources


  • Please log in to reply
2 replies to this topic

#1 the_hyrax_lord

the_hyrax_lord

    GMC Member

  • GMC Member
  • 495 posts

Posted 29 August 2011 - 12:20 PM

I'm using a counter, and draw_rectangle, to create a day/night cycle in my game. It works well, and looks (I think) pretty good in action. The problem is that I've now realised that I'm going to want light sources dotted about so that the player can still at night. However, the draw_rectangle is overlaid over everything, including any light sources, rendering them useless.

I have a feeling I could use blend modes to get the effect I want, but I've never really experimented with them before and my first attempts have failed miserably.

Is there a way to do this? I basically want a circle around the lightsource to remain 'lit' when the darker rectangle is drawn.
  • 0

#2 Amaterasu

Amaterasu

    GMC Member

  • New Member
  • 275 posts

Posted 29 August 2011 - 12:56 PM

Hey.

I've come across this problem before, but only ever came up with a very low-level solution, nothing fancy. Create a sprite that consists of a black background, with a transparent circle in the centre (so it looks like a black square with a hole drilled through the centre). We'll call this "hole_spr" Now, where you have a light source, have it draw hole_spr over the scene with the same alpha value as the "night" rectangle -- you can scale the image up to suit the intensity of the light.

Here's the complicated bit. You need to "stitch" the bits where hole_spr occurs together. Instead of using one big rectangle for the screen, you'll need to use little ones and patch them all over the screen without an overlap. With a single light source on the screen this is trivial. If there are multiple light sources, at the moment I can't think of a simple way of patching the pieces together without overlap.

Like you, I suspect there's a better solution (blend modes?). But I don't know what it is.

Hope this helps anyway! :laugh:
  • 0

#3 the_hyrax_lord

the_hyrax_lord

    GMC Member

  • GMC Member
  • 495 posts

Posted 30 August 2011 - 04:34 AM

Hey.

I've come across this problem before, but only ever came up with a very low-level solution, nothing fancy. Create a sprite that consists of a black background, with a transparent circle in the centre (so it looks like a black square with a hole drilled through the centre). We'll call this "hole_spr" Now, where you have a light source, have it draw hole_spr over the scene with the same alpha value as the "night" rectangle -- you can scale the image up to suit the intensity of the light.

Here's the complicated bit. You need to "stitch" the bits where hole_spr occurs together. Instead of using one big rectangle for the screen, you'll need to use little ones and patch them all over the screen without an overlap. With a single light source on the screen this is trivial. If there are multiple light sources, at the moment I can't think of a simple way of patching the pieces together without overlap.

Like you, I suspect there's a better solution (blend modes?). But I don't know what it is.

Hope this helps anyway! :laugh:

Hmm, the problem with that method is two-fold: 1, there will be multiple light-sources (no set number, more could appear at any time); 2, the light-sources will change position arbitrarily (at the whim of the player). 'Stitching together' would be nigh-on impossible, and certainly more trouble than it's worth, in this case.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users