Entities
We will assume you are familiar with the pygame-ce library fundamentals in the following. If not, please refer to the pygame-ce docs.
Attributes
Entities are the things that fill your scene — players, NPCs, interfaces, or even a whole level.
Each entity has the following attributes:
rect : pygame.FRect— position and sizeuid : int— unique id for every entity createdtags : list[str]— list of tagsdebug_color: tuple | str— color used to outline the entity in the debugging viewparent_scene : Scene | None— scene the entity belongs toparent_layer : SceneLayer | None— layer the entity belongs to
Useful methods:
set_position(self, x, y)/set_center(self, x, y)add_tags(self, *tags)/remove_tags(self, *tags)has_tags(self, *tags)/has_any_tags(self, *tags)kill()— remove this entity from its parent scene/layer
Drawable
Drawable extends Entity with a surface and draw state:
visible,render_order,surface,blit_flagsset_render_order(n)— controls draw order within its layerset_visible,set_alpha,set_sizedraw(camera)— blits the surface if visible and in view
Lifecycle
Add entities through the scene by naming the layer:
scene.add("world", player)
scene.add("hud", overlay_entity)
scene.root.add(button) # GUI widgets under the hud root
Adds and removes are deferred by one frame and applied when the layer flushes.
When an entity is attached or detached:
do_when_added(self)do_when_removed(self)