Hello,
I am very new to Objective C and Cocos2d. I have spent most of the day trying to figure out how to do this. I tried several ways but it doesn't work. I have an Atlas Sprite Manager with lots of sprites in it. These sprites are added on a timer and will be removed when I'm done with them one at a time. The sprites are simple blocks and will be deleted when clicked. The problem is, since I don't know how many sprites there are and tagging doesn't seem to be an option because I don't know what the tags would be since they are being added and removed by the game engine. I just need to create a simple loop so I can interact with the sprites one at a time, update them and let the engine proceed to the next loop. How do I do this?
I tried the example from:
http://www.cocos2d-iphone.org/forum/topic/754#post-4442
layer *layer = [mygame node];
for(id *item in layer.children)
{
//and if I want to make sure the child is the type I want:
if([item isKindOfClass:[AtlasSprite class]]) <----- This gives me this - Warning: invalid receiver type 'id*'
{
//int x = item.position.x; <---- this errors out saying unused variable x
}
}
Then I tried to just loop through the children of the manager itself like this.
AtlasSpriteManager *mgr = (AtlasSpriteManager*) [self getChildByTag:kTagSpriteManager];
for(id *sprite in mgr.children)
{
int x = sprite.position.x; <----- Again same error
}
I think I see a problem because sprite is not really a sprite it's an id but how do I make the ID point to the sprite so I can work with it?