Text object

The Text object can display text using a font in your game. Note that there are not many fonts common to all computers - see this page for some common web fonts. Alternatively, the Text object supports Web Fonts using the Set web font action. See the tutorial on Using Web Fonts in the Text object for more information.

The Text object does not display anything if its bounding rectangle is too small to fit a single letter of text. If text objects appear to go invisible, try resizing them larger.

Text rendering

Different browsers render text in different ways, and Construct 2's layout view also renders text differently to other browsers. This means you should expect the appearance of the Text object to vary slightly across browsers.

You should test your game in a range of browsers to ensure text objects display how you intend for all users. For more information see Best practices.

Unsupported fonts in the editor

For technical reasons, some fonts are not supported by Construct 2's text renderer. This only affects the editor and does not necessarily mean the font will not work in the browser - be sure to test across different browsers. To guarantee that the font you are using is available to everyone, it is recommended to use Web Fonts instead.

Text properties

Text
The text for the object to initially be showing.

Initial visibility
Whether or not the object is shown (visible) or hidden (invisible) when the layout starts.

Font
The font the text object uses to display its text. Click the '...' button to the right of the font name to open a font picker dialog. Fonts chosen this way must be installed to the user's computer for it to display correctly. For this reason it is recommended to use Web Fonts instead if you are choosing an uncommon font.

Color
Choose the color of the text object's text.

Horizontal alignment
Choose whether the text displays left, center or right aligned within its bounding rectangle.

Vertical alignment
Choose whether the text displays top, center or bottom aligned within its bounding rectangle.

Hotspot
Choose the position of the hotspot (or origin) of the object relative to its unrotated bounding rectangle.

Wrapping
Choose how text wraps at the end of a line. Word will wrap entire words separated by spaces or hyphens. Character will wrap to the next line on any character, which might split words in half in Western languages but is more suitable for other languages like Chinese.

Line height
Amount to change the space between each line of text, in pixels. Use 0 for the default amount, -5 for 5 pixels shorter than default, 10 for 10 pixels taller than default, and so on.

Text conditions

For conditions common to other objects, see common conditions.

Compare text
Test whether the text object is currently displaying a certain string of text. The comparison can be either case sensitive ("TEXT" is different to "text") or case insensitive ("TEXT" is considered the same as "text"). To test if the text object is not showing some text, invert the condition.

Text actions

For actions common to other objects, see common actions.

Set font color
Set the color of the text. Use an expression in the form rgb(red, green, blue).

Set font face
Change the font used to display the text. The font must be installed to the user's computer to display correctly. For this reason it is recommended to use Web Fonts instead if you are choosing an uncommon font.

Set font size
Set the size of the text in points (pt).

Set web font
Set the font to a web font loaded online. For more information see the tutorial Using Web Fonts in the Text object.

Append text
Add some text to the end of the current text. For example, if the text object contains Hello and has World appended, the text object then contains HelloWorld.

Set text
Set the text the object is currently displaying. Use the & operator to combine text and numbers. For more information, see expressions.

Text expressions

For expressions common to other objects, see common expressions.

Text
Return a string containing the object's current text.

TextWidth
TextHeight
Return the size of the actual text content within the text object's rectangle. Note the Text object must be drawn before these have the correct values. If you set the text then immediately access these expressions, they won't yet have the correct value. Adding a 'Wait 0.1 seconds' action will usually solve this.

Tags: