简体   繁体   English

无法设置CCLabelTTF anchorPoint

[英]unable to set CCLabelTTF anchorPoint

i am using CCLabelTTF together with NSLocalizedString, but i am not able to set the anchor point. 我正在将CCLabelTTF与NSLocalizedString一起使用,但是我无法设置锚点。 (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!!!"] (我希望我所有的按钮都向左对齐,所以应该是ccp(0,0.5f),但是在任何本地化中,结果始终是居中。以下方法在Helper.m中,我称CCLabelTTF * startLabel = [助手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 顺便说一句,我在哪里可以找到一些常见的本地化词汇,例如“播放”,“恢复”,“暂停”等?我认为Google翻译不够准确

Take a look at CCLabelTTF Class Reference here: 在这里查看CCLabelTTF类参考:

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. 创建具有对齐方式的CCStringTTF。

Alignment could be one of the followings: 对齐方式可能是以下之一:

CCTextAlignmentLeft     
CCTextAlignmentCenter   
CCTextAlignmentRight 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM