4

Apparently is is possible to use Cocos2d-js 3.0 RC3 cc.LabelTTF with custom fonts, for example as answered here. However this doesn't seem to produce any results for me, neither in the local JSBinding app nor in the web browser.

Font file was included in the res object:

var res = {
    lobster_ttf: "res/Lobster.ttf"
};

var g_resources = [];
for (var i in res) {
    g_resources.push(res[i]);
}

Lobster.ttf does exist in the directory res.

The label is instantiated as follows:

var label = new cc.LabelTTF("labeltext", res.lobster_ttf, 48);

Doing this will not display the label in the specified font but in the default font. Specifying an installed font instead of the path to the custom ttf does however work.

Is there extra work required to be able to use TTF files?

Community
  • 1
  • 1
Appleshell
  • 7,088
  • 6
  • 47
  • 96
  • Are you sure the path is right and the ttf-file is valid? In my project this commands loads the ttf font in WEB, Android and iOS: var label = cc.LabelTTF.create("text", "res/fonts/American Typewriter.ttf", 160); – Michael Aug 31 '14 at 10:39

1 Answers1

2

cocos2d-js v3.0 rc3 Mine worked using the font name (font name when installing the font, not the file name font)

sample: var label = new cc.LabelTTF("labeltext", "Lobster", 48);

Give it a try..

Tim