Font support
In this blog entry we would talk about fonts.
Fonts are now supported and are used in the main menu screen (the copyright text). The fonts in JA2 are stored in the .sti files (as sub-images), along with shadow support and palettes. Each font letter image therefor has the main color letter and shadow letter (encoded differently). In the Ja2Unity those image are imported as separate color channels: R is for the main color, B is for the shadow color and in the G channel, the background color is stored, but I don't know if it is used anywhere in the original game. Each font asset (AssetJa2Font class - which is the main asset) therefor has those sub-assets:
- Texture atlas with all the supported letters (it's just the tiny subset of the UNICODE)
- Palette used for font coloring (as Texture2DArray assigned to the font material)
- Font asset (TMP_FontAsset)
- Font material asset with custom shader assigned
![]() |
| Font asset |
Because TMP_FontAsset isn't used directly, the new UI.TextWithShadow class was created, which extends the TMPro.TextMeshProUGUI. This has two practical reasons:
- Because no TMP_FontAsset is used directly, the component needs to be able to store the AssetJa2Font asset instead, from which font asset will be read and also to be able to specify the shadow color (which is now set in the component) but was missing in the original TMPro.TextMeshProUGUI class (for obvious reasons).
- To add support for asset ref mocker (AssetRefMockerText).
![]() |
| TextWithShadow and AssetRefMockerText components |
For font rendering, the custom shader (Ja2/FontShadow) is used, which either renders the text with shadow or without it. The main color and shadow color are set on the cloned material, when the asset ref is loaded. For now, dynamic changes of the colors during the gameplay isn't supported (yet?).
I've just realized, that I didn't mentioned the link to the repository so far. So, here it is: https://github.com/Trigve/Ja2xUnity
I've also updated the README.md there with instruction for how to build the asset bundles. Also, there is a player build (for Windows) which could be used for testing (but its lifetime will be very limited as this project is "action in progress" so the newest asset bundles may not work with the older player). Only main menu is shown and nothing could be done, but it is proof of the concept that the way I choose is working.



Comments