Most Efficient way to deal with multiple CCSprites?

1.2k views Asked by At

I have four different types of objects within my environment(box2d), each type of object having multiple instances of itself, and would like to find the most efficient way to deal with adding and manipulating all the CCSprites. The sprites are all from different files, so would it be best to create each sprite and add it to a data structure (NSMutableArray) or would I use a CCSpriteBatchNode even though each CCSprite file is different (for each type of object)? Thanks.

@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

There are 1 answers

4
makdad On BEST ANSWER

Well, CCSpriteBatchNode isn't likely your answer, if you are using different textures. From the Cocos2D documentation here:

CCSpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call (often known as "batch draw"). A CCSpriteBatchNode can reference one and only one texture (one image file, one texture atlas).

So that's out. Ostensibly, you'd be adding these CCSprite objects to a CCLayer (or some other CCNode object), right?

There's no need to create a separate array for managing child objects -- Cocos2D provides you with the children property of any node. If you [myLayer addChild:newSprite], you'll have a reference to it in children.

Does that help? I can expand my answer if you provide me with a little more idea of your use case.