Godot Version
4.3
Question
Well hello, I couldn’t find any information on how I can implement the mechanics of changing/partially changing a player’s sprite after taking damage in the game (2d, top-down). In theory, it should work so that after a player takes damage, their character’s sprite would change. (As an example, if it’s a human sprite, his hand would disappear immediately after the first damage, and then the second after the second damage, and only then after the third damage would the game over). I think I have described it in detail. I’m new to Godot, so hey, thanks in advance.
If you’re using different sprites for different statuses, you can just change the sprite’s texture property in the function where it gets damaged. Sprite2D — Godot Engine (stable) documentation in English
I would probably just keep the different textures all preloaded and tracked in an array or dictionary.
Another way to go, especially if you want to just remove, or swap, or overlay, different parts of the character interchangeably without creating a new sprite for each possible combination, would be to have your character be a scene made of multiple parts. Similar to how a weapon is often a different sprite, arms and legs, etc, can each be their own sprite. Here you can literally have all possible sprites in the scene and just show/hide them with the visible property to get the effect you want. (Maybe if it gets very complex you’ll want to add to / remove from the scene for performance, so that not every sprite is in the tree at the same time, but I doubt that would make much of a difference.)
1 Like