使 text = int (cocos2d iPhone)

发布于 2024-10-25 10:25:40 字数 706 浏览 6 评论 0原文

我有一个名为percentComplete 的int(用于SplashScene)。我需要将其制作成文本(CCLabelBMFont),其数字与 int 相同,并在 int 时更新。想象一个加载屏幕,其中有一个数字表示距离游戏开始还有多远(77%)。到目前为止我已经开始了。我最终收到了警告。 %Complete 是 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];
    }

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 getPercentCompleteAsString]]; //Invalid receiver type 'int'
    percentCompleteText.position = ccp(111, 111); //CHANGE POSITION
    //SCHEDULE UPDATE EVERY .01s
}   

    -(NSString *)getPercentCompleteAsString {
        return [NSString stringWithFormat:@"%d", percentComplete];
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑着哭最痛 2024-11-01 10:25:40

我假设 -(NSString *)getPercentCompleteAsString-(void)displayPercentCompleteText:(id)sender 属于同一类,而 percentComplete 是该类的成员变量 (ivar) ..

将行:更改

[percentCompleteText setString:[percentComplete getPercentCompleteAsString]]

为:

[percentCompleteText setString:[self getPercentCompleteAsString]]

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]]
你丑哭了我 2024-11-01 10:25:40
 return [NSString stringWithFormat:@"%d", percentComplete];

如果您将行更改为

return [NSString stringWithFormat:@"%i", percentComplete];

而不是 double 会怎么样..

 return [NSString stringWithFormat:@"%d", percentComplete];

what if you change the line to

return [NSString stringWithFormat:@"%i", percentComplete];

instead of double..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文