The Label component exists to allow you to attach text content to any game object. While Defold’s GUI support is advanced, using it to glue information to in game objects can be tricky since GUIs do not live in the game world.
A label component renders a piece of text on screen, in game space. By default it is sorted and drawn with all sprite and tile graphics. The component has a set of properties that governs how the text is rendered.
To create a Label component, either:
The new label component has a set of special properties exposed that you can change in the editor or in runtime.
Note that the default material has shadow rendering disabled for performance reasons.
By setting the pivot you can change the alignment mode for the text.
South, the text is center-aligned.
Westmodes, the text is left-aligned.
Eastmodes, the text is right-aligned.
You can manipulate labels in runtime by getting and setting the label text as well as the various other properties.
numberfor uniform scaling or a
vector3for individual scaling along each axis.
function init(self) -- Set the text of the "my_label" component in the same game object -- as this script. label.set_text("#my_label", "New text") end
function init(self) -- Set the color of the "my_label" component in the same game object -- as this script to grey... local grey = vmath.vector4(0.5, 0.5, 0.5, 1.0) go.set("#my_label", "color", grey) -- ...and remove the outline, by setting its alpha to 0... go.set("#my_label", "outline.w", 0) -- ...and scale it x2 along x axis. local scale_x = go.get("#my_label", "scale.x") go.set("#my_label", "scale.x", scale_x * 2) end