1

Alright, so I've been pondering over this for quite awhile now; looking through documentation, examples, previously made games, ect...

Basically (for those familiar with Box2d Lights), I'm trying to create bodies on top of my walls (so there's shadow casting, and so the light will stop instead of going through the wall). I have no problem creating, positioning, and updating the bodies, but the only real problem which I can't figure out is a way to make the filled body to be invisible or transparent so it shows my tileset (or wall) while still giving a shadow effect if light was casted onto it.

Perhaps I'm thinking or going about this the wrong way. Feel free to correct me.

Here's an image to display an example of a body I created on top of my wall. The shadows are handled properly, but I cannot see my wall.

Any help is greatly appreciated. Thanks.

Handles shadow properly, but I can't see my wall.

Sebastian
  • 5,721
  • 3
  • 43
  • 69
Gosre
  • 61
  • 9
  • So you want to see the wall itself, but behind it should be shadow right? As i have never used box2D i don't know much about it, but to have the shadow after the wall (so that your wall is still lighted) you may have to push the body at the end of your wall, depending of the direction you are looking at. But as much as i can remember bodys are also used for the collision detection right? So that could be a problem. As i said i don't know much about box2D so this is only an idea. – Robert P Mar 12 '14 at 16:58
  • Yeah, I'm currently not using bodies for collision detection (although I might switch over to that). A workaround is to put the black body behind the wall, which gives a shadow effect of the wall quite nicely, but not to the best precision as if the body were on top of the wall completely. Still, I appreciate your comment! – Gosre Mar 12 '14 at 21:26
  • With that black box behing the wall you would have problems if you are looking to the wall in a "strange" angle like 33°. You would have to rotate the box and change its shape a bit. That would be a bit hard, wouldn't it? – Robert P Mar 13 '14 at 06:58

1 Answers1

0

You have two options here:

  • Set the shadow-dropping bodies behind the wall and use only transparent bodies for collision detection using BitMasks
  • Or render your wall sprites on top of box2dLights
Sebastian
  • 5,721
  • 3
  • 43
  • 69