1
votes

Please help me anyone of possible. I am building a game where I will be loading multiple CCSpriteBatchNode objects and make them change co-ordinates and rotate the frames so it would seem as if the they are animated and they are moving. I have already achieved moving one CCSpriteBatchNode object from one coordinate to another and it is animated. Now I need it to do another very different animation and load another sprite sheet file and move somewhere else, how can I do this?

This is my code so far:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"PotkaEntry.plist"];

CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"PotkaEntry.pvr.ccz"];

[self addChild:spriteSheet];

NSMutableArray *entryAnimFrames = [NSMutableArray array];

for(int i = 1; i<=12; i++)
{
    [entryAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Potka_entry%d.png", i]]];
}

CCAnimationCache *entryAnim = [CCAnimation animationWithFrames:entryAnimFrames delay:0.08f];

CGSize winSize = [CCDirector sharedDirector].winSize;

self->_body1 = [CCSprite spriteWithSpriteFrameName:@"Potka_entry1.png"];

_body1.position = CGPointMake(winSize.width/2, 0);

self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:entryAnim restoreOriginalFrame:NO]];

[_body1 runAction:_walkAction];

_body1.scale = 0.4;

[spriteSheet addChild:_body1];

id entryAction = [CCMoveTo actionWithDuration:5.0f position:ccp(winSize.width/2,60)];

[_body1 runAction:entryAction];
1
why not just make another CCSpriteBatchNode? What is the issue you're having?FBryant87
I am asking how I can load another sprite sheet (as in another .pvr.ccz file) onto the same CCSpriteBatchNode object and another sprite frame (the .plist file) in the same CCSpriteFrameCache object? If I do it your way, should I remove the current CCSpriteBatchNode object before loading another one? Thanks in advance.Shahnawaz

1 Answers

5
votes

You need to create a new CCSpriteBatchNode for each spritesheet you use (by spritesheet I mean the combined pvr.ccz file and .plist file)

The CCSpriteFrameCache is a single cache shared across all your scenes and classes. When you call this method:

[CCSpriteFrameCache sharedSpriteFrameCache]

You are not making a new CCSpriteFrameCache object everytime, there is just ONE instance. You store all your loaded spritesheets in this single cache. So you could load 2 spritesheets into the cache like so:

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sheet1.plist"]; 
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"sheet2.plist"];

You then need to create a CCSpriteBatchNode for EACH spritesheet, you cannot have more than one sheet in a batch node:

CCSpriteBatchNode *spriteSheet1 = [CCSpriteBatchNode batchNodeWithFile:@"sheet1.pvr.ccz"]; 
CCSpriteBatchNode *spriteSheet2 = [CCSpriteBatchNode batchNodeWithFile:@"sheet2.pvr.ccz"];

You can then add both of these batch nodes to a layer if you wish. Sprites added to batch nodes must be from the spritesheet that batch node is using.