TextObject Module
TextObject
Bases: RoomObject
A drawable text object for displaying text in a game level.
Inherits from RoomObject and provides functionality for rendering and updating text with customizable font, size, color, and style.
Attributes:
Name | Type | Description |
---|---|---|
rendered_text |
The rendered pygame Surface of the text. |
|
rect |
Rect
|
The rectangle representing the text's position and size. |
built_font |
The pygame Font object used for rendering. |
|
text |
str
|
The text string to display. |
size |
int
|
Font size. |
font |
str
|
Font name. |
colour |
tuple
|
RGB color of the text. |
bold |
bool
|
Whether the font is bold. |
Source code in GameFrame/TextObject.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
__init__(room, x, y, text='Not Set', size=60, font='Comic Sans MS', colour=(0, 0, 0), bold=False)
Initializes a TextObject with the given properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
room
|
Level
|
The game level or room where the object is placed. |
required |
x
|
int
|
The x-coordinate of the object. |
required |
y
|
int
|
The y-coordinate of the object. |
required |
text
|
str
|
The text to display. Defaults to 'Not Set'. |
'Not Set'
|
size
|
int
|
Font size. Defaults to 60. |
60
|
font
|
str
|
Font name. Defaults to 'Comic Sans MS'. |
'Comic Sans MS'
|
colour
|
tuple
|
RGB color of the text. Defaults to (0, 0, 0). |
(0, 0, 0)
|
bold
|
bool
|
Whether the font is bold. Defaults to False. |
False
|
Source code in GameFrame/TextObject.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
update_text()
Updates the rendered text surface and its rectangle based on current properties.
Source code in GameFrame/TextObject.py
50 51 52 53 54 55 56 57 58 |
|