处理多个 CCSprite 的最有效方法?
我的环境(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果您使用不同的纹理,CCSpriteBatchNode 不太可能是您的答案。来自 Cocos2D 文档此处:
所以就这样了。表面上,您会将这些 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:
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 inchildren
.Does that help? I can expand my answer if you provide me with a little more idea of your use case.