pyxen.Camera
A Camera defines what the renderer sees in the world.
It is attached to an entity as a component. The renderer uses the camera’s transform and properties to compute the view and projection matrices.
A world must contain at least one camera to render anything.
Creating a Camera
camera = world.spawn(
x=0,
y=0,
camera=Camera()
)
Or added later:
camera = world.spawn()
camera.camera = Camera()
Camera Uses the Entity Transform
A camera does not store position itself — it uses the entity’s transform:
camera.x = 100
camera.y = 50
camera.rotation = 30
camera.scale = (2, 2)
Moving the entity moves the view. Parent transforms also affect the camera.
Properties
zoom
camera.camera.zoom = 1.0
Type: float
Default: 1.0
| Value | Effect |
|---|---|
1.0 | Default view |
>1 | Zoom in |
<1 | Zoom out |
Example:
camera.camera.zoom = 2.0 # zoom in
camera.camera.zoom = 0.5 # zoom out
Zoom affects only the projection matrix, not the entity transform.
Example: Following a Player
player = world.spawn(x=0, y=0, sprite=hero)
camera = world.spawn(camera=Camera())
def update():
camera.x = player.x
camera.y = player.y
Or simpler, set the camera parent to the player:
player = world.spawn(x=0, y=0, sprite=hero)
camera = world.spawn(camera=Camera(), parent=player)
Zoomed-out camera:
camera.camera.zoom = 0.75
Screen Shake & Flash
A camera can apply two screen effects, both measured in frames (Pyxen runs at a fixed 30 fps):
cam = entity.camera
cam.shake(intensity, duration=8) # jolt the view; fades out over `duration`
cam.flash(color, duration=8) # full-screen colour that fades out
| Method | Parameters | Description |
|---|---|---|
shake(intensity, duration=8) | intensity in pixels, duration in frames | Jitters the view by a deterministic, decaying offset. |
flash(color, duration=8) | color as a Color or (r, g, b[, a]), duration in frames | Fades a full-screen colour overlay out over duration. |
def on_hit():
entity.camera.shake(3.0, 10)
entity.camera.flash((1.0, 0.0, 0.0, 0.6), 6)
Both effects are deterministic, so they replay identically in the time-travel debugger.
Multiple Cameras
If multiple cameras exist, the first active camera found in the world is used.
Mini samples
Open from Samples & Tutorials inside Pyxen:
- Camera() follow — Camera attached to an entity follows it. Use arrow keys.
- tween zoom — Animate the camera’s zoom factor.