Help with .ttf font

Hi,

I have problems loading files .ttf or .otf. I cant found a example to create a label with a external font. Can somebody give me a good code example to do this ?

Thanks.

I’m currently using a .ttf font in my menus. Here’s what I have done.

I pull in the font using font-face from the header of my doc, then use the following code:

cc.MenuItemFont.setFontName('Press Start 2P');
cc.MenuItemFont.setFontSize(14);
var menuItem1 = new cc.MenuItemFont.create("Home", MyFirstApp, 'loadScene');

menuItem1.setPosition(cc.ccp(s.width-50, s.height-20));

var menu = cc.Menu.create(menuItem1);
    menu.setPosition(cc.ccp(0,0));

layer1.addChild(menu);
this.addChild(layer1);

It’s not a label, but I’m sure the same concept applies. Hope this helps a little.

Jon Cazier wrote:

I’m currently using a .ttf font in my menus. Here’s what I have done.
>
I pull in the font using font-face from the header of my doc, then use the following code:
>
>
[…]
>
It’s not a label, but I’m sure the same concept applies. Hope this helps a little.

Hi Jon, thanks for the info. How you load the .ttf font ? I’m using some like this:

assetToLoad = [{type:"image", src:"Resources/background.png"},
@ {type:“image”, src:“Resources/CloseNormal.png”},@
@ {type:“image”, src:“Resources/CloseSelected.png”},@
@ {type:“fnt”, src:“Resources/fonts/ALoveofThunder.ttf”}];@
cc.Loader.shareLoader().preload(assetToLoad);

// Create and initialize a score label
this.scoreLabel = cc.LabelTTF.labelWithString("0", 100, cc.TextAlignmentLeft, "Resources/fonts/ALoveofThunder.ttf", 10); // or "ALoveofThunder"
this.scoreLabel.setPosition(SCORE_POSITIONS[panelNumber-1]);
this.view.addChild(this.scoreLabel, 5);

But always show Arial. I need define the font in other place ?

Thanks !

I’m very much a noob here, so I hope I’m not giving bad advice.

The one other thing that I did was pull the font into the document with `font-face


     `font-face {
 font-family: ‘Press Start 2P’;
 src: url(Assets/Fonts/PressStart2P-Regular.ttf);
 font-weight:400;
 }


Jon Cazier wrote:

I’m very much a noob here, so I hope I’m not giving bad advice.
>
The one other thing that I did was pull the font into the document with @font-face
>
[…]

Thanks a lot Jon. I forget do this. That was the problem !