无法设置CCLabelTTF anchorPoint

时间:2012-01-29 12:18:59

标签: iphone ios cocos2d-iphone

我正在使用CCLabelTTF和NSLocalizedString,但我无法设置锚点。 (我希望我的所有按钮都向左对齐,所以它应该是ccp(0,0.5f),但结果总是居中,在任何本地化中。 以下方法在Helper.m中,我调用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;
}
顺便问一下,在哪里可以找到一些常见的本地化词汇,如“播放”,“恢复”,“暂停”等等?我认为谷歌翻译不够准确

1 个答案:

答案 0 :(得分:1)

在这里查看CCLabelTTF课程参考:

http://www.cocos2d-iphone.org/api-ref/0.99.5/interface_c_c_label_t_t_f.html

尝试这种方法:

labelWithString:dimensions:alignment:fontName:fontSize:

或者这个:

initWithString:dimensions:alignment:fontName:fontSize:

创建带对齐的CCStringTTF。

协调可以是以下之一:

CCTextAlignmentLeft     
CCTextAlignmentCenter   
CCTextAlignmentRight 
相关问题