FANDOM


cursor( [x,] [y,] [col] )
Sets the left-margin cursor position for print().
x
The x coordinate of the upper left corner of the line. The default is 0.

y
The y coordinate of the upper left corner of the line. The default is 0.

col
(Optional) The palette index to set the pen color to.

The draw state maintains a cursor location (and a pen color) for printing text with the print() function. PICO-8 uses this to maintain a scrolling display, especially for the command prompt.

The coordinates passed in set the starting location of the next print() call as well as setting the left margin for all subsequent calls.

See print() for a more detailed explanation of the text cursor's behavior.

Other functions that affect the cursor Edit

Calling cls() effectively also calls cursor(0, 0).

Calling print(str) without explicit coordinate arguments will adjust the cursor's Y value when required for newlines and scrolling.

Calling print(str, x, y) with explicit coordinate arguments effectively also calls cursor(x, y) after the entire string is printed.

Technical notes Edit

The current cursor position is memory-mapped and may be read or written directly:

  • 0x5f26: cursor x position
  • 0x5f27: cursor y position
  • 0x5f25: pen color (see color())

Examples Edit

-- set the cursor position to (20, 24).
cursor(20, 24)
 
print("line one")
print("line two")
print("line three")
 
-- get the cursor position from its memory-mapped addresses
cursor_x = peek(0x5f26)
cursor_y = peek(0x5f27)
Cursor-example

See also Edit

Community content is available under CC-BY-SA unless otherwise noted.