Layered Sprite is a Godot tool to easily divide a sprite in layers. It can be used for customizable characters.
For a better understanding of the tool, please consider taking a look at the demo.
To use this in your scenes, add a LayeredSprite
node. Then, as childs of that node, add Sprite
or AnimatedSprite
nodes. Give names to those nodes, as they will later be the layer names. You can also give those nodes their default texture
or SpriteFrames
.
add_animated_sprite_layer(layer_name: String, frames: SpriteFrames = null) -> void
: Creates a newAnimatedSprite
layer.add_sprite_layer(layer_name: String, texture: Texture = null) -> void
: Creates a newSprite
layer.get_layer_count() -> int
: Returns the number of layers, that is, the number ofSprite
andAnimatedSprite
childs.get_layer_position(layer_name: String) -> int
: Returns the position (or depth) of the layer. Layers with lower position draw first, behind layers with higher position.get_layers() -> Dictionary
: Returns a Dictionary of every layer, where the Keys are the layer names and the Values a reference to the layer node.has_layer(layer_name: String) -> bool
: Returns whether or not such layer exists.is_animated_sprite_layer(layer_name: String) -> bool
: Returns whether or not such layer is anAnimatedSprite
layer.is_sprite_layer(layer_name: String) -> bool
: Returns whether or not such layer is aSprite
layer.move_layer(layer_name: String, to_position: int) -> void
: Moves a layer to the given position. It uses Godot'smove_child
in the background.remove_layer(layer_name: String) -> void
: Removes a layer.set_animation(animation: String) -> void
: Sets an animation to allAnimatedSprite
layers.set_layer_animation(layer_name: String, animation: String) -> void
: Sets an animation to a specificAnimatedSprite
layer.set_layer_asset(layer_name: String, asset) -> void
: Sets the asset of a layer, that is, itstexture
orSpriteFrames
.set_layer_visible(layer_name: String, value: bool) -> void
: Sets thevisible
property of a layer. Please, don't directly modify thevisible
parameter of layers.
To manage different layer assets you can use a LayeredSpriteCloset
node. This node can handle groups of layers and lists of assets for each group. To organize this, you'll have to create different LayerGroup
resources. Each group has a name and one or more members. Each member is a Dictionary entry, where the Key is the layer name and the value is an array of the different assets (texture
or SpriteFrames
).
layered_sprite
: TheLayeredSprite
node to change.groups
: Array ofLayerGroups
.current_group
: The currently selected group.current_group_index
: The index of the currently selected group.
previous_group() -> void
: Selects the previous group.previous_asset() -> void
: Selects the previous asset of the current group·next_group() -> void
: Selects the next group.next_asset() -> void
: Selects the next asset of the current group·set_group_index(value: int) -> void
: Selects a group given it's index.set_asset_index(value: int) -> void
: Selects an asset of the current group given it's index.