Advanced
Generic destroy methods to be overridden by the subclass
This is a function that will create a texture from a text string, style and resolution. Useful if you want to make a texture of your text and use if for various other pixi things!
The options of the text that will be used to generate the texture.
Constructor options used for Text
instances. These options extend TextOptions with
canvas-specific features like texture styling.
Optional
anchor?: number | PointDataThe anchor point of the text that controls the origin point for positioning and rotation. Can be a number (same value for x/y) or a PointData object.
// Set anchor to center
const text = new Text({
text: 'Hello Pixi!',
anchor: 0.5 // Same as { x: 0.5, y: 0.5 }
});
// Set anchor to top-left
const text2 = new Text({
text: 'Hello Pixi!',
anchor: { x: 0, y: 0 } // Top-left corner
});
// Set anchor to bottom-right
const text3 = new Text({
text: 'Hello Pixi!',
anchor: { x: 1, y: 1 } // Bottom-right corner
});
Optional
resolution?: numberThe resolution/device pixel ratio for rendering. Higher values result in sharper text at the cost of performance. Set to null for auto-resolution based on device.
Optional
roundPixels?: booleanWhether to round the x/y position to whole pixels. Enabling can prevent anti-aliasing of text edges but may cause slight position shifting.
Optional
style?: TextStyle | TextStyleOptionsThe style configuration for the text. Can be a TextStyle instance or a configuration object. Supports canvas text styles, HTML text styles, and bitmap text styles.
const text = new Text({
text: 'Styled Text',
style: {
fontSize: 24,
fill: 0xff1010, // Red color
fontFamily: 'Arial',
align: 'center', // Center alignment
stroke: { color: '#4a1850', width: 5 }, // Purple stroke
dropShadow: {
color: '#000000', // Black shadow
blur: 4, // Shadow blur
distance: 6 // Shadow distance
}
}
});
const htmlText = new HTMLText({
text: 'HTML Styled Text',
style: {
fontSize: '20px',
fill: 'blue',
fontFamily: 'Verdana',
}
});
const bitmapText = new BitmapText({
text: 'Bitmap Styled Text',
style: {
fontName: 'Arial',
fontSize: 32,
}
Optional
text?: TextStringThe text content to display. Use '\n' for line breaks. Accepts strings, numbers, or objects with toString() method.
Optional
Advanced
textureStyle?: TextureStyleOptions | TextureStyleOptional texture style to use for the text texture. This allows fine control over how the text is rendered to a texture before being displayed.
The texture style can affect:
the newly created texture
Returns a texture that was created wit the above getTexture
function.
Handy if you are done with a texture and want to return it to the pool.
The texture to be returned.
System plugin to the renderer to manage canvas text.