Cocos2d, Programming

Using External Fonts with Cocos2d for Mac

This post is mainly for reference so that I don’t forget how to do this but I thought that maybe this would help out some of you as well.

So basically this applies to anyone who is wanting to use a font that is not part of the Mac OS X system fonts within your Mac game using Cocos2D.

For this tutorial, I’ve created a new project named Demo and have chosen the default Cocos2D Mac Template

If you’ll click on the HelloWorldLayer.m file, and review the init method. We will be changing the default font from Marker Felt to our own custom font that we will download.

To use a custom font here is what you’ll have to do:

  • Click on your project and then click on your project target and then click on Build Phases
  • At the bottom, find the Add Build Phase Button, click it and then click on Add Copy Files
  • Click on the disclosure triangle to expose Copy Files
  • Destination should be Resources and Subpath should be Fonts
  • If you haven’t done so yet, please go ahead and download a font. I will be using Led 8×6 
  • When your download has completed, drag the font file into the Add files here box within the Copy Files Build Phase. Keep the defaults and click Finish
  • You should have something similar to the below screen shot



You then need to add the ATSApplicationFontsPath key to your Info.plist file, with the name of the folder containing your font as its value:

Now we are all set to begin using our custom font within our project. Let’s go ahead and click back over to the HelloWorldLayer.m file.

  1. Within the init method replace @”Marker Felt” with @”Led 8×6″

Notice that we are not using the name of the file which is led_8x6.ttf but instead we are using the actual font name. The way you would go about knowing what the name of the font is, would be to double-click on the file and let it install, then look for it in Font Book.

Finally lets run the project. You should see your custom font now.


The following two tabs change content below.
I've been in the Geek category for as long as I can remember. I am into anything technology and Sci-Fi related. I like tinkering with electronics as well as writing applications for Mac & iPhone.

Leave a Reply