Cocos2d iphone 在CCNode中设置CCLabelTTF的位置并添加到CCScene[cocos2d v3]

Cocos2d iphone 在CCNode中设置CCLabelTTF的位置并添加到CCScene[cocos2d v3],cocos2d-iphone,cclayer,cclabelttf,ccnode,Cocos2d Iphone,Cclayer,Cclabelttf,Ccnode,我很难理解这里发生了什么。我目前有一个从CCNode继承的“Header”类。此CCNode类具有多个属性,包括CCSprite和CCLabelTTF。在init中,我创建这些对象并设置它们的位置。然后,我将这个头类包括在场景中,并将其作为子类添加到场景中。但是,标签位置设置不正确。它将标签的位置属性设置为0,0 下面是标题的代码。h: @interface Header : CCNode { CCButton *settingsButton_; CCButton *crewBu

我很难理解这里发生了什么。我目前有一个从CCNode继承的“Header”类。此CCNode类具有多个属性,包括CCSprite和CCLabelTTF。在init中,我创建这些对象并设置它们的位置。然后,我将这个头类包括在场景中,并将其作为子类添加到场景中。但是,标签位置设置不正确。它将标签的位置属性设置为0,0

下面是标题的代码。h:

@interface Header : CCNode {
    CCButton *settingsButton_;
    CCButton *crewButton_;
    CCButton *goldButton_;
    CCSprite *divider_;
    CCLabelTTF *rank_;
    CCLabelTTF *userName_;
}

@property (nonatomic, retain) CCButton *settingsButton;
@property (nonatomic, retain) CCButton *crewButton;
@property (nonatomic, retain) CCButton *goldButton;
@property (nonatomic, retain) CCSprite *divider;
@property (nonatomic, retain) CCLabelTTF *rank;
@property (nonatomic, retain) CCLabelTTF *userName;

+ (id)node;
- (id)init;

@end
和标题。m:

@implementation Header

+(id)node {
    return [[self alloc] init];
}

-(id)init {
    self = [super init];
    if (!self) return(nil);

    NSString *rankString = [[GameManager sharedGameManager] getRank];

    self.rank = [CCLabelTTF labelWithString:rankString fontName:@"Copperplate-Bold" fontSize:16.0];
    self.rank.color = [CCColor blackColor];
    self.rank.positionType = CCPositionTypeNormalized;
    self.rank.position = ccp(0.35, 0.965);

    [self addChild:self.rank];

    return self;
}

@end
现在,当我将这个头部CCNode添加到我的图层时,位置不会停留在
ccp(0.35,0.965)
,它只是重置为0,0


这里有我遗漏的东西吗?

问题是CCPositionNormalization。如果您使用它,它不需要实际的像素大小。有一次我评论说,使用实际像素大小(例如ccp(100200))效果很好。谢谢

请尝试较大的位置值。iPhone/iPad无法将标签显示为(0.35,0.965)像素。为什么不使用整数值呢?您可以使用float,但是(0.35,0.965)实际上大约是(0,0)。。。