When the user taps a button, I want to move a sprite to the next nearest ball (sprite), so they can move from place to place.
As there will only be a limited amount of balls on the screen at a time, I was thinking I should store them in an array, and then when they move offscreen (are destroyed by a function I have in place), they are removed from the array.
I have the current setup (not in a loop atm) :
ball = [[CCSprite spriteWithFile:@"ball.png"] retain];
ball.position = ccp(randX, randY);
NSMutableArray *myArray = [[NSMutableArray alloc] init];
[myArray addObject: ball];
[myArray addObject: ball];
[myArray addObject: ball];
for (int i = 0; i < 2; i++) {
CCSprite *sprite = [myArray objectAtIndex:i];
NSLog(@"%@", sprite.position.x);
}
Why is NSLog printing "(null)" to the console?