How to set the anchor point of a node?

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

is it possible to set the anchor point of a node in Godot?
I only see the centered option and offset may modify the origin of the node.
However, when the texture size of each Frame in AnimationSprite is different, it’s hard to align each frame, for example, to the bottom.
If we have some option like set the anchor point to (0, 0) will align by left top, and (0.5, 1) will align by center bottom, it will be much easier.

:bust_in_silhouette: Reply From: Robster

Do you mean the pivot point? That can be done with pressing V whilst having the mouse over a node in the editor. I hope that helps but maybe I misunderstood?

it seems the pivot point also use the absolute value, not the percentage.
What I ask for is, for example, when set a sprite to position(0,0), whatever texture it use, the bottom of the texture is at position(0, 0)

alexzheng | 2017-04-24 05:21

it seems set the pivot point just the same as change the offset and position value.

alexzheng | 2017-04-24 05:24

ahhh I see. I am not sure to be honest. You could possibly try something like:

mySprite.set_pos(Vector2(newLocationX - MySprite.get_texture().get_width(), newLocationY - mySprite.get_texture().get_height()))

I haven’t tried that code, it’s just theoretical, but you could use texture width and height to offset the placement?

EDIT: just updated code a little

Robster | 2017-04-24 05:27

I also got the idea that adjust the position of the node, but it’s not straightforward, and it becomes much more complicated for some situations like AnimatedSprite.

alexzheng | 2017-04-24 08:26

Best advice i can give you is to normalize the sprite sizes, or use Sprite+AnimationPlayer instead of AnimatedSprite node

Mariano Javier Sulig | 2017-04-24 17:58

:bust_in_silhouette: Reply From: alexzheng

Thanks for all the suggestions here.
It seems it’s not supported currently.
I wish the maintainers of the engine could add this feature.
Most other engines has this API.