How to use a local font in Phaser 3?

点点圈 提交于 2019-12-10 16:47:20

问题


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.


回答1:


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>

And then use a div to load your font:

<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',
});


来源:https://stackoverflow.com/questions/51217147/how-to-use-a-local-font-in-phaser-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!