class Eagle::BitmapFont

Overview

A font drawn from a grid of glyph images, as used by classic and pixel-art games.

atlas = Texture.new(Image.new(96, 48))
font = BitmapFont.grid(atlas, 6, 8) # glyphs from ' ' onward, row by row

Defined in:

eagle/graphics/font.cr

Constructors

Instance Method Summary

Instance methods inherited from class Eagle::Font

glyph(char : Char) : Glyph | Nil glyph, height : Float32 height, kerning(a : Char, b : Char) : Float32 kerning, letter_spacing : Float32 letter_spacing, letter_spacing=(letter_spacing : Float32) letter_spacing=, line_height : Float32 line_height, measure(text : String) : Vec2 measure, scale : Float32 scale, scale=(scale : Float32) scale=, texture : Texture texture, width(text : String) : Float32 width, wrap(text : String, max_width : Number) : Array(String) wrap

Constructor methods inherited from class Eagle::Font

default : Font default, load(path : String, size : Number, filter : GPU::Filter = GPU::Filter::Linear) : Font load

Constructor Detail

def self.builtin : BitmapFont #

Builds Eagle's embedded 5x7 pixel font. Font.default returns a shared copy.


def self.grid(texture : Texture, cell_w : Int32, cell_h : Int32, first : Char = ' ', count : Int32 = 95, advance : Int32 | Nil = nil) : BitmapFont #

Builds a font from a sheet where glyphs sit in equal cells, row by row, starting at first.


def self.new(texture : Texture, line_height : Float32) #

Creates an empty bitmap font. Add glyphs with #add, or use .grid to build one from a sheet.


Instance Method Detail

def add(char : Char, region : TextureRegion, advance : Float32 | Nil = nil, offset : Vec2 = Vec2::ZERO) : self #

Adds a glyph for char. The advance defaults to the region width.


def glyph(char : Char) : Glyph | Nil #

The glyph for char, or nil.


def line_height : Float32 #
Description copied from class Eagle::Font

Distance between baselines, in pixels, before scale.


def texture : Texture #
Description copied from class Eagle::Font

The atlas texture holding the glyphs.