Reputation: 932
i am using CCLabelTTF together with NSLocalizedString, but i am not able to set the anchor point. (I want all my buttons to be aligned left, so it should be ccp(0, 0.5f), but the result is always center, in any localization. the following methods are in a Helper.m, and i call CCLabelTTF* startLabel = [Helper createItemLabelWithStringUpperCase: @"PLAY!!!"]
+(CCLabelTTF*) createLocalizedLabelWithStringUpperCase: (NSString*) str color: (ccColor3B) c fontSize: (int) s {
NSString* font;
if ([Helper useCutomFontFile]) {
font = @"font.ttf";
}
else {
font = @"Arial";
}
CCLabelTTF* label = [CCLabelTTF labelWithString:NSLocalizedString(str, nil) fontName:font fontSize:s];
CCLOG(@"%@\n", str);
CCLOG(@"%@\n", NSLocalizedString(str, nil));
label.color = c;
return label;
}
+(CCLabelTTF*) createLocalizedLabelWithStringUpperCase: (NSString*) str color: (ccColor3B) c {
return [Helper createLocalizedLabelWithStringUpperCase:str color:c fontSize:32];
}
+(CCLabelTTF*) createUnlocalizedLabelWithString:(NSString *)str color:(ccColor3B)c fontSize: (int) s {
CCLabelTTF* label = [CCLabelTTF labelWithString: str fontName:@"font.ttf" fontSize:s];
label.color = c;
return label;
}
+(CCLabelTTF*) createUnlocalizedLabelWithString: (NSString*) str color: (ccColor3B) c {
return [Helper createUnlocalizedLabelWithString:str color:c fontSize:32];
}
+(CCLabelTTF*) createItemLabelWithStringUpperCase: (NSString*) str {
CCLabelTTF* label = [Helper createLocalizedLabelWithStringUpperCase:str color:ccBLACK];
label.anchorPoint = ccp(0, 0.5f);
return label;
}
btw, where can i find some common localized vocabulary like "play", 'resume' 'pause" etc? i don't think google translate is accurate enough
Upvotes: 0
Views: 1123
Reputation: 2292
Take a look at CCLabelTTF Class Reference here:
http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_label_t_t_f.html
And try this method:
labelWithString:dimensions:alignment:fontName:fontSize:
or this:
initWithString:dimensions:alignment:fontName:fontSize:
To create a CCStringTTF with alignment.
Alignment could be one of the followings:
CCTextAlignmentLeft
CCTextAlignmentCenter
CCTextAlignmentRight
Upvotes: 1