CCLabelAtlas setString doesn't update label
Posted
by JonnyFunFun
on Stack Overflow
See other posts from Stack Overflow
or by JonnyFunFun
Published on 2010-03-13T20:58:39Z
Indexed on
2010/03/13
21:05 UTC
Read the original article
Hit count: 451
cocos2d
|cocos2d-iphone
Hello! I have a CCLabelAtlas that I have on a layer to display the current score within my game...the problem that I am having with it is that it does not update when I use [scoreLabel setString:]
. Here's how I have it laid out:
In the header:
@interface GameScene : CCLayer {
...
CCLabelAtlas* scoreLabel;
}
And in the 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 is a custom map that includes ./0123456789
of my desired font. When the score is changed, I attempt to do this to get the label to update with the current score:
NSString* str = [[NSString alloc] initWithFormat:@"%d", [[GameRunner sharedInstance] currentScore]];
[scoreLabel setString: str];
[str release];
[scoreLabel draw];
Problem is that it doesn't ever update - it just sits there and displays 0. I know for a fact due to breakpoints and debugging that setString is being called, and that the string that it should be displaying is correct - but it just doesn't update. Hard-coding the value and saying [scoreLabel setString:@"1234"]
does nothing, either. What am I doing wrong here? I am using Cocos2d 0.99 - thanks in advance!
© Stack Overflow or respective owner