【问题标题】:Best way to display a game score on iPhone with cocos2d?使用 cocos2d 在 iPhone 上显示游戏分数的最佳方式?
【发布时间】:2008-12-03 16:22:26
【问题描述】:

我希望使用 cocos2d 在 iPhone 应用程序中持续显示游戏分数。关闭 cocos2d 显示应用程序运行的 FPS 的代码:

-(void) showFPS
{
    frames++;
    accumDt += dt;

    if ( accumDt > 0.1)  {
        frameRate = frames/accumDt;
        frames = 0;
        accumDt = 0;
    }

    NSString *str = [NSString stringWithFormat:@"%.1f",frameRate];
    [FPSLabel setString:str];
    [FPSLabel draw];
}

我可以让分数正确显示,但它会闪烁,即使应用程序以 60 FPS 的速度运行...有什么想法吗?

【问题讨论】:

  • 关于你展示的这段代码的一件事,不要用 draw 给 FPSLabel 发送消息。相反,请在更新后使用 [FPSLabel setNeedsDisplay:YES]。这应该会取消您的闪烁。

标签: iphone objective-c cocoa-touch cocos2d-iphone


【解决方案1】:

对于任何可能感兴趣的人,我最终使用了 cocos2d 标签:

scoreLabel = [Label labelWithString: [NSString stringWithFormat:@"%d", score] dimensions: CGSizeMake(180, 20) alignment: UITextAlignmentRight fontName:@"Arial" fontSize: 20];
[scoreLabel setPosition: cpv(100,100)];
[self add: scoreLabel];

希望这可以帮助其他人。

【讨论】:

  • 从 Cocos2d 0.8 开始,您应该使用 BitmapFontAtlas,因为它对于屏幕上经常更新的内容要快得多。
【解决方案2】:

尝试改用 LabelAtlas。它更快(它消耗的 CPU 更少)。 请参阅 cocos2d 发行版附带的 AtlasDemo 以了解如何使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2013-01-17
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多