world
The world object is the core of Pyxen’s entity system. It manages entity lifecycle, component storage, and queries.
See also: Game Loop.
Entity Lifecycle
Spawn
e = world.spawn(name="enemy", x=100, y=50)
Creates a new entity with optional components.
See: spawn()
Destroy
world.destroy(e)
Removes an entity and all of its components.
See: destroy()
Queries
world.all()
for e in world.all("enemy", without=("dead",)):
...
Returns an iterator over entities matching required components.
See: world.all()
world.pick()
for e in world.pick(input.mouse.pos.x, input.mouse.pos.y, "clickable"):
e.on_click()
Picks entities at a screen-space point or rectangle. Returns an iterator, topmost first.
See: world.pick()
Lookup
world.get()
Retrieve an entity by name.
player = world.get(name="player")
If multiple entities share the same name, the one with the lowest entity ID is returned.
See: world.get()
Spatial Systems
GridMap
Attach a spatial grid container to an entity.
e.map = GridMap(rows=10, columns=10, size=(16,16))
See: GridMap
GridBody
Attach grid-based collision and movement.
e.body = GridBody(...)
See: GridBody
Mini samples
Open from Samples & Tutorials inside Pyxen:
- world.spawn() — Create an entity with a sprite at a position.
- world.destroy() — Remove entities from the world. Click any square to destroy it.
- world.all() — Query every entity that has a given component.
- world.get() — Look up a single entity by name.
- world.pick() — Pick the entity under the cursor on click.