Im facing a problem with a game Im developing. Ive got several animations and my problem is , they work properly but the first time they are loaded, there is a delay, just for the first time. I dont know how to solve it up. Ive read all the documentation about CCAnimationCache, Ive read the forums and Ive had no success. Im still having the same problem, the animations work but the first time one of them is loaded, there is a delay. Can you please help me with that? Ive also read this site : http://www.johnwordsworth.com/2011/07/loading-cocos2d-sprite-frame-animations-from-plist-files/ and they speak about preloading but my result is the same.
I cache the animations at the beginning and it seems they are in the cache but the result is not the desired all the time and Ive got this delay everytime I load one of the animations for the first time.
Ive coded a function to preload all the animations following the specs and using CCAnimationCache and it doesnt work or maybe Im wrong. Here is some code Ive made :
for(int element = 0; element < 3; element++){
for(int pos = 0; pos < 3; pos++){
CCAnimation *auxAnimation = nil;
animation = getAnimationInformationWithElement(element, pos);
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:[NSString stringWithFormat:@"%@.plist",animation.animationFileHeader]];
for(int i = 0; i <= animation.numberOfFrames; i++) {
if(i<=9)auxFileName = [animation.animationPNGFileName stringByAppendingString:@"0000"];
else auxFileName = [animation.animationPNGFileName stringByAppendingString:@"000"];
[elementsAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@%d.png",auxFileName,i]]];
}
auxAnimation = [CCAnimation elementsAnimFrames];
[animationsToBeSaved elementsAnimFrames];
elementsAnimFrames = [[[NSMutableArray alloc] init] autorelease];
[[CCAnimationCache sharedAnimationCache] addAnimation:auxAnimation name:[NSString stringWithFormat:@"animation_%d_%d",element,pos]];
}
}
Any ideas?