您的错误似乎是您也没有遵循本书的下一部分。完成下一部分应该允许您编译代码而不会出现这样的警告。
本书该部分的更完整摘录是:
然后在 GameSceneinit
方法中添加对initSpiders
接下来讨论的方法的调用,就在后面scheduleUpdate:
-(id) init {
if ((self = [super init]))
{
… 96 CHAPTER 4: Your First Game
[self scheduleUpdate];
[self initSpiders];
}
return self;
}
之后,将相当多的代码添加到GameScene
类中,从 initSpiders
清单 4-8 中的方法开始,它正在创建蜘蛛精灵。
清单 4-8。 为了更容易访问,蜘蛛精灵被初始化并添加到 CCArray
-(void) initSpiders
{
CGSize screenSize = [[CCDirector sharedDirector] winSize];
// using a temporary spider sprite is the easiest way to get the image's size
CCSprite* tempSpider = [CCSprite spriteWithFile:@"spider.png"];
float imageWidth = [tempSpider texture].contentSize.width;
// Use as many spiders as can fit next to each other over the whole screen width.
int numSpiders = screenSize.width / imageWidth;
// Initialize the spiders array using alloc.
spiders = [[CCArray alloc] initWithCapacity:numSpiders];
for (int i = 0; i < numSpiders; i++)
{
CCSprite* spider = [CCSprite spriteWithFile:@"spider.png"];
[self addChild:spider z:0 tag:2];
// Also add the spider to the spiders array.
[spiders addObject:spider];
}
// call the method to reposition all spiders
[self resetSpiders];
}