处理多个CCSprites的最有效方法?

时间:2011-02-07 22:42:21

标签: iphone objective-c cocos2d-iphone box2d-iphone

我的环境中有四种不同类型的对象(box2d),每种类型的对象都有自己的多个实例,并希望找到最有效的方法来处理添加和操作所有CCSprites。精灵都来自不同的文件,所以最好创建每个精灵并将其添加到数据结构(NSMutableArray),或者我会使用CCSpriteBatchNode,即使每个CCSprite文件不同(对于每种类型的对象)?感谢。

@interface LevelScene : CCLayer
{
    b2World* world;
    GLESDebugDraw *m_debugDraw;

    CCSpriteBatchNode *ballBatch;
    CCSpriteBatchNode *blockBatch;
    CCSpriteBatchNode *springBatch;
    CCSprite *goal;
}

+(id) scene;

// adds a new sprite at a given coordinate
-(void) addNewBallWithCoords:(CGPoint)p;

// loads the objects (blocks, springs, and the goal), returns the Level Object
-(Level) loadLevel:(int)level;

@end

1 个答案:

答案 0 :(得分:1)

好吧,如果您使用不同的纹理,CCSpriteBatchNode可能不是您的答案。来自Cocos2D文档here

  

CCSpriteBatchNode就像一个批处理   node:如果它包含子节点,它会   在1个单一的OpenGL调用中绘制它们   (通常称为“批量抽奖”)。一个   CCSpriteBatchNode可以引用一个   并且只有一个纹理(一个图像文件,   一个纹理图集。

所以那就是了。表面上看,你要将这些CCSprite对象添加到CCLayer(或其他一些CCNode对象),对吗?

无需为管理子对象创建单独的数组 - Cocos2D为您提供任何节点的children属性。如果您[myLayer addChild:newSprite],则会在children中对其进行引用。

这有帮助吗?如果你让我对你的用例有更多的了解,我可以扩展我的答案。

相关问题