最有效的方式来处理多个CCSprites? [英] Most Efficient way to deal with multiple CCSprites?

查看:198
本文介绍了最有效的方式来处理多个CCSprites?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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


推荐答案

,CCSpriteBatchNode不太可能是你的答案,如果你使用不同的纹理。从Cocos2D文档此处

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


CCSpriteBatchNode就像一个批处理
节点:如果它包含子节点,它将
绘制在单个OpenGL调用
(通常称为分批抽取)。 A
CCSpriteBatchNode可以引用一个
并且只引用一个纹理(一个图像文件,
一个纹理atlas)。

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).

这样就出来了。表面上,你会添加这些CCSprite对象到CCLayer(或一些其他CCNode对象),是吗?

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

没有必要创建一个单独的数组来管理子对象 - Cocos2D为您提供任何节点的 children 属性。如果您 [myLayer addChild:newSprite] ,您将在 children 中引用它。

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.

这篇关于最有效的方式来处理多个CCSprites?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆