Skip to content
Matthew LaRocca edited this page Dec 4, 2021 · 3 revisions

Font Assets allow you to write dynamic text strings. Two types of fonts are supported file and image based fonts.

File based fonts

Font assets can be created by from .ttf or .otf fonts. In order to save resources, a reduced number of glyphs may be created from a source string. If no source string is provided, a standard set of glyphs will be used

When specifying a file based font in the asset manifest the following properties are supported:

Property Required Description
src yes specifies the path to the source font file
size yes the font size
name yes a name to use in the asset definition
sourceString no a string containing the glyphs to encode in the font. If unspecified a default selection of characters will be used.

An example of converting a font:

{
    "src": "Consolas.ttf",
    "size": 12,
    "name": "Consolas12"
},

Image based fonts

Fonts can also be created by specifying an image (or frames to be assembled into an atlas). Currently, when using this option, the font is assumed to be a monospaced font in which the advance width is the width of each tile.

When specifying an image based font in the asset manifest the following properties are supported:

Property Required Description
image yes specifies the image to be converted and used to draw the font glyphs. Note this field can have any fields supported by the Image Asset specification.
name yes a name to use in the asset definition
sourceString yes a string containing the glyphs to encode in the font. It is important to note that the number of characters in this string must match the number of frames in the source image. Additionally, the order of the characters in the string should correspond to the frame numbers in the image.

An example of converting an image based font:

{
    "image": {
        "frameDir": "image_font",
        "hslices": 10,
        "vslices": 4,
        "frameSize": "16x16",
        "name": "Mario64FontImage"
    },
    "name": "Mario64",
    "sourceString": " \"'0123456789?abcdefghijklmnopqrstuvwxyz"
}

An example of converting an image based font from a specific set of tiles:

{
    "image": {
        "name": "title_font_image",
        "frames": [
            "fire_font/let_sp.png",
            "fire_font/let_c.png",
            "fire_font/let_e.png",
            "fire_font/let_i.png",
            "fire_font/let_l.png",
            "fire_font/let_n.png",
            "fire_font/let_r.png",
            "fire_font/let_s.png",
            "fire_font/let_t.png"
        ],
        "frameSize": "32x32",
        "hslices": 3,
        "vslices": 3
    },
    "name": "title_font",
    "sourceString": " ceilnrst"
}
Clone this wiki locally