objective c - cocos2d v3 exception thrown removing sprite from scene -


so im trying make tower defense game, (towers shoot bullets @ advancing enemies), problem when try remove bullet scene after hit enemy, throws exception, no error in debugger.

here code:

-(void)shootweapon { ccsprite * bullet = [ccsprite spritewithimagenamed:@"snowball.png"]; [thegame addchild:bullet]; [bullet setposition:mysprite.position];//todo offset snowball right of tower [bullet runaction:[ccactionsequence actions:[ccactionmoveto actionwithduration:0.3      position:chosenenemy.mysprite.position],[ccactioncallfunc actionwithtarget:self    selector:@selector(damageenemy)],[ccactioncallfunc actionwithtarget:self    selector:@selector(removebullet:)], nil]];  } -(void)removebullet:(ccsprite *)bullet { [bullet.parent removechild:bullet cleanup:yes]; }  -(void)damageenemy { [chosenenemy getdamaged:damage]; } 

if has idea why going on, appreciated.

cheers

the bullet not being passed, hence exception on removebullet: method.

this line problem:

[ccactioncallfunc actionwithtarget:self                           selector:@selector(removebullet:)] 

add breakpoint [bullet.parent removechild:bullet cleanup:yes]; , po bullet on debugger , nil.

my solution use block action, example:

ccaction *blockaction = [ccactioncallblock actionwithblock:^{         [bullet removefromparentandcleanup:yes];     }]; 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -