Using custom fonts in Cocos2d

How do I use custom TTF fonts in my Cocos2d iPhone apps?


I searched for this for a while and decided to post as question and answer for people wanting to implement.

The solution is quite easy.

  1. Find the fonts you want and download them. This website has a huge collection of free fonts.

  2. Add the font files to your project.

  3. Add the font names to your info.plist file using the array below as an example.

  4. Find the font's name; Double click the font file and use the font name shown in the title of the window. In this example it is "Action Man"

To use the font name the way you would normally:

CCLabel* myLabel = [CCLabel labelWithString:@"Some Text" fontName:@"Action Man" fontSize:18];

Add this to your info.plist file:

    <string>Action Man Bold.ttf</string>

In Cocos2D, you can include the font file with your resources and then in fontName: simply supply the filename. For example:

CCLabelTTF *label = [CCLabelTTF labelWithString:@"whatever" fontName:@"FONTNAME.ttf" fontSize:18];

This is often easier than the method Hanaan has posted.

You should use the exact same file name capitalisation as the filename.

You do not need to add fonts to your info.plist if you are only using it in Cocos2D bits.

If, like Confused, you find that the font works on the simulator but not the device, it is probably a file name capitalisation mistake. The iPhone is case-sensitive, the simulator is not.

As these answers are outdated, I'm sure my question/ answer will help all those out there.

Importing fonts for cocos2dx iOS

this is for iOS and Android platform font importing, with just a single line of code!

Need Your Help

Is Laravel right choice for my project or some other is better

php entity-framework cron laravel-4

We are planing to make a new system to replace our 10 year old system, in doing so we are considering to make the new system in Laravel. Now I have concerns I will have to hack the whole thing and ...

Validate an IP Address (with Mask)

java grails groovy

I have ip addresses and a mask such as I would like to check if is inside that range. Is there a library or utility that would do this or do I need to write something myself?