topdownengine.env_object Reference¶
Resolved: Mutable Default Argument Bug (Fixed in v0.4.3)
Prior to version 0.4.3, omitting the colliders argument in the EnvObject
initialization caused colliders to persist across separate instances due to
a mutable default list.
The default argument has been changed to None and now safely initializes
a fresh, empty list for every individual instance.
EnvObject
¶
Bases: GameObject
This class represents all environment objects in the engine.
Attributes:
| Name | Type | Description |
|---|---|---|
CAUSES_COLLISIONS |
bool
|
Overrides GameObject. Defaults to True. |
Source code in topdownengine\env_object.py
current_frame
property
¶
Current animation frame the GameObject is on.
draw_index
property
¶
The draw index of the GameObject.
image
property
¶
Image for drawing.
rect
property
¶
Rect object for drawing.
world_colliders
property
¶
Return a list of collider Rects in world-space, as opposed to GameObject.colliders, which uses relative positioning to the GameObject itself.
__init__(animation_paths=None, frame_size=None, colliders=None)
¶
Initialize the EnvObject.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
animation_paths
|
dict[str, str]
|
The animation paths to load animations from. Defaults to None. |
None
|
frame_size
|
tuple[int] | None
|
The frame size to use to load/generate animations. Defaults to None. |
None
|
colliders
|
list[Rect] | None
|
The list of colliders of the EnvObject, relative to itself. If it is set to None, there will be no colliders. Defaults to None. |
None
|
Source code in topdownengine\env_object.py
generate_colliders()
¶
Default list of Rect objects for collisions.
Source code in topdownengine\game_object.py
load_animations()
¶
Load unscaled animations.
Source code in topdownengine\game_object.py
scale_animations()
¶
Scale animations.
set_scale(new_scale, game)
classmethod
¶
This method sets the target scale of all GameObjects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_scale
|
int
|
The new target scale being set to. |
required |
game
|
Game | None
|
The Game object being used. While you may pass in None, you MUST pass in a Game instance if you have already defined GameObjects. |
required |
Source code in topdownengine\game_object.py
update(dt, game)
¶
This method updates the GameObject instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
The deltatime. |
required |
game
|
Game
|
The Game object. |
required |