- Sets the camera offset in the draw state.
- The x offset, in pixels, to subtract from future draw coordinates. (default 0)
- The y offset, in pixels, to subtract from future draw coordinates. (default 0)
- An x,y tuple representing the previous camera offset.
Setting a camera offset causes all subsequent draw operations to have the offset subtracted from their x and y coordinates. Camera sets the origin point for draw functions, and by default it is
camera() works is somewhat unintuitive. So, if you might expect to use
camera(64,64) to put the camera origin in the middle of the screen, you'd actually use
camera(-64,-64) to move the screen so that its middle is in front of the camera. This is probably because
camera() sets an screen variable that is invisibly used by all draw functions, and in this case, the origin changed from
Camera offsets can be used to implement screen effects such as parallax scrolling (with a different offset per layer) or screen shake (a small random offset per frame).
The current camera offset is memory-mapped and may be read or written directly:
- 0x5f28 / 24360: offset x lo byte
- 0x5f29 / 24361: offset x hi byte
- 0x5f2a / 24362: offset y lo byte
- 0x5f2b / 24363: offset y hi byte
-- draw a dark blue circle at (20, 20) circfill(20, 20, 10, 1) camera(-2, 2) -- draw a white circle at (22, 18) circfill(20, 20, 10, 7) camera(-64, -64) -- draw a big red circle, centered circfill(0, 0, 63, 8) -- get the current offset from its memory-mapped addresses camera_x = peek2(0x5f28) camera_y = peek2(0x5f2a)