FWIW, I found this surprisingly simple and useful...
I had the need for some of my AtlasSprites to sometimes be behind other sprites (belonging to other AtlasSpriteManagers) and sometimes in front. Now, with Sprites, this is no problem because you can manipulate the Z-order easily. With AtlasSprites you don't have this luxury if the sprites you want to hide behind or go in front of are in other Atlases. My solution was to create two AtlasSpriteManagers, both using the same Atlas, but with different Z-orders. Then when I want to effectively move individual sprites up and down the Z-order, I call the following which is in my AtlasSprite subclass:
-(void) switchSpriteManager:(AtlasSpriteManager *)newManager
{
[spriteManager removeChild:self cleanup:YES];
[newManager addChild:self];
textureAtlas_ = [newManager textureAtlas];
spriteManager = newManager;
}
When I first wrote this, I was getting access violations, which I traced down to a bug which otherwise goes unnoticed in TextureAtlas.m. The following changes need to be made to textureAtlas.m in order for this trick to work:
Line 144: Change NSUInteger to NSInteger
Line 147: Change (remaining) to (remaining > 0)
Line 183: Change NSUInteger to NSInteger
Line 187: Change (remaining) to (remaining > 0)
The local integer arithmetic in these two areas can produce a negative number, but the type of the variable is unsigned and the following if statement simply checks if not zero when it should really check if greater than zero.
I will create an issue for this so hopefully this change will be put into cocos2d so it doesn't have to be moded in the future.
In any case, I wanted to post this here as I think this trick can be useful in other situations aside from wanting to manipulate the Z-order of AtlasSprite children among across multiple AtlasSpriteManagers. Off the top of my head, you could use this to effectively create a 3-D Atlas where you load different AtlasSpriteManagers with different Atlases effectively making different layers. The images each of the Atlases would need to be related obviously, but this would allow you to swap out whole classes of images in bulk easily AND WITHOUT ANY OVERHEAD of setting texture rects or otherwise manipulating the Atlas.