CCFontManager
CCFontManager
Cocos2DManages font registration and provides utilities for working with fonts across the framework. Supports both content pipeline fonts (.xnb via SpriteFont) and direct TTF file loading (bypasses the content pipeline). For direct TTF loading (no content pipeline required), use CCLabel: var label = new CCLabel("Hello", "fonts/myfont.ttf", 24); For content pipeline fonts, use CCLabelTTF: var label = new CCLabelTTF("Hello", "arial", 24); If the content pipeline fails for certain fonts (e.g. MonoGame's FontDescriptionProcessor rejects the font), switch to CCLabel with a .ttf file path instead.
Inheritance: System.Object
Properties
Returns a copy of all registered TTF font paths.
Methods
Clear()
Clear()()Clears all registered fonts.
Example
CreateLabel(string, string, float)
Cocos2D.CCNode CreateLabel(string, string, float)(System.String text, System.String fontName, System.Single fontSize)Creates the appropriate label type for a given font. If the font name ends with .ttf, creates a CCLabel (native TTF rendering, bypasses the content pipeline). Otherwise, creates a CCLabelTTF (content pipeline SpriteFont rendering).
Parameters:
text (System.String) - Text to display.fontName (System.String) - Font name or TTF path (e.g. "arial" or "fonts/myfont.ttf").fontSize (System.Single) - Font size in points.Returns:
Cocos2D.CCNode - A CCNode that displays the text (either CCLabel or CCLabelTTF).Example
CreateLabel(string, string, float, CCSize, CCTextAlignment, CCVerticalTextAlignment)
Cocos2D.CCNode CreateLabel(string, string, float, CCSize, CCTextAlignment, CCVerticalTextAlignment)(System.String text, System.String fontName, System.Single fontSize, Cocos2D.CCSize dimensions, Cocos2D.CCTextAlignment hAlignment, Cocos2D.CCVerticalTextAlignment vAlignment)Creates the appropriate label type with alignment support. If the font name ends with .ttf, creates a CCLabel. Otherwise, creates a CCLabelTTF.
Parameters:
text (System.String)fontName (System.String)fontSize (System.Single)dimensions (Cocos2D.CCSize)hAlignment (Cocos2D.CCTextAlignment)vAlignment (Cocos2D.CCVerticalTextAlignment)Returns:
Cocos2D.CCNodeExample
IsTTFFont(string)
System.Boolean IsTTFFont(string)(System.String fontName)Checks whether a font name refers to a TTF file (ends with .ttf extension).
Parameters:
fontName (System.String)Returns:
System.BooleanExample
IsTTFRegistered(string)
System.Boolean IsTTFRegistered(string)(System.String relativePath)Checks whether a TTF font has been registered.
Parameters:
relativePath (System.String)Returns:
System.BooleanExample
RegisterTTF(string)
System.Boolean RegisterTTF(string)(System.String relativePath)Registers a TTF font file path for use with CCLabel. The path must be relative to the content root (e.g. "fonts/myfont.ttf"). Rooted paths and directory traversal (e.g. "..") are rejected. The TTF file must exist in your content directory.
Parameters:
relativePath (System.String) - Path relative to content root, e.g. "fonts/myfont.ttf".Returns:
System.Boolean - True if the font file exists and was registered.Example
ResolveFontPath(string)
System.String ResolveFontPath(string)(System.String relativePath)Resolves a content-relative font path to a full filesystem path. Rejects rooted paths and directory traversal. Returns null if the content manager is not initialized or the path is invalid.
Parameters:
relativePath (System.String)Returns:
System.StringExample