c++ - remove a sprite in cocos2d-x -


i new cocos2d-x.i developing game in xcode using cocos2d-x. in game, have sprite animation(man) , moving obstacles , coins. making collision sprite animation & coins. when 10 coins, adding life(adding sprite life). question when collision happening between sprite animation(man) & obstacles, life should decrease(i mean life sprite should remove) not removed. using following code.

if(coincount%10==0) {   lifecount=lifecount+1; } if(lifecount==1) {  life = ccsprite::create("life.png");  life->setposition( ccp(winwsize/2, winhsize/1.08) );  this->addchild(life, 5); } else if(lifecount==2) {  life1 = ccsprite::create("life.png");  life1->setposition( ccp(winwsize/1.8, winhsize/1.08) );  this->addchild(life1, 5); } else if (lifecount==3) {  life2 = ccsprite::create("life.png");  life2->setposition( ccp(winwsize/1.6, winhsize/1.08) );  this->addchild(life2, 5); }  if (manrect.intersectsrect(obs5rect)) { if(lifecount>=1) {  lifecount=lifecount-1;  this->scheduleonce(schedule_selector(playscene::remove),0.5f); }  void playscene::remove() { if(lifecount==0) {     this->removechild(life, true); } else if(lifecount==1) { this->removechild(life1, true); } else if(lifecount==2) { this->removechild(life2, true); } 

but sprite not removing, when obstacle collide sprite animation(man). please me find solution. thanks.

i think best bet do:

life1->settag(99); // made 99 

and when want remove use removechildbytag(99);


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -