我在一个层上有一个CCLabelAtlas,用来显示我的game...the中的当前分数,问题是当我使用[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 --提前谢谢!
发布于 2010-03-15 22:39:50
也许这是你使用的字体有问题?尝试使用Cocos2D附带的字体映射之一,看看它是否适合您。
发布于 2010-03-18 20:30:51
方法-CCLabelAtlas setString:做了几件事。
您是否可以验证以下内容是否正确:(放置断点并单步执行函数)
resizeCapacity不会失败resizeupdateAtlasvalues检索UTF8字符数组指针。检查它是否是正确的字符串,在此过程中,用同样的方法检查n,它应该是您的字符串长度请参阅下面的setString代码:
- (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];
}如果你还需要任何帮助,请告诉我结果是什么。
https://stackoverflow.com/questions/2440005
复制相似问题