我需要从 CCSpriteBatch 节点切换纹理图集。我选择的方法是,在可玩角色到达特定 X 轴 (700) 后,游戏会改变它。
它在视觉上工作正常,但问题是,它在更改屏幕时冻结了 2-3 秒,并且我在控制台中收到内存警告。
我不认为我是唯一一个这样做过的人,这让我想知道切换 CCSpriteBatchNode 的正确(最轻)方式是什么。
请参见下面的当前切换代码:
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];
}
谢谢