CCPixelLabel
CCPixelLabel
Cocos2DA label optimized for frequent text updates. Pre-caches individual character textures at construction time, then repositions sprites on text changes — no texture regeneration. Ideal for scores, timers, health counters, and other HUD elements that change every frame.
Inheritance: System.Object → Cocos2D.CCNode
Implements: Cocos2D.ICCSelectorProtocol, Cocos2D.ICCFocusable, Cocos2D.ICCTargetedTouchDelegate, Cocos2D.ICCStandardTouchDelegate, Cocos2D.ICCTouchDelegate, Cocos2D.ICCKeypadDelegate, Cocos2D.ICCKeyboardDelegate, Cocos2D.ICCRGBAProtocol, System.Collections.Generic.IComparer{Cocos2D.CCNode}
Constructors
CCPixelLabel(string, string, float)
CCPixelLabel(string, string, float)(System.String text, System.String fontName, System.Single fontSize)Creates a new CCPixelLabel with default settings.
Parameters:
text (System.String) - Initial text to display.fontName (System.String) - System font name.fontSize (System.Single) - Font size in points.Example
CCPixelLabel(string, string, float, CCTextAlignment, bool, int)
CCPixelLabel(string, string, float, CCTextAlignment, bool, int)(System.String text, System.String fontName, System.Single fontSize, Cocos2D.CCTextAlignment alignment, System.Boolean antialiased, System.Int32 maxChars)Creates a new CCPixelLabel.
Parameters:
text (System.String) - Initial text to display.fontName (System.String) - System font name (e.g. "arial").fontSize (System.Single) - Font size in points.alignment (Cocos2D.CCTextAlignment) - Text alignment.antialiased (System.Boolean) - Whether to use antialiased filtering.maxChars (System.Int32) - Maximum number of visible characters. Pre-allocates this many sprites.Example
Properties
Gets or sets text alignment (Left, Center, Right).
Gets the measured height of a single character in this font.
Gets or sets the color applied to all glyph sprites.
Gets the font name used by this label.
Gets the font size used by this label.
Gets or sets whether glyph sprites use antialiased (linear) filtering. When false, uses point filtering for pixel-perfect rendering.
Gets or sets the opacity applied to all glyph sprites.
Gets or sets the displayed text. Changing this repositions existing glyph sprites without regenerating any textures.
Methods
CacheCharacters(string)
CacheCharacters(string)(System.String characters)Pre-caches additional characters beyond the default character set. Call this once at startup if your text will include characters not in the default set (e.g. Unicode or special symbols).
Parameters:
characters (System.String)Example
MeasureString(string)
System.Single MeasureString(string)(System.String text)Measures the width of a string in points without rendering it.
Parameters:
text (System.String)Returns:
System.SingleExample
PurgeCachedData()
PurgeCachedData()()Clears all static font caches and disposes cached textures. Call this when changing scenes or when you need to free memory from fonts that are no longer used.
Example
SetMaxChars(int)
SetMaxChars(int)(System.Int32 maxChars)Grows the glyph sprite pool if the current maxChars is insufficient.
Parameters:
maxChars (System.Int32)Example