Cls

From Pico-8 Wiki
Jump to navigation Jump to search
cls( [color] )
Clears the graphics buffer.
color
A color to use for the background. The default is 0 (black).

The cls() function clears the graphics buffer, effectively setting every pixel to the color 0. If the color argument is provided, that number is used instead.

cls() also sets the text cursor in the draw state to (0, 0). On top of this, cls() also also resets the clipping rectangle to (0,0).

This ignores the alternate palette set by pal() for the purposes of using color 0. (pal(0, 7) cls() does not fill the screen with white.) To fill the screen with a specific color, use rectfill.

It is common (though not required) to call cls() at the beginning of the _draw() function as part of the game loop.

Examples

function _init()
  x = 0
end

function _update()
  -- add 1 to x. if x > 128, reset it to 0.
  x = (x + 1) % 128
end

function _draw()
  cls()
  circfill(x, x, 10, 8)
end

Try removing the cls() call from this example.

Cls example.gif

See also