加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 如何在Cocos2d中更新和显示分数整数?

发布时间:2020-12-14 20:01:11 所属栏目:百科 来源:网络整理
导读:我显然正在制作一个有分数的游戏.如何调用更新方法并在右上角实际显示整数? 解决方法 在这里,这可能会奏效 在.h文件中: @interface HelloWorld : CCLayer { int score; CCLabelTTF *scoreLabel;}- (void)addPoint; 在.m文件中: In the init method: //Set
我显然正在制作一个有分数的游戏.如何调用更新方法并在右上角实际显示整数?

解决方法

在这里,这可能会奏效

在.h文件中:

@interface HelloWorld : CCLayer {
    int score;    
    CCLabelTTF *scoreLabel;
}

- (void)addPoint;

在.m文件中:

In the init method:

//Set the score to zero.
score = 0;

//Create and add the score label as a child.
scoreLabel = [CCLabelTTF labelWithString:@"8" fontName:@"Marker Felt" fontSize:24];
scoreLabel.position = ccp(240,160); //Middle of the screen...
[self addChild:scoreLabel z:1];

别的地方:

- (void)addPoint
{
    score = score + 1; //I think: score++; will also work.
    [scoreLabel setString:[NSString stringWithFormat:@"%@",score]];
}

现在只需致电:[self addPoint];每当用户杀死敌人时.

这应该工作,告诉我,如果没有,因为我没有测试它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读