API Reference › Screen — drawing › Screen.fill_rectangle
method

Screen.fill_rectangle

Screen.fill_rectangle(x, y, width, height, color)

Draws a solid block of color from the top-left corner (x, y) spanning width by height pixels. This is the workhorse for drawing tiles, sprites-from-primitives, health bars, and background panels, since a Ludic game paints every pixel itself rather than loading image assets. Coordinates are in pixels measured from the top-left of the screen, so multiply a grid column/row by your tile size to place things on a board. Parts of the rectangle that fall outside the framebuffer are simply clipped.

Parameters

xthe left edge, in pixels from the left of the screen
ythe top edge, in pixels from the top of the screen
widththe rectangle width in pixels
heightthe rectangle height in pixels
colorthe fill color, e.g. a Color.* name or a 0xRRGGBB literal

Example

program FilledTiles {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  const TILE_SIZE: int = 16

  handler SpawnPlayer phase Start {
    spawn Player { Position { column: 4, row: 3 } }
  }

  handler DrawWorld phase Render {
    Screen.clear(Color.MidnightBlue)
    for (Position) in query [Position, {Player}] {
      Screen.fill_rectangle(
        x: Position.column * TILE_SIZE,
        y: Position.row * TILE_SIZE,
        width: TILE_SIZE,
        height: TILE_SIZE,
        color: Color.LimeGreen)
    }
    Screen.show()
  }
}
← All symbols