Reputation: 479
I have to run a 19 sec animation with 466 frames each frame is "1024x768" i am using zwoptex to make a sprite sheet but a sheet is of "4096 X 4096" and it can hold only 15 frames.
I have made mulitple sheets , 30 to be precise and run the animation with them but it has jerks , whn i use just 2 or 3 sheets its quite smooth.
Here is my code
cache=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache addSpriteFramesWithFile:@"Set_1.plist"];
cache1=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache1 addSpriteFramesWithFile:@"Set_2.plist"];
cache2=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache2 addSpriteFramesWithFile:@"Set_3.plist"];
cache3=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache3 addSpriteFramesWithFile:@"Set_4.plist"];
cache4=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache4 addSpriteFramesWithFile:@"Set_5.plist"];
cache5=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache5 addSpriteFramesWithFile:@"Set_6.plist"];
cache6=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache6 addSpriteFramesWithFile:@"Set_7.plist"];
cache7=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache7 addSpriteFramesWithFile:@"Set_8.plist"];
cache8=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache8 addSpriteFramesWithFile:@"Set_9.plist"];
cache9=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache9 addSpriteFramesWithFile:@"Set_10.plist"];
cache10=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache10 addSpriteFramesWithFile:@"Set_11.plist"];
cache11=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache11 addSpriteFramesWithFile:@"Set_12.plist"];
cache12=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache12 addSpriteFramesWithFile:@"Set_13.plist"];
cache13=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache13 addSpriteFramesWithFile:@"Set_14.plist"];
cache14=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache14 addSpriteFramesWithFile:@"Set_15.plist"];
cache15=[CCSpriteFrameCache sharedSpriteFrameCache];
[cache15 addSpriteFramesWithFile:@"Set_16.plist"];
equ=[CCSprite spriteWithFile:@"m1.png"];
[self addChild:equ z:5 tag:90 ];
equ.anchorPoint=ccp(0, 0);
equ.position=ccp(0, 0);
NSMutableArray *framesArray=[NSMutableArray array];
NSMutableArray *framesArray1=[NSMutableArray array];
NSMutableArray *framesArray2=[NSMutableArray array];
NSMutableArray *framesArray3=[NSMutableArray array];
NSMutableArray *framesArray4=[NSMutableArray array];
NSMutableArray *framesArray5=[NSMutableArray array];
NSMutableArray *framesArray6=[NSMutableArray array];
NSMutableArray *framesArray7=[NSMutableArray array];
NSMutableArray *framesArray8=[NSMutableArray array];
NSMutableArray *framesArray9=[NSMutableArray array];
NSMutableArray *framesArray10=[NSMutableArray array];
NSMutableArray *framesArray11=[NSMutableArray array];
NSMutableArray *framesArray12=[NSMutableArray array];
NSMutableArray *framesArray13=[NSMutableArray array];
NSMutableArray *framesArray14=[NSMutableArray array];
// NSMutableArray *framesArray15=[NSMutableArray array];
for (int i=1; i<=15; i++) {
NSString *frameName=[NSString stringWithFormat:@"m%d.png", i];
NSString *frameName1=[NSString stringWithFormat:@"m%d.png", i+(15*1)];
NSString *frameName2=[NSString stringWithFormat:@"m%d.png", i+(15*2)];
NSString *frameName3=[NSString stringWithFormat:@"m%d.png", i+(15*3)];
NSString *frameName4=[NSString stringWithFormat:@"m%d.png", i+(15*4)];
NSString *frameName5=[NSString stringWithFormat:@"m%d.png", i+(15*5)];
NSString *frameName6=[NSString stringWithFormat:@"m%d.png", i+(15*6)];
NSString *frameName7=[NSString stringWithFormat:@"m%d.png", i+(15*7)];
NSString *frameName8=[NSString stringWithFormat:@"m%d.png", i+(15*8)];
NSString *frameName9=[NSString stringWithFormat:@"m%d.png", i+(15*9)];
NSString *frameName10=[NSString stringWithFormat:@"m%d.png", i+(15*10)];
NSString *frameName11=[NSString stringWithFormat:@"m%d.png", i+(15*11)];
NSString *frameName12=[NSString stringWithFormat:@"m%d.png", i+(15*12)];
NSString *frameName13=[NSString stringWithFormat:@"m%d.png", i+(15*13)];
NSString *frameName14=[NSString stringWithFormat:@"m%d.png", i+(15*14)];
id frameObject=[cache spriteFrameByName:frameName];
id frameObject1=[cache1 spriteFrameByName:frameName1];
id frameObject2=[cache2 spriteFrameByName:frameName2];
id frameObject3=[cache3 spriteFrameByName:frameName3];
id frameObject4=[cache4 spriteFrameByName:frameName4];
id frameObject5=[cache5 spriteFrameByName:frameName5];
id frameObject6=[cache6 spriteFrameByName:frameName6];
id frameObject7=[cache7 spriteFrameByName:frameName7];
id frameObject8=[cache8 spriteFrameByName:frameName8];
id frameObject9=[cache9 spriteFrameByName:frameName9];
id frameObject10=[cache10 spriteFrameByName:frameName10];
id frameObject11=[cache11 spriteFrameByName:frameName11];
id frameObject12=[cache12 spriteFrameByName:frameName12];
id frameObject13=[cache13 spriteFrameByName:frameName13];
id frameObject14=[cache14 spriteFrameByName:frameName14];
[framesArray addObject:frameObject];
[framesArray1 addObject:frameObject1];
[framesArray2 addObject:frameObject2];
[framesArray3 addObject:frameObject3];
[framesArray4 addObject:frameObject4];
[framesArray5 addObject:frameObject5];
[framesArray6 addObject:frameObject6];
[framesArray7 addObject:frameObject7];
[framesArray8 addObject:frameObject8];
[framesArray9 addObject:frameObject9];
[framesArray10 addObject:frameObject10];
[framesArray11 addObject:frameObject11];
[framesArray12 addObject:frameObject12];
[framesArray13 addObject:frameObject13];
[framesArray14 addObject:frameObject14];
}
id animObject=[CCAnimation animationWithSpriteFrames:framesArray delay:0.0407];
id animObject1=[CCAnimation animationWithSpriteFrames:framesArray1 delay:0.0407];
id animObject2=[CCAnimation animationWithSpriteFrames:framesArray2 delay:0.0407];
id animObject3=[CCAnimation animationWithSpriteFrames:framesArray3 delay:0.0407];
id animObject4=[CCAnimation animationWithSpriteFrames:framesArray4 delay:0.0407];
id animObject5=[CCAnimation animationWithSpriteFrames:framesArray5 delay:0.0407];
id animObject6=[CCAnimation animationWithSpriteFrames:framesArray6 delay:0.0407];
id animObject7=[CCAnimation animationWithSpriteFrames:framesArray7 delay:0.0407];
id animObject8=[CCAnimation animationWithSpriteFrames:framesArray8 delay:0.0407];
id animObject9=[CCAnimation animationWithSpriteFrames:framesArray9 delay:0.0407];
id animObject10=[CCAnimation animationWithSpriteFrames:framesArray10 delay:0.0407];
id animObject11=[CCAnimation animationWithSpriteFrames:framesArray11 delay:0.0407];
id animObject12=[CCAnimation animationWithSpriteFrames:framesArray12 delay:0.0407];
id animObject13=[CCAnimation animationWithSpriteFrames:framesArray13 delay:0.0407];
id animObject14=[CCAnimation animationWithSpriteFrames:framesArray14 delay:0.0407];
id animAction=[CCAnimate actionWithAnimation:animObject];
id animAction1=[CCAnimate actionWithAnimation:animObject1];
id animAction2=[CCAnimate actionWithAnimation:animObject2];
id animAction3=[CCAnimate actionWithAnimation:animObject3];
id animAction4=[CCAnimate actionWithAnimation:animObject4];
id animAction5=[CCAnimate actionWithAnimation:animObject5];
id animAction6=[CCAnimate actionWithAnimation:animObject6];
id animAction7=[CCAnimate actionWithAnimation:animObject7];
id animAction8=[CCAnimate actionWithAnimation:animObject8];
id animAction9=[CCAnimate actionWithAnimation:animObject9];
id animAction10=[CCAnimate actionWithAnimation:animObject10];
id animAction11=[CCAnimate actionWithAnimation:animObject11];
id animAction12=[CCAnimate actionWithAnimation:animObject12];
id animAction13=[CCAnimate actionWithAnimation:animObject13];
id animAction14=[CCAnimate actionWithAnimation:animObject14];
//animAction=[CCRepeatForever actionWithAction:animAction];
CCSequence *moveAction = [CCSequence actions:animAction,animAction1,animAction2,animAction3,animAction4,animAction5,animAction6,animAction7,animAction8,animAction9,animAction10,animAction11,animAction12,animAction13,animAction14,nil];
moveAction.tag=100;
[equ runAction:moveAction];
Upvotes: 1
Views: 343
Reputation: 64477
animation with 466 frames each frame is "1024x768"
Stop right there!
The problem is that each of your 4096x4096 texture atlases (spritesheets) uses 64 MB of memory. Only 2-4 (depending on device memory) will fit in memory at any given time.
Since you're caching them in sequence, you additionally increase loading time because by the time it's supposed to cache texture number 3 or 4 cocos2d will receive a memory warning, and purge unused textures - the first couple textures.
Then when you start your animation, it loads each texture atlas into memory the moment it is being used because the only cached textures by that point are perhaps 8 through 10. At the same time other unused textures get cached out because you keep receiving memory warnings.
You have two options:
For more info check my cocos2d memory optimization guide.
Upvotes: 4