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.
Note if
WebGL is enabled in
project properties, due to technical limitations all Text objects appear on top of everything else in the game. For example, Sprites cannot be displayed on top of Text objects when WebGL is on, because the text is rendered to an overlay above the game. It is recommended to design your game so it is not necessary for other objects to appear on top of text objects, since turning off WebGL can reduce performance.
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
TextThe text for the object to initially be showing.
Initial visibilityWhether or not the object is shown (visible) or hidden (invisible) when the layout starts.
FontThe 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.
ColorChoose the color of the text object's text.
Horizontal alignmentChoose whether the text displays
left,
center or
right aligned within its bounding rectangle.
HotspotChoose whether the hotspot (or origin) of the object is at the
top-left of the bounding rectangle (the default), or
centered. This is usually only important if the text object is being rotated.
WrappingChoose 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.
Text conditions
For conditions common to other objects, see
common conditions.
Compare textTest 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 colorSet the color of the text. Use an expression in the form
rgb(red, green, blue).
Set font faceChange 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 sizeSet the size of the text in points (pt).
Set web fontSet the font to a web font loaded online. For more information see the tutorial
Using Web Fonts in the Text object.
Append textAdd 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 textSet 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.
TextReturn a string containing the object's current text.
TextWidthTextHeightReturn the size of the actual text content within the text object's rectangle.