Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 8ff70902d0
Fetching contributors…

Cannot retrieve contributors at this time

147 lines (121 sloc) 4.103 kB
/* cocos2d for iPhone
* Copyright (C) 2008,2009 Ricardo Quesada
* This program is free software; you can redistribute it and/or modify
* it under the terms of the 'cocos2d for iPhone' license.
* You will find a copy of this license within the cocos2d for iPhone
* distribution inside the "LICENSE" file.
* Portions of this code are based and inspired on:
* by Michael Daley
#import "CCAtlasNode.h"
#import "CCSpriteSheet.h"
#import "Support/ccHashSet.h"
/** bitmap font definition */
typedef struct _bitmapFontDef {
//! ID of the character
unsigned int charID;
//! origin and size of the font
CGRect rect;
//! The X amount the image should be offset when drawing the image (in pixels)
int xOffset;
//! The Y amount the image should be offset when drawing the image (in pixels)
int yOffset;
//! The amount to move the current position after drawing the character (in pixels)
int xAdvance;
} ccBitmapFontDef;
/** bitmap font padding
@since v0.8.2
typedef struct _bitmapFontPadding {
/// padding left
int left;
/// padding top
int top;
/// padding right
int right;
/// padding bottom
int bottom;
} ccBitmapFontPadding;
enum {
// how many characters are supported
kBitmapFontAtlasMaxChars = 2048, //256,
/** CCBitmapFontConfiguration has parsed configuration of the the .fnt file
@since v0.8
@interface CCBitmapFontConfiguration : NSObject
// XXX: Creating a public interface so that the bitmapFontArray[] is accesible
// The characters building up the font
ccBitmapFontDef bitmapFontArray[kBitmapFontAtlasMaxChars];
// FNTConfig: Common Height
NSUInteger commonHeight;
// Padding
ccBitmapFontPadding padding;
// values for kerning
ccHashSet *kerningDictionary;
/** allocates a CCBitmapFontConfiguration with a FNT file */
+(id) configurationWithFNTFile:(NSString*)FNTfile;
/** initializes a BitmapFontConfiguration with a FNT file */
-(id) initWithFNTfile:(NSString*)FNTfile;
/** CCBitmapFontAtlas is a subclass of CCSpriteSheet.
- Treats each character like a CCSprite. This means that each individual character can be:
- rotated
- scaled
- translated
- tinted
- chage the opacity
- It can be used as part of a menu item.
- anchorPoint can be used to align the "label"
- Supports AngelCode text format
- All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
because it might affect the rendering
CCBitmapFontAtlas implements the protocol CCLabelProtocol, like CCLabel and CCLabelAtlas.
CCBitmapFontAtlas has the flexibility of CCLabel, the speed of CCLabelAtlas and all the features of CCSprite.
If in doubt, use CCBitmapFontAtlas instead of CCLabelAtlas / CCLabel.
Supported editors:
@since v0.8
@interface CCBitmapFontAtlas : CCSpriteSheet <CCLabelProtocol, CCRGBAProtocol>
// string to render
NSString *string_;
CCBitmapFontConfiguration *configuration;
// texture RGBA
GLubyte opacity_;
ccColor3B color_;
BOOL opacityModifyRGB_;
/** conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) GLubyte opacity;
/** conforms to CCRGBAProtocol protocol */
@property (nonatomic,readonly) ccColor3B color;
/** creates a bitmap font altas with an initial string and the FNT file */
+(id) bitmapFontAtlasWithString:(NSString*)string fntFile:(NSString*)fntFile;
/** init a bitmap font altas with an initial string and the FNT file */
-(id) initWithString:(NSString*)string fntFile:(NSString*)fntFile;
/** updates the font chars based on the string to render */
-(void) createFontChars;
/** Free function that parses a FNT file a place it on the cache
CCBitmapFontConfiguration * FNTConfigLoadFile( NSString *file );
/** Purges the FNT config cache
void FNTConfigRemoveCache( void );
Jump to Line
Something went wrong with that request. Please try again.