MichaelSinsbeck / platformer

A ninja platformer written in LÖVE
7 stars 0 forks source link

Shadows and walls... drawing order and covering #62

Closed Germanunkol closed 10 years ago

Germanunkol commented 10 years ago

We've discussed this in multiple threads now, I figured we should make one for this issue.

You said you have it covered by drawing the walls and objects after the shadows. That works with the brightness of the walls, but then the player can no longer walk from light into the shadows and I think that's one of the coolest effects.

Is there a simple solution? I don't know the details of how you draw images, but couldn't each object just store a "layer" value (either 1 or 2) and then the draw function is called twice, once for layer 1 and once for layer 2, with the layer passed as an argument?

michalove commented 10 years ago

The problem is this: The player must be behind the shadow, the shadow must be behind the walls and the walls must be behind the player. If we break one of these three rules (which we have to), we get undesired effects.

I don't see a simple solution.

Maybe it is possible to make an extra shader for the objects. This shader would draw an image, but modify it by data stored in the canvas (is it possible to hand extra textures to a shader?). That means that the shadows/lights are not drawn from a canvas directly, but applied through a shader.

For the non-shader version one could use stencils, to draw parts of the objects with a different color: 1) Draw objects normally. 2) Apply stencil (light-triangles are available) 3) Draw object again, but lighter.

I could also change the images of the ninja. But then he would not "hang" on the walls as he does now. I find this really cute, so this solution is not really an option.