Centering the objects for screen resize

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

I was fiddling with making a 2d gui the other day, and I stumbled on this, I figured it’s pretty simple, but I can’t understand it. Basically when the window is resized, the layout remains the same, wich means that people with smaller screens could potentially not even see the boutons. Scince an image is worth a thousand words, here are two!

and whene the screen size changes the image is no longer centered:

After a little while, I managed to get it to work by putting everything in the anchor section to center, but also discovered other combinations seem to work. I realize this is probably really simple, but I don’t understand how it works. Why is the setting on the controle node, and not on the botoun, does this mean it will work for any gui object? Also, there are anchors on the actuall botoun node, what do these do? And how do the anchors work (wich anchor does what)? Anybody mind to explain how the anchor system works?

:bust_in_silhouette: Reply From: CowThing

All nodes that inherit from Control will have anchor and margin settings. This includes the Button nodes (Basically anything with a green icon in Godot). The anchors and margins are based on the direct parent of the Control. So if the root node of your scene is a Control but it is small and anchored to the top left corner, then all children nodes will follow that as well. If the parent of the Control isn’t a Control then the anchors will attach based on the Viewport. (If you’re making a HUD, using a CanvasLayer for the root of the scene is a good option). When you have a Control node selected there is a button at the top of the 2D editor that is called “Anchor”, this allows you to easily change the anchor of a control.

You can find more information here: http://docs.godotengine.org/en/latest/tutorials/2d/size_and_anchors.html

Still not sure I get it, but I have understood a little more, so thanks!

Sojan | 2016-08-29 23:27