Skip to main content
Version: Release

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 size
  • uid : int — unique id for every entity created
  • tags : list[str] — list of tags
  • debug_color: tuple | str — color used to outline the entity in the debugging view
  • parent_scene : Scene | None — scene the entity belongs to
  • parent_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_flags
  • set_render_order(n) — controls draw order within its layer
  • set_visible, set_alpha, set_size
  • draw(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)