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

1.5 KiB

id name category kind tokens sig tip order ns member
screen-draw_number Screen.draw_number screen namespace-method Screen.draw_number Screen.draw_number(x, y, value, color, scale) Draw an integer directly, with no string allocation or conversion. 5 Screen draw_number

Draws an integer as digits using the built-in font, without first turning it into a string — so it never allocates and is safe to call every frame for constantly-changing values. Use it for scores, timers, frame counts, health totals, and any HUD number, while reserving Screen.draw_text for fixed labels. It takes the same top-left position, color, and integer scale as draw_text. Negative values are drawn with a leading minus sign.

Parameters:

  • x — the left edge of the first digit, in pixels
  • y — the top edge of the number, in pixels
  • value — the integer to draw
  • color — the digit color, e.g. a Color.* name or a 0xRRGGBB literal
  • scale — integer size multiplier (1 = native size)
program ScoreHud {
  state ScoreHudState {
    score: int = 0
  }

  handler EarnPoints(score_hud_st: mut ScoreHudState) phase Update {
    score_hud_st.score = score_hud_st.score + 1
  }

  handler DrawWorld(score_hud_st: ScoreHudState) phase Render {
    Screen.clear(Color.MidnightBlue)
    Screen.draw_text(x: 6, y: 4, text: "SCORE", color: Color.White, scale: 1)
    Screen.draw_number(x: 52, y: 4, value: score_hud_st.score, color: Color.Gold, scale: 1)
    Screen.show()
  }
}