Text objects are versatile, allowing for either single or multiple lines of text. By default, they start aligned left. When multiple lines are involved, each new line aligns to the left margin as well.
The approach to alignment varies based on the number of text lines...
Single-Line Text Alignment
For a single line, the alignment involves its position relative to a reference point, which could be the scene or another object (like a button).
Tip: For static text, position it once using conditions such as At the beginning of the scene or Trigger once. For dynamic text, like a changing score, reposition it within an event that updates regularly, possibly every frame.
Centering Text in the Scene
To center text within the scene, apply the Center X position action with SceneWindowWidth() / 2
. This aligns the text object's center to the scene's width midpoint.
For right alignment, use the X position action with SceneWindowWidth() - OBJECT.Width()
. This places the text so its right edge aligns with the scene's right edge.
Text Alignment Relative to Objects
To align text to other objects, like centering on a button, use the Center position action. Set X and Y to OBJECT.CenterX()
and OBJECT.CenterY()
to center the text on the button.
Aligning Text in Multi-Line Objects
Positioning multi-line text objects works similarly, affecting the object as a whole. To align the lines of text inside the object differently, use the Alignment action. Choose left
, center
, or right
to align the text within the object accordingly.
Note:The Alignment action doesn't apply to single-line text objects.