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
Multiple Cameras
If multiple cameras exist, the first active camera found in the world is used.