Cls
Parameters
| None. |
Description
|
Clears the current buffer to the cls colour. This is the "wipe the slate" command at the top of almost every game loop: Cls, draw the new frame, Flip. Without it, each frame draws over the remains of the last one and moving things leave trails. The fill colour is black until you change it with ClsColor. Cls clears whatever buffer is current - so it can also blank an ImageBuffer() you are composing. One subtlety: it clears only the area inside the current Viewport, so with a reduced viewport the rest of the buffer is left untouched - useful for redrawing just a game window while a HUD stays put. In 3D games you normally skip Cls: RenderWorld repaints the whole view every frame anyway, and clearing first is wasted work (CameraClsMode controls that clear instead). See also: ClsColor, Flip, SetBuffer, Viewport. |
Example
; Cls Example ; ----------- Graphics 640,480,0,2 SetBuffer BackBuffer() clearing=1 angle#=0 While Not KeyDown(1) ; Space toggles whether we clear the screen each frame If KeyHit(57) Then clearing=1-clearing ; Cls wipes the drawing buffer clean; skip it and drawings pile up If clearing Then Cls ; A ball circling the screen centre angle=angle+2 Color 128+Sin(angle)*127,200,128-Sin(angle)*100 Oval 300+Cos(angle)*180,220+Sin(angle)*140,40,40,1 ; Black panel keeps the overlay readable when trails build up Color 0,0,0 Rect 0,0,640,44,1 Color 255,255,255 Text 0,0,"Space: toggle Cls on/off Esc: exit" If clearing Then Text 0,20,"Cls ON - each frame starts clean" Else Text 0,20,"Cls OFF - old frames remain as trails" EndIf Flip Wend End
Index