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

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

概述我显然正在制作一个有分数的游戏.如何调用更新方法并在右上角实际显示整数? 在这里,这可能会奏效 在.h文件中: @interface HelloWorld : CCLayer { int score; CCLabelTTF *scoreLabel;}- (void)addPoint; 在.m文件中: In the init method: //Set the scor 我显然正在制作一个有分数的游戏.如何调用更新方法并在右上角实际显示整数?解决方法 在这里,这可能会奏效

在.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];每当用户杀死敌人时.

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

总结

以上是内存溢出为你收集整理的iphone – 如何在Cocos2d中更新和显示分数整数?全部内容,希望文章能够帮你解决iphone – 如何在Cocos2d中更新和显示分数整数?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1060463.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存