Using TrueType Fonts in CocosSharp RRS feed

  • Question

  • User4641 posted

    I'm looking to use a free TrueType font that I downloaded from FontSquirrel in my game (Android & Windows platforms) but I'm having a little difficulty understanding the proper way to get it loaded into CocosSharp.

    According to the article here (https://github.com/mono/CocosSharp/wiki/Labels), it indicates that CCLabel can use TTF font if included with the application. Also, I've looked at the tests project for CocosSharp, specifically the SystemFontTest class and content folders and tried some tests of my own with CCLabel and my font, but I keep getting the "stock" font for the label, which seems to indicate the font didn't load and I'm doing something wrong. I'm currently testing on Android using the Xamarin Android Player.

    My questions are the following: * What's the correct way to include a TrueType font with the CocosSharp application (per the Labels article above)? * Do I need to have a spritefont that refers to the TrueType font as well? The Labels article seemed to indicate spritefonts (using CCLabelTtf) and TTF (using CCLabel) were separate. * Do I need to load the TrueType font specially in my code or is it enough to include it in the fonts directory of my Content folder and CocosSharp does the rest? I didn't see any special loading code in the SystemFontTest class, so I'm assuming CocosSharp will do the heavy lifting.

    Any help would be appreciated. :) Thanks.

    Saturday, February 21, 2015 10:16 PM

All replies

  • User103733 posted

    Take a look at this link.

    Sunday, February 22, 2015 4:25 AM
  • User4641 posted

    @CharlieKilian - thanks for the link. I had actually already read through that post, but it didn't really answer my questions and actually was one of the reasons I created my post here. That talked about creating spritefont XNB resources, which I knew about. But the Labels post I listed above seems to indicate you could use a TrueType font in your project without making a spritefont by using a CCLabel object, with the advantage being on-the-fly scaling of the font as opposed to a fixed font size with a spritefont (several for any different sizes you want) & CCLabelTtf. I'm curious about the mechanics behind adding each to a project as it doesn't seem clear to me what the distinction is. :)

    Sunday, February 22, 2015 6:11 PM
  • User68494 posted


    Take a look at the SystemFontTest.cs.

    Add the .ttf to the Content directory and make sure you mark it as Content

    I would go with CCLabelBMFont or spritefont if you are targeting WP8 as the WP8 does not support .ttf. They are truthfully faster in my opinion even though the CCLabel and .ttf is easier and also has the drawback of no support for WP8.

    Monday, February 23, 2015 1:35 PM
  • User4641 posted

    @kjpou1 - Thanks for the reply. I tried your suggestion and couldn't get it to work as you specified (marked as Content). However, I was able to get it to work with it placed in my Content directory marked as an AndroidAsset (I'm working on my Android project at the moment), so I'm happy with it at the moment. I'll keep your suggestion on the Bitmap/spritefont in mind if I target WP8.

    I have another question after getting this to work. I wanted to put the font in my Content/fonts directory of the project but couldn't get it to work unless I prefixed the fonts directory to the name as shown below:

    var label = new CCLabel("Welcome to My Game!", "fonts/CrimsonText-Bold.ttf", 72);

    I tried adding the fonts directory as a content search path in my AppDelegate but that didn't seem to help:


    Any thoughts? Thanks for the help, I've at least got a working font now. :smiley:

    Friday, February 27, 2015 2:29 AM
  • User68494 posted

    Hey Rick

    Glad you got it working. Android is different and of course needs to be marked as AndroidAsset. All the other platforms use Content so went with that.

    There is already an issue created for what you are describing and we will be addressing it in the near future. Just for a little background, it was easier to keep .ttf files in the Content directory with full path specified because of the way each platform loads them. We are hoping to be able to get around this next time.

    Friday, February 27, 2015 5:33 AM
  • User4641 posted

    Okay, thanks for the help. I appreciate it.

    Friday, February 27, 2015 12:25 PM