Text
A text object for rendering strings with a specified font.
Constructor
Text(font: Font)Parameters
font: The font to use for rendering this text.
Properties
| Name | Description | Type |
|---|---|---|
text | The string content of the text object. | str |
color | The color of the text. | Color |
wrap_width | The width at which to wrap text. Set to 0 for no wrapping. | int |
size | The size of the text in pixels. | Vec2 |
width | The width of the text in pixels. | int |
height | The height of the text in pixels. | int |
shadow_color | The color of the text shadow. | Color |
shadow_offset | The offset of the text shadow. | Vec2 |
Methods
Draw
draw(pos: Vec2 = None, anchor: Anchor = Anchor.TOP_LEFT) → NoneDraw text to the renderer.
\n will write text on a new line.
A shadow is drawn if shadow_color.a > 0 and shadow_offset is not (0, 0).
Parameters
pos: The position to draw the text at. Defaults to (0, 0).anchor: The anchor point to draw the text from. Defaults to TOP_LEFT.
Set Font
set_font(font: Font) → NoneSet the font to use for drawing text.
Parameters
font: The font to use for drawing text.
Get Rect
get_rect() → RectGet the bounding rectangle of the text.
Returns
Rect : The bounding rectangle of the text.