Book of Defold
  • Book of Defold
  • Defold A-Z
    • What is Defold?
    • Why Defold?
    • Defold History
    • Editor Tour
    • File Formats
    • game.project
    • Defold Tips
      • Anchored GUIs
      • GUIs for Window Size
      • Pixel Art Assets
    • Lua Tips
      • Lua Tables
      • About math.random()
      • Randomly 1 or -1
      • Lua Modules
      • Global Scope
    • Running Projects
    • Bundling Projects
    • Releasing Projects
    • Command Line Tools
    • Debugging Projects
  • Dive into Defold
    • Make Games Now!
    • Avoider - Action
    • Asteroids - Action
    • Level Editor - Tool
  • Dev Tips
    • Learn Programming
    • Game Business
    • Useful Software
  • Quick Projects
    • Lasers
Powered by GitBook
On this page
  1. Defold A-Z
  2. Defold Tips

Anchored GUIs

Do you want groups of GUI elements to be anchored to a corner of your game's screen? You'll need to do something which may not be obvious to you at first to make the GUI elements look right.

PreviousDefold TipsNextGUIs for Window Size

Last updated 6 years ago

When you first attempt to anchor GUI elements to an area to the screen you may do it simply by setting each GUI node to have an X and Y anchor and a pivot. But if you scale the screen you may notice some issues with spacing.

As can be seen in the "Scaled Window" image above, the spacing between the nodes is inconsistent with the amount of scaling.

The fix for this is easy!

For each area of the screen you wish to anchor nodes to, you must create a parent anchor GUI node.

Create a box node. Set its size mode to manual, and set its size to 0,0,0. This will make it invisible.

Then set the anchor box node to have the anchor type you want. In this case X anchor left, Y anchor top.

Now you can move the box node to the area of the screen you wish to anchor other GUIs to.

Then parent the other elements to this anchor GUI. You'll need to update their positions as they will now be relative to the anchor GUI.

Now when you scale the window the GUI elements will look to be spaced more consistently.

You should generally follow this example when anchoring elements to areas of the screen as even in less extreme scaling situations the spacing can look off without this.

Using anchor GUIs can be useful for general GUI organization as well.

Unscaled Window
Scaled Window