c++ - Animation using .png files cocos2dx -
i have 34 .png image files 9 different scenarios. each time user picks 1 of 9 scenarios , according generate animation using following
std::string name; mixingscreen::animation = ccanimation::create(); // load image file local file system ccspriteframe, add ccanimation (int = 0; < 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 facing when animation runs, there time lag(everything stops few seconds) , animation starts. solution?
every time call animation->addspriteframewithfilename() new "ccspriteframe" created.
instead should first add sprite frames ccspriteframecache , use
animation->addspriteframe(ccspriteframecache::sharedspriteframecache()->spriteframewithname(""))
ps: these function names might little different hope idea.
Comments
Post a Comment