Fonts
render.makefont.RdFonts are used to draw text ingame with render.text(). A font is a list including $sprites, a list of sprites for each character supported by the font.
All fonts are monospaced.
Details
Fonts can have the following metadata:
$width: | | Width of each character in the font, in pixels. |
$height: | Height of each character in the font. | |
$kerning: | Default spacing between characters. | |
$linespacing: | Default vertical spacing between lines of text. | |
$sprites: | List of sprite matrices for each character. |
render.makefont()
render.makefont() is a convenient extension of render.makesprite() to create batches of characters at once. To use it, enter a string of all characters in the char_group lined up horizontally (see examples).
The function does NOT create a full font object; it just generates some of the $sprites.
The function returns a list with a sprite set for each character. The sprites' widths must be set by width, while the height is determined by the number of newlines in txt like in render.makesprite().
The char_groups are as follows:
uppercase: | | abcdefghijklmnopqrstuvwxyz |
lowercase: | ABCDEFGHIJKLMNOPQRSTUVWXYZ | |
numbers: | 0123456789 | |
symbols: | ()[]{}<>+-*/=~.,:;'"``!?@#$%^&_ |
Missing characters will be replaced with empty sprites of the appropriate size.
Examples
#used for `fonts.3x3`:
example_font = list(
width = 3,
height = 3,
sprites = render.makefont('uppercase',width=3,'
o oo ooo oo ooo ooo o o o ooo ooo o o o o o ooo ooo ooo o ooo oo ooo o o o o o o o o o o oo
ooo ooo o o o oo oo o ooo o o oo o ooo o o o o ooo o o oo o o o o o o ooo o o o
o o ooo ooo oo ooo o ooo o o ooo oo o o ooo ooo o o ooo o oo o o oo o ooo o ooo o o o oo
')
)
render.matrix(cbind(
example_font$sprites$H,
matrix(0,3,1),
example_font$sprites$I
))
#> [] [] [][][]
#> [][][] []
#> [] [] [][][]