API Reference › Screen — drawing › Screen.camera
method

Screen.camera

Screen.camera(x, y)

Sets a camera offset applied to every draw: a world point (wx, wy) lands on screen at (wx - x, wy - y). Move it to scroll the world under a fixed viewport. The camera moves everything drawn, so reset it to (0, 0) before drawing a fixed HUD. Same control as Camera.set. Deterministic.

Example

program Demo {
  property Position { x: int = 0, y: int = 0 }
  model Player { Position }
  handler DrawWorld phase Render {
    Screen.camera(Position.x - 160, Position.y - 120)   # centre on the player
    Screen.fill_rectangle(x: 0, y: 0, width: 16, height: 16, color: Color.Red)
    Screen.camera(0, 0)                                  # HUD in screen space
    Screen.draw_text(x: 4, y: 4, text: "SCORE", color: Color.White, scale: 1)
    Screen.show()
  }
}
← All symbols