0 votes

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.

in Engine by (247 points)

2 Answers

+4 votes

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?

by (810 points)

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)

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

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

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.

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

+1 vote

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.

by (247 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories