Module bank_fonts
Loads and caches bitmap fonts for the Micro2D engine.
Each font consists of a Lua data file and a PNG image sheet.
You can use my own tool called BMFont2Lua to convert your own BMFonts JSON files to Lua table.
Info:
- Author: Sharper Dev
Functions
| FontsBank.loadFont (id, fontPath) | Loads a font from the given path and associates it with the given ID. |
| FontsBank.unloadFont (id) | Frees the image sheet and removes the font associated with the ID. |
| FontsBank.getFont (id) | Returns the cached font entry for the ID, or nil if it is not loaded. |
Functions
- FontsBank.loadFont (id, fontPath)
-
Loads a font from the given path and associates it with the given ID.
The font is stored in memory and can be retrieved using
FontsBank.getFont(id).Parameters:
- id string The ID to associate the font with.
- fontPath
string The path to the font files. The font name should be the last part of the path, and the files should be named
<fontName>.luaand<fontName>.png.
Returns:
-
table The loaded font data.
Usage:
local myFont = FontsBank.loadFont("myFont", "romfs/micro2d/fonts/myFont")
- FontsBank.unloadFont (id)
-
Frees the image sheet and removes the font associated with the ID.
Parameters:
- id string ID of the font to unload.
Usage:
FontsBank.unloadFont("myFont")
- FontsBank.getFont (id)
-
Returns the cached font entry for the ID, or
nilif it is not loaded.Parameters:
- id string ID of the font to retrieve.
Returns:
-
table|nil Font entry containing
dataandsheet.Usage:
local myFont = FontsBank.getFont("myFont")