Most Efficient way to deal with multiple CCSprites?

别等时光非礼了梦想. 提交于 2019-12-13 21:05:33

问题


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:


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.



来源:https://stackoverflow.com/questions/4927516/most-efficient-way-to-deal-with-multiple-ccsprites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!