CCLabelTTF
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World"
fontName:@"Marker Felt" fontSize:64];1. The CCLabelTTF object will use the CCTexture2D class to create an image texture from your text and display that texture onscreen.
2. After the initialization code above, you can use the CCLabelTTF like any other CCNode, add it to your layer, position it, and so forth.
3. Each time you call the setText method, a new texture is created.
CCLabelTTF *gameBeginLabel = [CCLabelTTF labelWithString:@"Game Start" fontName:@"Helvetica" fontSize:64];
[gameBeginLabel setPosition:ccp(screenSize.width/2,screenSize.height/2)];
[self addChild:gameBeginLabel];
id labelAction = [CCSpawn actions:
[CCScaleBy actionWithDuration:2.0f scale:4],
[CCFadeOut actionWithDuration:2.0f],
nil];
[gameBeginLabel runAction:labelAction];
Anchor Points and Alignment

[gameBeginLabel setAnchorPoint: ccp(0, 0.5f)];Listing the Fonts Available in iOS
NSMutableArray *fontNames = [[NSMutableArray alloc] init];
NSArray *fontFamilyNames = [UIFont familyNames];
for (NSString *familyName in fontFamilyNames) {
NSLog(@"Font Family Name = %@", familyName);
NSArray *names = [UIFont fontNamesForFamilyName:familyName];
NSLog(@"Font Names = %@", fontNames);
[fontNames addObjectsFromArray:names];
}
[fontNames release];CCLabelBMFont
1. CCLabelTTFs are great for when you just need the standard iOS fonts and do not have to change the text of the labels very often.
2. A bitmapped font atlas is an image containing all of the characters you want to dis- play along with coordinates data that allows the characters to be cut out of the master image.
3. Since the characters are already stored as images, you can- not alter their size without using a different font atlas.
CCLabelBMFont *gameBeginLabel =
[CCLabelBMFont labelWithString:@"Game Start"
fntFile:@"SpaceVikingFont.fnt"];Live Debugging
1.
本文介绍Cocos2d-x中使用CCLabelTTF和CCLabelBMFont进行文本显示的方法,包括创建文本标签、设置位置与动作、调整锚点及对齐方式等,并提供了一种列出iOS可用字体名称的方案。

被折叠的 条评论
为什么被折叠?



