Cocos2d-js: How to use a custom ttf font on android devices?

前端 未结 2 1502
醉话见心
醉话见心 2021-01-19 00:52

I use following code to display a custom ttf font:

ml.score = cc.LabelTTF.create(ml.totalPoints.toString(), \"fonts/American Typewriter.ttf\", 60);
ml.score.         


        
相关标签:
2条回答
  • 2021-01-19 01:47

    Michael's answer works on my Android, but does not work in my browser.

    I could not find a multi-purpose method, but adding this in the head of index.html worked for my browser:

    <style>
    @font-face {
        font-family: 'Lobster';
        font-style: normal;
        font-weight: 400;
        src: local('Lobster'), url(res/Lobster.ttf) format('woff');
    }
    </style>
    

    with this in your js:

    var titleLabel = new cc.LabelTTF("Hello World", "Lobster", 72);
    

    Since this method only works in my browser, and the other method only works on my phone, I might need to come up with a toggle.

    0 讨论(0)
  • 2021-01-19 01:50

    I made a mistake. The file name was wrong. It should be

    ml.score = cc.LabelTTF.create(ml.totalPoints.toString(), "res/fonts/American Typewriter.ttf", 60);
    

    Otherwise the code works fine. (shame ...)

    0 讨论(0)
提交回复
热议问题