1

我一直在尝试通过“Make Games With Us”来了解如何制作 John Conway 的“生命游戏”。在我达到 MainScene.m 的 step 方法之前,我能够遵循大部分教程(这里是该站点的链接):

- (void)step
{
    [_grid evolveStep]
    _generationLabel.string = [NSString stringWithFormat:@"%d", _grid.generation];
    _populationLabel.string = [NSString stringWithFormat:@"%d", _grid.totalAlive];
}

错误属于同一类型;他们出现在 _grid.generation 和 _grid.totalAlive。错误如下:

Property 'generation' not found on object of type 'Grid *'
Property 'totalAlive' not found on object of type 'Grid *'

我已经查看了有关如何解决相同问题的链接,但我在 SpriteBuilder 中正确保存并发布了所有内容;用户显然解决了它,但我不知道如何解决。

更新:缺少属性声明(Grid.m):

#import "Grid.h"
#import "Creature.h"

// variables that cannot be changed
static const int GRID_ROWS = 8;
static const int GRID_COLUMNS = 10;

@implementation Grid {
    NSMutableArray *_gridArray;
    float _cellWidth;
    float _cellHeight;
    int _generation; // This one
    int _totalAlive; // This one
}

/*Rest of the methods go here*/

@end

先感谢您!

4

2 回答 2

2

不幸的是,这在我们的教程中是一个错误。

实际上,您需要将两个属性添加到Grid.h

@property (nonatomic, assign) int totalAlive;
@property (nonatomic, assign) int generation;

而不是将实例变量添加到Grid.m.

教程现已更新:https ://www.makegameswith.us/tutorials/game-of-life-spritebuilder/game-of-life-code/

您还可以在 GitHub 上找到该解决方案的完整代码: https ://github.com/MakeGamesWithUs/GameOfLife.spritebuilder

带来不便敬请谅解!

于 2014-05-27T20:15:24.880 回答
0

错误消息告诉您没有generation为该类命名的属性Grid。也许您对使用前导“_”与“self.”直接访问属性感到困惑。

确保存在这样的属性。更新问题以显示缺少属性的声明。

只需使用属性设置器和获取器,而不是直接访问它们。将所有 ivars 声明为属性。这创造了一致性并减少了错误。

于 2014-05-27T00:57:53.177 回答