您可以设置一下启动脚本,在启动脚本中加载字体资源,加载完成后打开需要的场景,在场景中通过getRes方法来获得这个资源
设置启动脚本的位置为:项目设置-脚本编译-启动脚本
启动脚本代码:
export async function main() {
console.log("Hello LayaAir!");
Laya.loader.load("resources/BitmapFont.fnt", Laya.Loader.FONT).then((res) => {
Laya.Scene.open(Laya.PlayerConfig.startupScene); //可以设置场景路径
})
}
场景中加载字体代码:
onAwake(): void {
let fnt = Laya.loader.getRes("resources/BitmapFont.fnt", Laya.Loader.FONT);
console.log(fnt);
}