ludic/docs/language/screen/screen-clear.md

1.3 KiB

id name category kind tokens sig tip order ns member
screen-clear Screen.clear screen namespace-method Screen.clear Screen.clear(color) Fill the whole framebuffer with one color to start a fresh frame. 0 Screen clear

Paints every pixel of the framebuffer a single color, wiping whatever the previous frame drew. Call it first inside your Render handler so each frame starts from a known background instead of leftover pixels. The one argument is a color, which can be a named palette value such as Color.MidnightBlue or a raw hex literal like 0x0d1020. After clearing, draw the scene on top and finish with Screen.show().

Parameters:

  • color — the background color to fill with, e.g. a Color.* name or a 0xRRGGBB literal
program ClearBackground {
  state ClearBackgroundState {
    elapsed_frames: int = 0
  }

  handler CountFrames(clear_background_st: mut ClearBackgroundState) phase Update {
    clear_background_st.elapsed_frames = clear_background_st.elapsed_frames + 1
  }

  handler DrawWorld(clear_background_st: ClearBackgroundState) phase Render {
    Screen.clear(Color.MidnightBlue)
    Screen.draw_number(x: 8, y: 8, value: clear_background_st.elapsed_frames, color: Color.White, scale: 1)
    Screen.show()
  }
}