如何在Phaser 3中使用本地字体? [英] How to use a local font in Phaser 3?
本文介绍了如何在Phaser 3中使用本地字体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在fonts/
目录中有一种字体.如何将其加载到游戏中,然后在游戏中的文本对象上使用它?在Phaser 3中,我找不到使用字体的任何东西.
I have a font in a fonts/
directory. How do I load this into the game, then use it on a text object in my game? I haven't been able to find anything on using fonts in Phaser 3.
推荐答案
首先使用css加载字体(@fontface):
First use css to load your font(@fontface):
<style media='screen' type='text/css'>
@font-face {
font-family: font1;
src: url('media/yourfont.ttf');
font-weight:400;
font-weight:normal;
}
</style>
然后使用div
加载字体:
<div style="font-family:font1; position:absolute; left:-1000px; visibility:hidden;">.</div>
现在您可以将其添加到游戏中:
Now you can put it in add it in your game:
this.add.text(190, 136, 'text', {
fontFamily: 'font1',
});
这篇关于如何在Phaser 3中使用本地字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文