iphone - 如何在 Cocos2d 中更新并显示分数整数?

标签 iphone xcode cocos2d-iphone

我显然正在制作一款有分数的游戏。如何调用更新方法并使整数实际显示在右上角?

最佳答案

在这里,这可能有效

在 .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 中更新并显示分数整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5611294/

相关文章:

ios - Unity Vuforia Xcode 构建错误 : "Undefined symbols for architecture arm64"

iphone - 我需要检查 iPhone 程序上的 View 层次结构

ios - 如果创建 BLE 应用程序,我的应用程序应该支持哪个最低 iOS 版本?

ios - 如何将多个对象传递给延迟方法?

ios - Cocos2d 游戏在某些设备上无法启动

iphone - 三个else-if语句

IOS - 获取通知并决定做什么

iphone - 将 SQLite 中的数据保存为 BLOB 是一种良好的编程习惯吗?

iPhone 应用程序 : Webapps or native?

ios - 如何在 iOS 中使用 Cocos2d V3 制作类似 Candy Crush Saga 应用程序的 Ray Animation