PICO-8 Wiki
(update with some behaviors I've noticed, among other tweaks like adding links)
m (→‎Examples: formatting)
Line 33: Line 33:
 
cursor(20, 24)
 
cursor(20, 24)
   
print('line one')
+
print("line one")
print('line two')
+
print("line two")
print('line three')
+
print("line three")
   
 
-- get the cursor position from its memory-mapped addresses
 
-- get the cursor position from its memory-mapped addresses
cursor_x=peek(0x5f26)
+
cursor_x = peek(0x5f26)
cursor_y=peek(0x5f27)
+
cursor_y = peek(0x5f27)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
[[File:Cursor-example.png|thumb|220x220px]]
 
[[File:Cursor-example.png|thumb|220x220px]]

Revision as of 04:33, 1 March 2020

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

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

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

-- 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