AnimatedSprite: setting pivot points for frames

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

I have a bunch of PNG images with the animation frames for an animated sprite.
Each image has different width and height.
How can I set where the pivot / anchor point is for each of these individual frames?
(It might be in different places for each frame.)

Inb4: I know how to set the pivot point for the entire sprite object.
What I’m asking about is setting the pivots of the indiviual frames.
Because now I see that they are always centered.
Or if I turn off centering, they are always pivoted to the top-left corner.
(Or whatever the “offset” parameter is set up to.)

:bust_in_silhouette: Reply From: avencherus

As far as I can tell there is no such feature built into the node. If you want custom offsets per frame, you can do this pretty easily in script. Create an array of offsets that correspond to the frame number, and change it when the frame change is signaled.

This example is a two frame AnimatedSprite.

extends AnimatedSprite

func _ready():
	set_ofs()
	connect("frame_changed", self, "set_ofs")
	
var offsets = [Vector2(1000, 1000), Vector2(200, 200)]
	
func set_ofs():
	set_offset(offsets[get_frame()])
:bust_in_silhouette: Reply From: DavidPeterWorks

I had the same issue. I created a node that contains all of the sprites.
I fine-tuned my sprites’s offsets one-by-one.
The container node change visibility of frame (sprite node).
It can work with some sprites. I would not do that with more than 10 sprites.

For a huge amount of sprites.
I would export my sprite with a fixed border/space around the frame so all centered frame would look like fine.