You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a FairyGUI project that uses a font (Changa One). I have it in both .ttf and .woff formats.
When I publish to Laya, the font isn't published with it and so the layabox project doesn't contain the font and fallsback to system default on other devices.
I tried dynamically importing the font in Laya, but it did not work :/
asyncfunctionloadFont(name,url){returnnewPromise((resolve,reject)=>{varfont=new(selfasany).FontFace(name,`url(${url})`);font.load().then(function(loaded_face){(documentasany).fonts.ready.fonts.add(loaded_face);document.body.style.fontFamily=`"${name}, Arial`;console.log(`Font ${name} has been loaded`);resolve()}).catch(function(error){console.error(error);reject();});});}loadFont("Changa One","fonts/Changa-Bold.woff").then(()=>{newMain();});
Any idea of how to make this work? I'm kinda lost and all the (accurate and detailed) documentation for laya is in chinese, and I can't make an account on the laya forum because wechat won't let me.
The text was updated successfully, but these errors were encountered:
Thanks for the answer :)
I also realised why my code did not work: the Typescript compiler failed to parse the async keyword and Layabox never told me!
in the end, I have this piece of code that seems to work, in case anyone else might need it
functionloadFont(name,url,isBold,isItalic){returnnewPromise((resolve,reject)=>{letdescriptors:any={family: name}if(isBold)descriptors.weight="bold"if(isItalic)descriptors.style="italic"varfont=new(selfasany).FontFace(name,`url(${url})`,descriptors);font.load().then(function(loaded_face){(documentasany).fonts.add(loaded_face);console.log(`Font ${name} has been loaded (${url})`);resolve()}).catch(function(error){console.error(error);// This means the game will never run if one of the fonts fail to load.// Alternatively, resolve anyway to keep the game running in case of failure.// You can also use Promise.allSettled, but at the moment it is not supported in every browsersreject();});});}Promise.all([loadFont("Changa One","fonts/Changa-Regular.woff2",false,false),loadFont("Changa One","fonts/Changa-Italic.woff2",false,true),loadFont("Changa One","fonts/Changa-Bold.woff2",true,false)]).then(()=>{newMain();});
I have a FairyGUI project that uses a font (Changa One). I have it in both .ttf and .woff formats.
When I publish to Laya, the font isn't published with it and so the layabox project doesn't contain the font and fallsback to system default on other devices.
I tried dynamically importing the font in Laya, but it did not work :/
Any idea of how to make this work? I'm kinda lost and all the (accurate and detailed) documentation for laya is in chinese, and I can't make an account on the laya forum because wechat won't let me.
The text was updated successfully, but these errors were encountered: