Most Efficient way to deal with multiple CCSprites?

Posted by nardsurfer on Stack Overflow See other posts from Stack Overflow or by nardsurfer
Published on 2011-02-07T22:42:21Z Indexed on 2011/02/08 7:25 UTC
Read the original article Hit count: 179

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

or using NSMutableArray objects within the Level object...

@interface zLevel : zThing {
    NSMutableArray *springs;
    NSMutableArray *blocks;
    NSMutableArray *balls;
    zGoal *goal;
    int levelNumber;
}
@property(nonatomic,retain)NSMutableArray *springs;
@property(nonatomic,retain)NSMutableArray *blocks;
@property(nonatomic,retain)NSMutableArray *balls;
@property(nonatomic,retain)zGoal *goal;
@property(nonatomic,assign)int levelNumber;

-(void)initWithLevel:(int)level;
-(void)loadLevelThings;

@end

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c