Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

C# XNA: Drawing 2D Shadows

$
0
0
I'm working on a 2D game engine (Side Scrolling / Platform) with a lighting system that takes an array of points and sizes and draws gradient circles for the "lights" but when drawing this over my game you can see through the walls, so I'm trying to add shadows to the game.
Only the ground/environment will cast shadows (Maybe this will change, probably not), this is a tile based side scrolling game like terraria.

What I'm thinking is to calculate the triangles based on the angle of the line from the center of the light to the corners of each tile within the lights range and then using the DrawUserPrimitives to draw the triangles to shade in the shadows.

My concerns are:
1) Can I use DrawUserPrimitives to draw to a RenderTarget2D.
2) Is there a simpler / less intensive way to do this.

Feel free to ask for any source-code. I Attached an image to illustrate the lighting system and where the shadows are coming from. The legth of the shadow doesn't matter as they will go off-screen.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>