当我尝试将精灵添加到数组时,我遇到了一个未捕获的异常错误,对我来说一切都很好。我正在为这个 monoclestudios dot com/static/simplegame.zip 使用 MonocleStudios Simplegame 项目
代码应该是不言自明的:
The .m file:
@implementation GameScene
- (id) init {
self = [super init];
if (self != nil) {
Sprite * bg = [Sprite spriteWithFile:@"game.png"];
[bg setPosition:ccp(240, 60)];
[self addChild:bg z:0];
[self addChild:[GameLayer node] z:1];
Sprite * bg1 = [Sprite spriteWithFile:@"game.png"];
[bg1 setPosition:ccp(211, 260)];
[self addChild:bg1 z:0];
//the above works fine!
Sprite * bgX[50];
//if comment out the next 3 lines, everything runs but I get an "unused variable" warning
bgX[0] = [Sprite spriteWithFile:@"mytree.png"];
[bgX[0] setPosition:ccp(240,150)];
[self addChild:bgX[0] z:0];
}
return self;
}
@end