Making text = an int (cocos2d iPhone)
I have an int named percentComplete (for a SplashScene). I need to make that into text (CCLabelBMFont) that will have the same number as the int, and be updated when the int is. Think of a loading screen that has a number represent how far it is until the game can start (77%). I've started with this so far. I end up with a warning. percentComplete is the int, percentCompleteText is a CCLabelBMFont
-(void)displayPercentCompleteText:(id)sender {
percentCompleteText = (CCLabelBMFont *) [self getChildByTag:kTagPercentComplete];
[percentCompleteText setString:[percentComplete getPercentComplet开发者_高级运维eAsString]]; //Invalid receiver type 'int'
percentCompleteText.position = ccp(111, 111); //CHANGE POSITION
//SCHEDULE UPDATE EVERY .01s
}
-(NSString *)getPercentCompleteAsString {
return [NSString stringWithFormat:@"%d", percentComplete];
}
I'm assuming -(NSString *)getPercentCompleteAsString
is in the same class as -(void)displayPercentCompleteText:(id)sender
and percentComplete
is a member variable (ivar) of that class ..
Change the line:
[percentCompleteText setString:[percentComplete getPercentCompleteAsString]]
to:
[percentCompleteText setString:[self getPercentCompleteAsString]]
return [NSString stringWithFormat:@"%d", percentComplete];
what if you change the line to
return [NSString stringWithFormat:@"%i", percentComplete];
instead of double..
精彩评论