This project is read-only.

Issue loading font

Topics: Android
Mar 20, 2014 at 3:54 PM
I have a custom font I'm trying to use in my android port for my game. The font is located under the Resources/fonts. The font is set with a build action of "AndroidAsset" and I create the label doing the following:

scoreLabel = new CCLabelTTF (Score.ToString (), "Resources/fonts/mycustomfont.ttf", 60f) {
            Position = scorePosition,
            Color = new CCColor3B (XNA.Color.Black)
        };
I get the below error during runtime:
Can't find mycustomfont.ttf, use system default (arial)

In iOS, I had to add the font in info.plist file to get this to work, but I'm not sure if there are any other steps needed for Android.
Mar 20, 2014 at 6:37 PM
You have to use the new CCLabel class, not CCLabelTTF. The Labelttf class is reserved for spritefont encoded fonts. The 'ttf' is just a misnomer in this case.

new CCLabel() .... that's what you want to use.
Mar 20, 2014 at 7:22 PM
When I use CCLabel I dont get an error but my font does not get displayed, it seems like its using a default font.

The font is located under Resources/fonts/ and its set to be an AndroidAssest (Copy to Output Directory). Isn't there somewhere else I would need to define this font, like the Info.plist file for iOS?
Mar 20, 2014 at 7:45 PM
the ttf file goes into your content directory same as your images and other game assets.

Resources is for android-managed stuff, which is not used by the framework.
Apr 30, 2014 at 12:23 PM
Is the CCLabel purposely left out of wp7 version ? when i try to use it i get errors and have to revert to CCLabelTTF.
Apr 30, 2014 at 5:15 PM
Yes, we did not have a library for reading the TTF file on WP7.
Jun 21, 2014 at 9:18 AM
for android, i put my ttf font in "Assets/Content/fonts/name.ttf". so it will work correctly with CCLabel : new CCLabel( "string", "fonts/name.ttf", 22)