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

发布于 2024-10-16 14:35:57 字数 650 浏览 1 评论 0原文

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

@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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昵称有卵用 2024-10-23 14:35:57

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

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

所以就这样了。表面上,您会将这些 CCSprite 对象添加到 CCLayer(或其他一些 CCNode 对象),对吗?

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

这有帮助吗?如果您向我提供有关您的用例的更多想法,我可以扩展我的答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文