0

I have 34 .png image files for 9 different scenarios. Each time the user picks 1 of those 9 scenarios and according to that I generate animation using the following

 std::string name;
 MixingScreen::animation = CCAnimation::create();
 // load image file from local file system to CCSpriteFrame, then add into CCAnimation
 for (int i = 0; i < 34; i++)
 {
     std::stringstream st,ii;
     st << Constants::flav;
     if (i<10)
     {
         ii<<i;
        name="screen/screen02/fx/sugar/0" + st.str()+"/a_0000"+ii.str()+".png";
     }
     else
     {
         ii<<i;
        name="screen/screen02/fx/sugar/0" + st.str()+"/a_000"+ii.str()+".png";
     }
        //sprintf(szImageFileName, "Images/grossini_dance_%02d.png", i);
     MixingScreen::animation->addSpriteFrameWithFileName(name.c_str()); 
     }
     MixingScreen::animation->setDelayPerUnit(5.0f / 34.0f);

    action = CCAnimate::create(MixingScreen::animation);
    CCCallFunc *done = CCCallFunc::create(this, callfunc_selector(MixingScreen::doneMixing));
    CCSequence *readySequence = CCSequence::create(action,done,NULL);
    particles->runAction(readySequence);  

The problem I am facing is that when this animation runs, there is a time lag(everything stops for few seconds) and then the animation starts. Any solution?

icodebuster
  • 8,890
  • 7
  • 62
  • 65
amyn
  • 922
  • 11
  • 24

1 Answers1

2

Every time you call animation->addSpriteFrameWithFileName() a new "CCSpriteFrame" is created.

Instead you should first add the sprite frames to CCSpriteFrameCache and use

animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameWithName(""))

Ps: these function names might be a little different but i hope you get the idea.

GizmoThunder
  • 235
  • 1
  • 5
  • 1
    `CCSpriteFrameCache::sharedSpriteFrameCache()` is now deprecated. Use `CCSpriteFrameCache::getInstance()` instead. – namezero Jun 11 '15 at 20:00