I need to switch texture atlas from CCSpriteBatch node. The approach I chose is, after the playable character reaches a specific X axis (700) the game changes it.
and it works fine visually, but the problem is, it freezes for 2-3 seconds the screen while changing and I receive memory warning in the console.
I don't think I am the only one who ever did that, which makes me wonder how is the proper(lightest) way of switching CCSpriteBatchNode.
See below the current switching code:
if(mainCharacter.x > 700)
{
//NSLog(@"switch!");
float oldHeroX, oldHeroY;
oldHeroX = mainCharacter.x;
oldHeroY = mainCharacter.y;
[_myBatchNode removeChild:mainCharacter];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFramesFromFile:texturePList1];
[self removeChild:_myBatchNode];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:texturePList2];
_myBatchNode = [CCSpriteBatchNode batchNodeWithFile:texturePNG2];
[_myBatchNode.texture setAliasTexParameters];
[self addChild: _myBatchNode z:-6];
//this is just a method that starts the playable character sprite and add to batch node and layer
[self startCharacter:oldHeroX :oldHeroY];
}
thanks