Animate sprite with frames of varying size

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zylann
:warning: Old Version Published before Godot 3 was released.

How can I change the frames of a sprite with sub-rectanges of different sizes?
VFrames and HFrames expect the spritesheet to have the same frame sizes, but my character goes beyond its 32x32 rect for some of its actions (It’s just a frame change, not an actual “animation”).

Currently my character rotates around itself to look at the mouse, but when I change its frame the center of rotation is wrong. Ideally I would set this center in a spritesheet like with the Unity3D sprite editor, but in Godot I don’t know where to do that?

What about resizing the whole thing so your bigger frame fits inside the range?

grol | 2016-03-20 14:15

You could’ve posted it as answer :wink:

Kermer | 2016-03-20 17:12

I don’t do that because it would create a lot of unused blank space in the texture, just because a few frames have elements going beyond 32px in size. Also, not only the size, but the center might change.

Zylann | 2016-03-20 23:50

You ever figure out a good way of doing this?

mofro | 2017-07-08 15:05

I’m not working on the project requiring this currently, but my question still remains unanswered :confused:

Zylann | 2017-07-08 18:25

:bust_in_silhouette: Reply From: mofro

I figured out a way to do this that isn’t too tedius, you can use the auto slice tool on the spritesheet which gives you a bunch of region rects for each individual sprite the system detects.

Then you can create an animation with the rect region as the key and change the frames by clicking on the different auto detected regions.

Where is this auto slice tool?
I thought of using AtlasTextures (which basically are texture sub-rectangles as a resource), but once set on sprites they don’t retain their offset and you have to manually add it to AnimationPlayer, so can’t even use AnimatedSprite on this

Zylann | 2017-07-17 20:53

when you click on the sprite, on the bottom next to the animation tab a new option appears called “Texture Region”

mofro | 2017-07-18 00:09

Does anyone know how to do it for individual frames, in AnimatedSprite?

shield | 2017-12-14 18:59

You can create AtlasTextures, those have a rect you can define by using slice tool. Then, you can load them in the AnimatedSprite animations. It’s tedious though, but you need to do it anyways… if you use atlases.
If your textures are individual already, you don’t need the slice tool, right?

Zylann | 2017-12-14 21:37

:bust_in_silhouette: Reply From: phreakhead

The way I did it was I created an AnimationPlayer. Then in the AnimationPlayer, each different animation has a keyframe for the AnimatedSprite’s:

  • animation: change to the animation you want.
  • position: change so the center of that animation matches up to the center of the other animations in the AnimationSprite.

That way, you switch animations via the player, and it will choose the correct animation on the Sprite and reposition it so it looks like it matches up with the other frames.