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)
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).
Technical notes Edit
The current camera offset is memory-mapped and may be read or written directly:
- 0x5f28: offset x lo byte
- 0x5f29: offset x hi byte
- 0x5f2a: offset y lo byte
- 0x5f2b: 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=peek(0x5f28)+peek(0x5f29)*256 camera_y=peek(0x5f2a)+peek(0x5f2b)*256