When to use GUI vs objects?

Hello everyone,

New to Defold. I’m trying to make a button you click/touch and I’m unsure whether I should make it as a game object or gui. Can anyone give me any tips for when I should use one or the other and why? What does gui do differently? What’s the difference between regular scripts and gui scripts? Thanks.

For a button to click, I would recommend using a GUI, as you can use gui.pick_node() to easily check if a node is pressed.

For elements that don’t need to be clicked, other differences of GUI elements are that they will render on top of all your sprites (with the default render script), do not automatically move with the camera, render in order of the tree structure (or layer) instead of z position, and have more options for how they stretch and position when resizing the screen. A health bar, score box, main menu, or pop-up for example would make sense to be implemented in a GUI. So usually anything that is floating on top of the game world as information for the user, instead of being a part of the actual world.

Another difference is that game objects use factories to spawn more instances, and for GUI elements you have to clone another node (or node tree).

5 Likes