我有一个名为percentComplete的int(对于SplashScene)。我需要将其转换为与int具有相同编号的文本(CCLabelBMFont),并在int时更新。想象一下加载屏幕,其中有一个数字表示游戏开始前的距离(77%)。到目前为止我已经开始这样了。我最后发出警告。 percentComplete是int,percentCompleteText是CCLabelBMFont
-(void)displayPercentCompleteText:(id)sender {
percentCompleteText = (CCLabelBMFont *) [self getChildByTag:kTagPercentComplete];
[percentCompleteText setString:[percentComplete getPercentCompleteAsString]]; //Invalid receiver type 'int'
percentCompleteText.position = ccp(111, 111); //CHANGE POSITION
//SCHEDULE UPDATE EVERY .01s
}
-(NSString *)getPercentCompleteAsString {
return [NSString stringWithFormat:@"%d", percentComplete];
}
答案 0 :(得分:0)
return [NSString stringWithFormat:@"%d", percentComplete];
如果将行更改为
,该怎么办?return [NSString stringWithFormat:@"%i", percentComplete];
而不是双..
答案 1 :(得分:0)
我假设-(NSString *)getPercentCompleteAsString
与-(void)displayPercentCompleteText:(id)sender
属于同一类,而percentComplete
是该类的成员变量(ivar)。
更改行:
[percentCompleteText setString:[percentComplete getPercentCompleteAsString]]
为:
[percentCompleteText setString:[self getPercentCompleteAsString]]