How to destroy sprite with body by tag COCOS2D Box2D -
ccsprite* sprite = (ccsprite*)[self getchildbytag:5];
[self removechildbytag:5 cleanup:yes];
the code in question used remove sprite tag:5, need check
- (void)cctouchesended:(nsset *)touches withevent:(uievent *)event { //getting touch locations uitouch *touch = [touches anyobject]; cgpoint location = [touch locationinview: [touch view]]; location = [[ccdirector shareddirector] converttogl: location]; //converting cocos2d positioning b2vec2 locationworld = b2vec2(location.x/ptm_ratio, location.y/ptm_ratio); //getting body list world (b2body* b = world->getbodylist(); b; b = b->getnext()) { //getting fixture bodies b2fixture *bf1 = b->getfixturelist(); //checking whether fixture contains touch location! if (bf1->testpoint(locationworld)) { //if yes assigning user data sprite tempsprite ccsprite *tempsprite = (ccsprite *) b->getuserdata(); //checking whether user data sprite tag 5 if (tempsprite .tag==5) { //if yes remove sprite & body! [self removechild:tempsprite cleanup:yes]; world->destroybody(b); } } } }
Comments
Post a Comment