Phaser home
Phaser AE
Open source
Phaser 4
Download
Learn
Editor
Tools
Docs
Examples
News
Log in
Examples
/
Game Objects
/
Text
Phaser 4.1.0
Phaser 4 examples
Text
29
examples
Examples
29
Basic Text
Create text objects using default settings, style configuration objects, or method chaining to set font properties like family, size, and color.
Basic Text Creation
Demonstrates the simplest way to add and display a text string at specific coordinates in a scene.
Change Text
Demonstrates how to update the string content of a Text object dynamically using both the text property and the setText method.
Create Text from Configuration
Demonstrates how to create and style a Text Game Object by passing a configuration object to the Scene Maker.
Custom Webfonts via WebFont Loader
Demonstrates how to dynamically inject CSS @font-face rules into the document and use the WebFont Loader to ensure custom fonts are ready before rendering Text objects.
Emojis in Text
Demonstrates how to render emojis within a Text Game Object using emoji characters directly or Unicode escape sequences.
Google Webfont
This example demonstrates how to use the WebFont Loader to import and apply Google Fonts to Text objects, ensuring fonts are loaded before they are rendered.
Italic Text and Padding
Demonstrates how to apply italic font styles to Text objects and use padding to prevent character clipping on the right edge.
Multi-Line Text
Demonstrates how to display multiple lines of text within a single Text Game Object by providing an array of strings.
Multi-Line Text Alignment
Demonstrates how to display multi-line text using an array of strings and apply horizontal alignment.
Right To Left Text
This example demonstrates how to render right-to-left (RTL) text scripts using the rtl property, showcasing how to handle punctuation, numerals, and bidirectional text marks.
Right-Aligned Text Origin
Demonstrates how to right-align a single line of text relative to its position by setting the horizontal origin to 1.
Simple Text Button
Demonstrates how to create an interactive UI button using a Text Game Object with background colors and hover state pointer events.
Speech Bubble
Demonstrates how to create a stylized speech bubble using Graphics for the bubble shape and arrow, combined with a Text object featuring word wrapping and alignment.
Text Alignment
Demonstrates how to align multiple lines of text within a Text Game Object using the left, center, and right alignment properties.
Text Bounds
Demonstrates how to retrieve and visualize the rectangular bounds of Text objects. See how the bounding box dynamically updates as content changes and how it accounts for styles like stroke and shadow.
Text Gradient
Apply a linear color gradient to a Text object using the native Canvas context API.
Text Line Spacing
Demonstrates how to adjust the vertical distance between multiple lines of text in a Text Game Object using the lineSpacing property.
Text Metrics
Provide pre-defined text metrics in the configuration object to bypass internal canvas scanning and improve initialization performance.
Text Object Test String
Demonstrates how to use the testString property to influence the calculation of font metrics and vertical text alignment.
Text Origin
Demonstrates how to set the origin of a Text object to center it on its position coordinates, allowing it to rotate around its own center point.
Text Padding
Demonstrates how to apply internal padding to Text objects using uniform values, axis-specific values, or individual settings for each side.
Text Padding from Config
Demonstrates how to apply uniform, axis-based, or per-side padding to Text objects using a configuration object.
Text Shadow and Stroke Styles
Demonstrates how to control drop shadows on Text objects, specifically applying them to the fill, the stroke, or both.
Text to JSON
Demonstrates how to export a Text game object's properties and style configuration into a JSON-compatible object using the toJSON method.
Text with Fallback Font
This example demonstrates how to specify a comma-separated list of fallback fonts for a Text object to ensure it renders correctly if the primary font is missing.
Word Wrap
Demonstrates various word wrapping techniques for Text objects, including basic width-based wrapping, advanced wrapping with whitespace trimming, and custom wrapping callbacks for manual control.
Word Wrap by Callback
Demonstrates how to use a custom callback function to define your own logic for word-wrapping text.
Word Wrap By Width
Demonstrates how to wrap text by a specified pixel width, highlighting the differences between basic wrapping and advanced wrapping for whitespace handling and long words.