Documentation / @debuffjp/core / BitmapFont
Class: BitmapFont
Defined in: spryte/dist/bitmap-font.d.ts:37
A pixel font from a sprite sheet. Pass it as font to draw.text and draw.measure: glyphs land on whole logical pixels after scale and translation, so it stays crisp at any integer scale. Rotated or skewed glyphs keep their transformed positions. Before 0.12.2, only local positions were rounded.
// assets/font@6x9.png: glyphs on a 6×9 grid, exported from Aseprite
const font = new BitmapFont({ frames: assets.frames("font"), chars: BitmapFont.ASCII });
draw.text("coins 3", 4, 4, { font, color: "#fbbf24" });Constructors
Constructor
new BitmapFont(
o):BitmapFont
Defined in: spryte/dist/bitmap-font.d.ts:46
Parameters
o
Returns
BitmapFont
Properties
height
readonlyheight:number
Defined in: spryte/dist/bitmap-font.d.ts:41
Cell height in pixels.
lineHeight
readonlylineHeight:number
Defined in: spryte/dist/bitmap-font.d.ts:42
spacing
readonlyspacing:number
Defined in: spryte/dist/bitmap-font.d.ts:43
ASCII
readonlystaticASCII:string
Defined in: spryte/dist/bitmap-font.d.ts:39
Printable ASCII from space to "~", the order most font sheets use.
Methods
glyph()
glyph(
ch):Glyph|undefined
Defined in: spryte/dist/bitmap-font.d.ts:47
Parameters
ch
string
Returns
Glyph | undefined
lineWidth()
lineWidth(
line):number
Defined in: spryte/dist/bitmap-font.d.ts:54
Width of one line, without trailing spacing.
Parameters
line
string
Returns
number
measure()
measure(
text):object
Defined in: spryte/dist/bitmap-font.d.ts:49
Size of text in pixels. Lines split on "\n".
Parameters
text
string
Returns
object
h
h:
number
w
w:
number