-
-
Notifications
You must be signed in to change notification settings - Fork 168
Fonts in Kha
To use an external font in Kha you first need to load the font in question, like any other asset. Then after loading it you will be able to access it by calling Assets.fonts.myfontname
considering that the name of your font is myfontname.ttf
.
You will need to place the font file in the Assets folder and then load it in the project by doing this:
class Main {
import kha.System;
import kha.Window;
import kha.Assets;
import kha.Font;
public static function main():Void {
System.init(
{title: "Project", width: 1024, height: 768},
function (window:Window) {
Assets.loadFont("Aclonica_Regular", whenImDone);
}
);
}
public static function whenImDone(f:Font):Void {
new Project();
}
}
The reason of loading at the start of the project is that you will probably need to access the font in your project and if you call the load just before the new of your project, you will encounter an error since the asset loading and the new calls are concurrent calls. The whenImDone
function here solves the issue, and calls the start of the Project when the font is finished loading so you can use the font without faults in that project.
In Kha there is another way of loading assets in general. Basically you can do Assets.loadEverything(whenImDone)
which is a valid solution when you have all your assets in the Assets
folder but it is not advised to use this method with projects with a lot of assets since that can fill your RAM up.
- Introduction
- Getting Started
- Breaking Changes
- FAQ
- System targets
- Graphics targets
- Documentation
- API package descriptions