How to use several spritesheets to animate a KinematicBody2D with an AnimationPlayer and AnimationTree

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

Hi all,

I have made several sprite sheets for my projects, but realised that I can’t use several sprites at once since they overlap and are visible during each animation. How can I make it that only one animation plays, and the rest are hidden during the duration of the playing animation?

:bust_in_silhouette: Reply From: The_Black_Chess_King

The ideal usage of a spritesheet is for one sprite to display a frame of a single spritesheet frame, if you need different spritesheets from other imagefiles load them during runtime or preload them into a library. There are many ways of doing a animation system, you should explore what suits you the best, the properties you are interested to make a spritesheet work are hframes, vframes, frame and region.

Hframes and Vframes specify how many frames horizontally and vertically will be used from your spritesheet, animating the frame property will actually play the animation contained in that spritesheet, and if you want only a portion of that imagefile you can use region to basically use only a piece of that imagefile.

I will exemplify that with a simple spritesheet:

enter image description here

This spritesheet can play a running animation in 4 directions, each animation has 1 Vframes and 4 Hframes. You can switch direction by modifying the region position and size accordingly.

Or you can use all frames, then it will become 4 hframes and 4 vframes, and you would limit the frame animation to 0-3 for a animation of walking down, 3-7 for a animation of walking left, and so on.

You can do this in GDScript too, which will become automatically once you develop a system for that, or you can do manually with the animation editor, creating a animation per direction and so on, which is more work but easier to set-up.