I'm trying to simulate shadows for a 2D top-down RPG (in Python), but I can't think of the best way to do this

So far I've tried making copies of the original game entities and turning all opaque pixels black (which is a bit slow), then rotating them around the bottom of the original image... but i couldn't quite get that approach to work.

So how can I simulate this effect?

  • \$\begingroup\$ There's a lot of potential duplicates here, I picked this one because you didn't provide a whole lot of detail about the specifics of what kind of shadows you want (how you want them to act, or look like). The linked technique can be expanded to provide a wide variety of dynamic shadow effects, but it is possible you are looking for something that looks different -- in which case you should edit this question to specify that and we can remove the duplication link. \$\endgroup\$ – user1430 Aug 14 '14 at 15:30

It´s all depending on how dynamic you want your game to be. If your sun positions is going to change constantly. then you need a more advanced approach.

But, in my opinion, your approach of having the original image and rotating it is good enough. You can do a basic "dynamic" shadow and you don't have to do a lot of overhead data for just shadows.

Then of course you somehow need to tag specific objects to cast and not to cast shadows.

There is also other solutions like a ray traced approach or a static shadow map. The ray traced approach is quite straight forward, you trace on the screen and when your ray find a "blocking" pixel, you break the ray and don't paint anymore "light". this will be the most awesome dynamic solution.

The static shadow map, is basically the same but you ray trace offline and save it into a texture. this wont be dynamic at all since you have to rebake every time the sun position changes.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.