AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

FontAsset.Setup

Method

public RB.AssetStatus Setup(char unicodeStart, char unicodeEnd, Vector2i srcPos, SpriteSheetAsset spriteSheet, Vector2i glyphSize, int glyphsPerRow, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(List< char > characterList, Vector2i srcPos, SpriteSheetAsset spriteSheet, Vector2i glyphSize, int glyphsPerRow, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(char unicodeStart, char unicodeEnd, List< PackedSpriteglyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(char unicodeStart, char unicodeEnd, List< PackedSpriteIDglyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(char unicodeStart, char unicodeEnd, List< FastStringglyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(char unicodeStart, char unicodeEnd, List< string > glyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(List< char > characterList, List< PackedSpriteglyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(List< char > characterList, List< PackedSpriteIDglyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(List< char > characterList, List< FastStringglyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)
public RB.AssetStatus Setup(List< char > characterList, List< string > glyphSprites, SpriteSheetAsset spriteSheet, int characterSpacing, int lineSpacing, bool monospaced)

Parameters

unicodeStart char First unicode character in the font
unicodeEnd char Last unicode character in the font
srcPos Vector2i Top left corner of the set of glyphs in the sprite sheet
spriteSheet SpriteSheetAsset The sprite sheet containing the font
glyphSize Vector2i Dimensions of a single glyph
glyphsPerRow int Amount of glyphs per row in the sprite sheet
characterSpacing int Spacing between characters
lineSpacing int Line spacing between lines of text
monospaced bool True if font is monospaced
characterList List< char > List of all characters in this font. If there are duplicate characters the last copy is used.
glyphSprites List< PackedSprite > List of packed sprites to use for the glyphs
glyphSprites List< PackedSpriteID > List of packed sprite ids to use for the glyphs
glyphSprites List< FastString > List of packed sprite names to use for the glyphs
glyphSprites List< string > List of packed sprites to use for the glyphs. Must be in same order as characterList

Returns

RB.AssetStatus

Setup status

Description

Setup a custom font that can be used with RB.Print. Fonts are setup for a contiguous range of unicode characters specified by unicodeStart and unicodeEnd parameters. Unicode gaps are not allowed, all glyphs in the given range must be provided, even if they are blank.

Glyphs in a font can either come from a grid of sprites in a sprite sheet with the given glyphsPerRow. Glyphs from a sprite pack can be explicitly listed with the glyphSprites parameter.

The glyphSize specifies the maximum space a single glyph will take, and corresponds to the size of each grid cell when specifying glyphs by a grid of sprites. RetroBlit will automatically trim empty horizontal white space to the left and right of each glyph, unless the monospaced parameter is specified, in which case empty space is not trimmed at all, and all glyphs will occupy the same horizontal and vertical space.

Printed glyphs are spaced out with 1 pixel horizontal and vertical spacing by default. The spacing can optionally be altered with the characterSpacing and lineSpacing parameters.


Example sprite sheet containing a grid of font glyphs. See example code below on how this font could be loaded.

Example

SpriteSheetAsset spritesheetMain = new SpriteSheetAsset();
FontAsset retroFont = new FontAsset();

void Initialize() {
    spritesheetMain.Load("spritesheets/main");

    retroFont.Setup(
        'A''Z'// Character range, all characters between A to Z
        new Vector2i(016), // Position of the top left corner of the sprite grid
        spritesheetMain, // Sprite sheet
        new Vector2i(1212), // Glyph size / grid cell size
        10// Glyphs per row
        1// Horizontal spacing between characters
        2// Vertical spacing between lines of text
        false // Not mono-space
        );
}

void Render() {
    // These characters will all be be printed
    RB.Print(retroFont, new Vector2i(00), "HELLO THERE", Color.white, text);

    // Only "H" and "T" will be printed because the other characters are not in
    // the character set for this font!
    RB.Print(retroFont, new Vector2i(032), "Hello There", Color.white, text);
}

See Also

RB.Print
RB.PrintMeasure
SpriteSheetAsset

See Docs

Features - Fonts