Cocos2d iphone CCLabelAlas设置字符串不更新标签

Cocos2d iphone CCLabelAlas设置字符串不更新标签,cocos2d-iphone,Cocos2d Iphone,我在一个图层上有一个CCLabelAlas,用来显示游戏中的当前分数……我遇到的问题是,当我使用[scoreLabel setString:]时,它不会更新。下面是我的布局: 在标题中: @interface GameScene : CCLayer { ... CCLabelAtlas* scoreLabel; } 在init中: scoreLabel = [[CCLabelAtlas alloc] initWithString:@"0" charMapFile:@"scoreCharMap

我在一个图层上有一个CCLabelAlas,用来显示游戏中的当前分数……我遇到的问题是,当我使用[scoreLabel setString:]时,它不会更新。下面是我的布局:

在标题中:

@interface GameScene : CCLayer {
...

CCLabelAtlas* scoreLabel;
}
在init中:

scoreLabel = [[CCLabelAtlas alloc] initWithString:@"0" charMapFile:@"scoreCharMap.png" itemWidth:6 itemHeight:8 startCharMap:'.'];
[scoreLabel setPosition:ccp(105, 414)];
[self addChild:scoreLabel z: 6];
scoreCharMap.png是一个自定义映射,其中包含我所需字体的./0123456789。当分数更改时,我尝试这样做以使标签使用当前分数更新:

NSString* str = [[NSString alloc] initWithFormat:@"%d", [[GameRunner sharedInstance] currentScore]];
[scoreLabel setString: str];
[str release];
[scoreLabel draw];

问题是它永远不会更新-它只是坐在那里并显示0。由于断点和调试,我知道正在调用setString,并且它应该显示的字符串是正确的,但它只是不更新。硬编码值并说出[scoreLabel setString:@1234]也没有任何作用。我做错了什么?我正在使用Cocos2d 0.99-提前感谢

这可能是您使用的字体有问题吧?尝试使用Cocos2D附带的字体映射之一,看看它是否适合您

方法-[cclabelalas setString:]做了一些事情

您能否验证以下操作是否正确:放置断点并单步执行函数

resizeCapacity不会无法调整大小 UpdateAlasValues检索UTF8字符数组指针。检查这个字符串,看它是否是正确的字符串,当你在那里时,用同样的方法检查n,它应该是你的字符串长度 请参阅下面设置字符串的代码:

- (void) setString:(NSString*) newString {
    if( newString.length > textureAtlas_.totalQuads )
        [textureAtlas_ resizeCapacity: newString.length];

    [string_ release];
    string_ = [newString retain];
    [self updateAtlasValues];

    CGSize s;
    s.width = [string_ length] * itemWidth;
    s.height = itemHeight;
    [self setContentSize:s];
}

如果您仍然需要帮助,请告诉我结果是什么。

即使使用Cocos2d用于帧速率标签的fps_images.png,我也不走运。我不知道这是否可行,但这是一个随机的想法。您能否提供更全面的代码示例,如整个GameSecene类和更新分数的整个文件?你也试过在Cocos2D论坛上发布你的问题。。。