Text
A text object for rendering text to the active renderer.
Constructor
Properties
| Name | Description | Type |
|---|---|---|
color | Get or set the color of the rendered text. | Color |
height | Get the height in pixels of the current text. | int |
shadow_color | Get or set the shadow color for the text. | Color |
shadow_offset | Get or set the shadow offset for the text. | Vec2 |
size | Get the size (width, height) of the current text as a Vec2. | Vec2 |
text | Get or set the text string to be rendered. | str |
width | Get the width in pixels of the current text. | int |
wrap_width | Get or set the wrap width in pixels for text wrapping. | int |
Methods
Draw
draw(pos: Any = None, anchor: Any = None) → NoneDraw the text to the renderer at the specified position with alignment. A shadow is drawn if shadow_color.a > 0 and shadow_offset is not (0, 0).
Args
pos: The position in pixels. Defaults to (0, 0).anchor: The anchor point for alignment (0.0-1.0). Defaults to top left (0, 0).
Raises
RuntimeError: If the renderer is not initialized or text drawing fails.RuntimeError: If the text font is not set or has gone out of scope.
Get Rect
get_rect() → RectGet the bounding rectangle of the current text.
Returns
Rect : A rectangle with x=0, y=0, and width/height of the text.