ios - When to release a CCSpriteBatchNode once the animation is finsihed[Solved] -
i playing animation , want remove batch node parent (cclayer) animation finishes playing. running ccsequence have function named animationfinished called when finishes playing. can't remove batch node parent in function released , don't have other retain. game crashes, still being used engine.
so @ event can release batch node. if don't , added again , again cclayer.please see code below
void gamelayer::playanimation(const animationfileandtypeinfo &powerfileinfo,float placeatscreenwidthratio,float placeatscreenheightratio){ std::string firstframe,framename,plist,plistpng; plist=powerfileinfo.animfileinfo.plist; plistpng=powerfileinfo.animfileinfo.plistpng; firstframe=powerfileinfo.animfileinfo.firstframe; framename=powerfileinfo.animfileinfo.framename; // generic animation play code ccspriteframecache *animcache = ccspriteframecache::sharedspriteframecache(); animcache->addspriteframeswithfile(plist.c_str()); _animplaybatchnode = ccspritebatchnode::create(plistpng.c_str(), 100); this->addchild(_animplaybatchnode,kforeground+1); short numberofframes=getplistframescount(plist.c_str(),"frames");// plist full name postfix .plist ccarray *spriteframes = ccarray::createwithcapacity(numberofframes); spriteframes->retain(); _animplayfirstsprite = ccsprite::createwithspriteframename(firstframe.c_str());// postfix .png _animplaybatchnode->addchild(_animplayfirstsprite,kforeground+1); _animplayfirstsprite->setposition(ccp(_screensize.width*placeatscreenwidthratio, _screensize.height*placeatscreenheightratio)); for(int = 1; <= numberofframes; i++) { char szname[50] = {0}; sprintf(szname, "%s%i.png",framename.c_str(),i); ccspriteframe* frame = animcache->spriteframebyname(szname); spriteframes->addobject(frame); } ccanimation *animation = ccanimation::createwithspriteframes(spriteframes,0.05f); animation->retain(); animation->setdelayperunit(0.08f);// 0.05f ccsequence *seq=ccsequence::createwithtwoactions(ccanimate::create(animation), cccallfunco::create(animation,callfunco_selector(gamelayer::animationfinished),(ccobject*)_animplaybatchnode)); _animplayfirstsprite->runaction(seq); spriteframes->release(); animation->release(); } void gamelayer::animationfinished(ccobject *sender){ ccspritebatchnode *animbatchnode = (ccspritebatchnode*) sender; animbatchnode->removeallchildrenwithcleanup(true); _isanimationalreadyplaying=false; // animbatchnode->removefromparent() , crashes if }
Comments
Post a Comment