views:

645

answers:

1

Normally when adding sprites to a layer in cocos2d I'd just add a pointer to the layer's interface for each sprite to allow it to be referenced in that layer. However, I'm now using for loops to create an array of sprites:

-(void) make5Gobs
{
    Sprite *gobs[5];
    for(int i = 0; i < 3; i++) 
    {
     gobs[i] = [Sprite spriteWithFile:@"walk1-2.png"];
     [gobs[i] setPosition: cpv(100+75*i, 0)];
     [self addChild: gobs[i] z:0];
    }
    for(int i = 3; i < 5; i++) 
    {
     gobs[i] = [Sprite spriteWithFile:@"walk1-2.png"];
     [gobs[i] setPosition: cpv(137+75*(i-3), 75)];
     [self addChild: gobs[i] z:0];
    }

}

How can I reference these created sprites?

A: 

Found my error. I initialized the pointer Sprite *gobs[5]; in the method and not the interface.

deeb