A Sprite-Sheet Animation Script for the Sprite node

This article also published in : https://www.reddit.com/r/godot/comments/atixe9/a_spritesheet_animation_script_for_the_sprite_node/

I’ve created a SimpleAnimation.gd to attach to a Sprite node to animate sprite sheet. The source code is in : https://github.com/nthana/SimpleAnimation

The problem:

Many 2D animation resources are in the form of sprite sheet– an image containing smaller images inside.Godot has the Sprite node that partially support sprite sheet. With the “vframes” and “hframes” properties, a sprite sheet with equi-size images can be segmented properly. However, to actually animate it, an AnimationPlayer or some coding is required to increase the “frame” property.

Another problem is that the above solution will be even harder when the sequence of the sprite sheet’s inside images are not in the sequence of left to right and up to down.

The solution:

  1. The Sprite node is used normally by setting the “vframes”, “hframes”, and “frame” properties.
  2. A custom script “SimpleAnimation.gd” is created to attach with the Sprite node. The script will receive a frame sequence string such as “0-9, 13, 15, 0-4”. The parser can receive hyphens and commas.
  3. An FPS (frame per second) or a duration (total animated time) can be specified.
  4. Playing and loop boolean values can be specified.

Anyone interested can try the sample project on the above link.

This is the sample screen shot of the properties in the inspector.

The properties of the SimpleAnimation.gd

Write and test on the Godot Engine version 3.0.6 stable version.

Update : For Animation Preview, after attaching the script for the first time, if you want to see the animation preview, you should save and close the scene and then reopen it.

This is the problem of Godot tool scripts. Godot tool scripts will not be operated when first attached. (source : https://github.com/godotengine/godot/issues/16974 )

Leave a comment