+1 vote

I have been using the Godot engine for a short time and now I want to create a small 2D strategy game.
In the game there are cities, in my project these are a scene with a Node2D as root. To click on a city I have added a button as child node. My problem is that I just can't figure out how to nail a button to the position of the Node2D. The button is always too big and does not behave correctly.

in Engine by (41 points)

Can you provide screenshots?

1 Answer

+1 vote
Best answer

How to nail a button to the position of the Node2D

If the button is a direct child of the Node2D, it already is! The position-property is always relative to the parent-node, it it's set to (0, 0) the top-left corner will be the position of the parent.

The button is always too big

You can set the rect_size-property to precisely the value you want, let's say (200, 20). If you want the button to be centered on the position of it's parent-node, set the rect_position accordingly, i.e. in this case to (-100, 10).

and does not behave correctly

Which behavior do you expect? And what's happening instead?

by (10,423 points)
selected by

Thanks for the nice answer, I have found a solution.

a scene where a sprite has a size of 1

I'm assuming you're talking about the Sprite's scale here, not it's size?

So why is the sprite not 16 times smaller but almost as big as the tile.

Why should it? If you have a Sprite and assign to it an Image of size 16x16 pixels, it will be 16x16 pixels wide. That doesn't change if you add it as a child of another scene.

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.