2

I am trying to use custom font in Cocos2d-Android with CClabel, I have added my font file into the assets and trying to use it by name "Faraco_Hand.ttf" and "Faraco_Hand" but its not working, I have googled around but haven't found any solution. this is how my code looks a like:

currentVideoLabel = CCLabel.makeLabel(VideosLabels[currentSelected], "Faraco_Hand.ttf", winSize.width/41);
        currentVideoLabel.setPosition(CGPoint.make(winSize.width/2, 20));
        addChild(currentVideoLabel);

If someone know this please help me.

Omer Abbas
  • 39
  • 1
  • 7
  • 1
    Cocos2d-android don´t have support anymore. You must use cocos2d-x, cross-plataform, use JNI to use c++ code. More info [HERE](http://stackoverflow.com/q/10711047/1077364). The problem you are asking is solve in a test inside cocos2d-x, take a look. – vgonisanz Jun 10 '12 at 08:32

4 Answers4

4

Hi i use this way to add font in my game here i am sharing you my code check it hope it's helpful for you here i am setting my font on label this is the only way to set fonts...all the best

Example:1

 CCLabel labelcontinue = CCLabel.makeLabel("continue", "fonts/JimboStd-Black.otf", 14);
                labelcontinue.setPosition(CGPoint.ccp(272, 95));
                labelcontinue.setColor(ccColor3B.ccc3(165, 42, 42));
                mainPaperNode.addChild(labelcontinue, 25);

Example2:

  CCLabel labelWelcome = CCLabel.makeLabel("Welcome", "fonts/JimboStdBlack.otf",20);
        labelWelcome.setColor(ccColor3B.ccc3(139, 69, 19));
        labelWelcome.setPosition(CGPoint.ccp(innerArea.getContentSize().getWidth() / 2, (innerArea.getContentSize().getHeight() / 2) + 138));
        innerArea.addChild(labelWelcome);
  • Why what is the problem....?facing any error during using this code..? i am using this in my game and its working fine.. –  Jul 26 '12 at 12:35
  • Priyank.. no its not making any change in my font. I want to use comic sans font. – Dhrupal Jul 27 '12 at 05:11
  • You have to use .otf file for using font like this way is is Comicsans.otf format..?then it should work –  Jul 27 '12 at 05:28
  • I was using .ttf but now i have tried with comic.otf. but still if doesn't make change.I have converted .ttf to .otf – Dhrupal Jul 27 '12 at 05:46
  • see this link. i need the help from cocos2d-android persons : http://stackoverflow.com/questions/17971120/can-we-use-googleads-admob-adwhirl-in-cocos2d-android – Akarsh M Aug 01 '13 at 08:55
  • OTF fonts are not supported in Android, you can only use TTF fonts. – Florian Nov 04 '13 at 07:21
1

i know this is late reply, anyhow it may help someone who search this same thing... CCLabel supports external fonts but some of the ttf will not recognized by android so it will through exception so better you try another font instead of this the code is same...

  label = CCLabel.makeLabel("label value", "external_font_name.ttf", 30);
  label.setPosition(CGPoint.make(winSize.width/2, 20));
  addChild(label);
kalandar
  • 793
  • 6
  • 13
  • see this link. i need the help from cocos2d-android persons : http://stackoverflow.com/questions/17971120/can-we-use-googleads-admob-adwhirl-in-cocos2d-android – Akarsh M Aug 01 '13 at 08:56
1

I don't think there's any problem with your method. I guess the problem is you are renaming the original font file. Rename the font file name with its original name (written in the font file itself, check attached image).

enter image description here

in this case, I kept my ttf file in Resources/fonts folder and wrote my code like:

CCLabelTTF* label = CCLabelTTF::create("Hello World", "fonts/A Damn Mess.ttf", 20);

Also check CCLabelTTF instead of CCLabel.

Hope this will help you.

Ankur
  • 1,268
  • 18
  • 22
  • see this link. i need the help from cocos2d-android persons : http://stackoverflow.com/questions/17971120/can-we-use-googleads-admob-adwhirl-in-cocos2d-android – Akarsh M Aug 01 '13 at 08:56
0

Hai this will help. This code works for me fine. Put custom font int assets->fonts

CCLabel label1 = CCLabel.makeLabel("Points: 0", "fonts/pin.ttf", 28);
    label1.setColor(ccColor3B.ccWHITE);
    label1.setPosition(280f * scaleX, 550f * scaleY);
    addChild(label1);
Bebin T.N
  • 2,539
  • 1
  • 24
  • 28