加载后无法在CCBFile上更改标签

时间:2014-08-13 02:58:23

标签: ios objective-c cocos2d-iphone spritebuilder

为了序言,我正在做SpriteBuilder的教程,其中一个是一个简单的Flappy Bird翻拍。重启按钮有点简单,所以我决定添加自己的触摸,一个显示玩家得分的图层,显示鸟类崩溃的时间。

我正在尝试在我的gameOverLayer上显示CCBFile MainScenegameOverLayer只是一个包含“游戏结束”标签的图层,并且您的分数和得分都很高。当播放器失败时,我正在调用[self gameOver],并且该方法具有用于在屏幕上显示CCBFile的代码。这很好用,但是当我尝试通过调用_scoreLabel.string = [NSString stringWithFormat:@"%d", _points];来更新标签时,同样在-(void)gameOver中,它也不会显示任何内容。我认为这可能是我的积分系统的一个问题,所以我用_scoreLabel.string = @"test"替换它。这也不起作用。

我觉得奇怪的是,当我在_scoreLabel.string = @"test"方法中调用viewDidLoad时,它的工作正常,但是当我在-(void)gameOver中执行相同操作时,它不会更新标签。

这是我正在做的......

Displaying the CCBFile

Displaying the CCBFile 2

GameOver.ccb

我创建了CCBFile

MainScene.h:

@property (weak, nonatomic) CCNode *gameOverLayer;
@property (weak, nonatomic) CCLabelTTF *finalScoreLabel;
@property (weak, nonatomic) CCLabelTTF *bestScoreLabel;

我将view gameOverLayer隐藏在viewDidLoad中

- (void)didLoadFromCCB {
    _gameOverLayer.visible = NO;
}

然后在-(void)gameOver

_finalScoreLabel.string = [NSString stringWithFormat:@"%i", _points];
_bestScoreLabel.string = [NSString stringWithFormat:@"%i", _best];

我尝试了一些简单的事情,但似乎比仅更新gameOver中的标签更复杂。好像一旦图层加载,你就无法改变它上面的标签,这对我来说似乎有些奇怪。有任何想法吗?非常感谢任何回复。感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用以下内容:

[_finalScoreLabel setString:[NSString stringWithFormat:@"%i", _points]];
[_bestScoreLabel setString:[NSString stringWithFormat:@"%i", _best]];

您正在使用正确的字符串,但查看标签标题我看不到任何已定义的字符串属性。只需手动输入这样的getter和setter方法。