Help creating multiple light sources

AdventureIslands

  • *
  • Posts: 728
I'm trying to so something small and experimental but for that, I need to figure out how to make multiple light sources, I checked out how light was done in the Maze Game example in Forge, but the problem with that solution is that you can't have multiple light sources on the stage because the images to create darkness cover each other up.

I'm trying to do something like in this example image, is there any simple way to create this? Could it be done somehow with stage high and wide black drawing or a region and then use different shaped actors to "cut holes" to the black to see through it?

How complicated would this be when I need many lights of different shapes and some of them move and can be turned on and off? I also need to make so that the character you control will die if she falls out of light and touch the darkness.

« Last Edit: April 19, 2012, 06:03:41 am by AdventureIslands »

coleislazy

  • *
  • Posts: 2607
For iOS, I have no clue. For Flash, you could probably manipulate the BitmapData object of the black mask by "cutting holes" with transparent pixels.

AdventureIslands

  • *
  • Posts: 728
For iOS, I have no clue. For Flash, you could probably manipulate the BitmapData object of the black mask by "cutting holes" with transparent pixels.

I could do black images with holes made with transparent pixels, but that doesn't really work when you have multiple of those images on the stages, the black parts of the images keep covering each others transparent parts.

coleislazy

  • *
  • Posts: 2607
I meant you could take the graphic image of the actor and actually turn some of its pixels transparent using various Flash functions. Something like this, if _Mask is the mask actor and _Light is a transparent circle actor type:

First, save the original image of the actor once so we can revert to it.
Code: [Select]
var originalImage:BitmapData = _Mask.currSprite.pixels.clone();
Then, reset the image each frame:
Code: [Select]
_Mask.currSprite.pixels = originalImage.clone();
Then, draw each light source:
Code: [Select]
var rect:Rectangle = new Rectangle(0,0,_circleWidth,_circleHeight);
_Mask.currSprite.pixels.copyPixels(getImageForActorType(_Light),rect,new Point(_x,_y));

Now, since each light source image will have to be square, they will have to include a black area around the transparent circle. With this method, light sources cannot overlap that area or that black may bleed onto previous transparent sections.

Note that this would only work in Flash and is completely off the top of my head with no testing.

AdventureIslands

  • *
  • Posts: 728
It will be a flash game. I will give this a try when I get home from work soon.

Do I need to use these codes as actor behaviors or how do they work? Do all three come for single lightsource actor?

The game will have different kinds of lightsources besides circles, but I guess those are done by drawing the black areas around the transparent graphic. Also will the lightsource be able to move? the hero of the game carries a lantern most of the time and when she doesn't have it she can push some objects that have lightsources on them.

coleislazy

  • *
  • Posts: 2607
It doesn't matter if its an actor behavior or scene, as long as it knows where to draw all the light sources.

The lightsources will move, since you're drawing them each frame. You don't have to actually create each source as an actor, either, since you're just going to be drawing the image of the actor type at each light source. Its a bit complex, but it should work. I'll try to put it together myself when I have some time, but you may not want to wait for me.