这是一个使用 CCSpriteFrameCache 和 CCSpriteBatchNode 的快速示例。
首先设置共享帧缓存(将其视为单个图像的名称与其组合批处理节点图像中的矩形帧之间的映射):
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"spritesheet.plist" textureFile:@"spritesheet.png"];
现在使用组合图像名称创建批处理节点(此 batchNode 为多个精灵进行单次绘制):
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"spritesheet.png" capacity:20];
现在创建传入单个图像名称的精灵节点。将其添加到批处理节点。(同样,batchnode 将执行绘制调用,因此这是性能优势所在):
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"name_of_your_sprite_in_plist"];
[batchNode addChild:sprite];
您可以将 sprite 视为之前直接从单个图像创建的 sprite(但具有使用批处理节点的性能优势)。