1
votes

I am currently developing one cocos2d game for iPad, in that game lot of animations is there. I have previously used zwoptex for creating spritesheet and adding animations in my project.

In my game 10 Levels is there, and after each level completed one animation will play, the animation is different for each level and animation image size is same as device screen size. so i am not create spritesheet file, instead of i am loading image directly. My problem is while animation it takes too much time for animation playing.

How to i fix it? please any one guide me. is it possible to load full screensize image(1024x768) in plist, because total 10 levels each level has 20 frames for animation, so 10X20 = 200 images need to load spritesheet.

I am using this code for animation

 CCAnimation *animation = [CCAnimation animation];
for(int i=1;i<=20;i++)
 {
  [animation addFrameWithFile:[NSString stringWithFormat:@"Level%dAni%d.png",level,i];
 }
 animation.delayPerUnit = 0.3f;
 animation.restoreOriginalFrame = YES;
 id action = [CCAnimate actionWithAnimation:animation];

My Question is it possible to load full screen animations with spritesheet? and animation loading time is differ and it takes too much time how to fix it?

Please help me..

3
You can use spritesheets for animation because it is more efficient and best suitable for animation which you want. It will definitely load faster than this. - Manthan
Hi Manthan i want to load 200 images that image size is 1024x768. so is it possible to load in spritesheet. i think 4096x4096 is maximum sprite sheet size. so how to load ? - banu
Why don't you turn these animations into videos and play them directly? A full screen frame-based animation is roughly the same as a video (provided you don't need to add other sprites in front of your fullscreen animation and even in that case using video files for the full screen animation with some sprites over it could be feasible). - Ricardo Sanchez-Saez
Thanks rsanchezsaez. i will try to convert animations into videos - banu

3 Answers

1
votes

Do the math and figure out the amount of memory you would need for 200 pics at 1024x768 pixels. Way too much memory for any iSomething device.

If you have a performance problem (ie are you running this on a device?), then there are two things you can do to improve image load speed:

  • Convert your images to .pvr.gz (i recommend TexturePacker for this). They load significantly faster than .png.
  • Use an RGBA4444 pixel format (again you can do this with TexturePacker), and set the texture format in cocos just prior to loading the images. Images will be smaller, take much less memory.

In your code, where you do the anim

    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA4444];
    // load your images and do your anim
    ...
    // at the completion of the anim
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
1
votes

Use NSThread and load your animation in this thread.

NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(preloadFireWorkAnimation) object:nil] autorelease];
    [thread start];

-(void)preloadFireWorkAnimation
 {
      // load your animation here;
 }