0

您好,我正在制作一个横向滚动 cocos2d 游戏,我想要一个标签来显示用户在游戏中飞行了多远。由于某种原因,我编写的代码没有出现标签。这是我的 GameEngine 类,它调用应该使标签出现的类方法:

//Set the meterDistance
    meterDistance = [MeterDistance createTheMeterDistance];
    [self addChild:meterDistance z:10];

这是 MeterDistance 类中的代码:

    meters = 1;

    meterLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"green_arcade-ipad.fnt"];
    meterLabel.position = ccp(200, screenHeight - 100);
    [self addChild:meterLabel z:10];
    meterLabel.anchorPoint = ccp(1.0, 0.5);

    [self schedule:@selector(updateLabel:)interval:1.0f/20.0f];

这是 updateLabel 方法:

-(void)updateLabel:(ccTime)delta{
meters++;

NSString* scoreString = [NSString stringWithFormat:@"%d", meters];
[meterLabel setString:scoreString];
}
4

1 回答 1

0

自从我上次处理 cocos2d 代码以来已经有一段时间了……你写的看起来还不错。

一步一步走,看看哪里出了问题。将标签放在屏幕中间(可能屏幕高度已关闭,或者 anchorPoint 将标签移到屏幕外)。

另一个可能的原因是字体文件名不完全是 @"green_arcade-ipad.fnt"。也许你错过了一个大写字母?

否则,您图层的其他一些元素可能会阻碍标签。

于 2013-08-28T06:28:04.607 回答