Animated Sprite and LightOccluder2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Radinyn

Hello, is it possible to add LightOcclusion2D to an animated sprite? If it isn’t what other way of creating shadows do you suggest?

:bust_in_silhouette: Reply From: splite

Did you try it?

Yes, you can attach LightOcclusion2D to any node, not just Sprite/AnimatedSprite. Thats the great thing about node hierarchy :slight_smile:

However, LightOccluder2D is really a (2d) polygon, so it will not magically transform from your AnimatedSprite, you have to draw it / animate it (if you are making just top down game and simple “circle under feet” is enought, you dont have to animate anything)

You have many options how to do that. You can use frame_changed signal and turning on/off your occluders or you can use AnimationPlayer… There are many possible solutions and “how to do it”… Just depends…

My personal recommandations?

Heavily opinion based?

If you are trying to do something trivial, for example “open / close” door, i would just add two LightOccluder, draw two polygons and keep switching them in “func openDoor():” / “func closeDoor():” (you will be switching path finding down the line, so… Sooner or later :slight_smile: )

If you are trying to do something super nice and cool, for example main character? I would stay away from AnimatedSprite and use KinematicBody with Skeleton, bunch of Sprites and AnimationPlayer (and ends up with chracter like in Salt&Sanctuary.)

But as i say, it depends what is the effect you are after…

By the way: Experiment with Closed & Cull modeon your ShadowOccluder2D - you can do really nice effects with it (like, your light cast shadow only from one side - you can simulate things “lamp is behind / in the front of wall and still be 2 dimensional”