- Clears the graphics buffer.
- color
-
- A color to use for the background. The default is 0 (black).
The cls()
function clears the graphics buffer. By default this means setting every pixel to color index 0, which is black by default. Optionally, a different color index may be provided to clear the screen to that color.
The clip rectangle is automatically reset to (0, 0, 128, 128) before the clear is performed, so it is only possible to use cls()
to clear the entire screen. To clear sub-rectangles of the screen, use rectfill()
instead.
Additionally, the cursor position in the draw state is set to (0, 0).
The color index written is always exactly as given, rather than being remapped via the pal()
feature. For instance, pal(8, 12) cls(8)
fills the screen with 8 (red), not 12 (blue).
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, wrap 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.