1

当我尝试将精灵添加到数组时,我遇到了一个未捕获的异常错误,对我来说一切都很好。我正在为这个 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
4

1 回答 1

0

以下工作正常(Cocos2D 0.7.3,如果这对 2.1 SDK 很重要):

Sprite *sprites[SPRITE_COUNT];
for(int i = 0; i < SPRITE_COUNT; i++) {
    sprites[i] = [Sprite spriteWithFile:@"file.png"];
    [sprites[i] setPosition: ccp(0, 0)];
    [self addChild: sprites[i] z:0];
}
于 2009-05-30T17:54:48.397 回答