c++ - Cocos2d-x 3.2 Error - Change Arrays to Vectors? -


i getting error following code because using arrays instead of vectors. best way write code using vectors?

ccanimate* createanimate(int framecount, float duration, const char* imagename) {    ccarray * spritesarray = ccarray::create();     (int = 0; < framecount; i++) {        ccstring *spritepath = ccstring::createwithformat("%s%i.png",imagename,i);       ccsprite *sprite = ccsprite::create(spritepath->getcstring());       spritesarray->addobject(sprite);     }     ccarray *animationframes = ccarray::create();     (int = 0; < spritesarray->count(); i++) {        ccsprite *sprite = (ccsprite*)spritesarray->objectatindex(i);       ccspriteframe *frame = sprite->displayframe();       animationframes->addobject(frame);     }     ccanimation* animation =  ccanimation::createwithspriteframes(animationframes,duration);    ccanimate* animate= ccanimate::create(animation);     return animate;     } 

vector<spriteframe*> villanspriteframes(framecount);     (int = 1; <= framecount; i++) {     char filename[128] = { 0 };     sprintf(filename, "imagename%d.png", i);      auto frames = spritecache->getspriteframebyname(filename);     villanspriteframes.pushback(frames); }  auto swordrun = animation::createwithspriteframes(villanspriteframes,         duration); swordrun->setrestoreoriginalframe(true); auto animate = animate::create(swordrun); return animate; 

to use code u have use .plist file using texture packer, pack files in using desired names. add texture file in init method like...

spriteframecache *spritecachespritecache = spriteframecache::getinstance(); spritecache->addspriteframeswithfile("fightanim.plist", "fightanim.png"); 

spriteframecache singleton object. hope helps you.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -