CCSprite* sprite = (CCSprite*)[self getChildByTag:5];
[self removeChildByTag:5 cleanup:YES];
问问题
1051 次
2 回答
-1
问题中的代码仅用于删除带有标签的精灵:5,您需要检查
- (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 to cocos2D positioning b2Vec2 locationWorld = b2Vec2(location.x/PTM_RATIO, location.y/PTM_RATIO); //Getting body list from world
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
{ //Getting Fixture from the bodies
b2Fixture *bf1 = b->GetFixtureList(); //Checking whether the fixture contains touch location!
if (bf1->TestPoint(locationWorld))
{ //If YES assigning user data to a sprite tempSprite
CCSprite *tempSprite = (CCSprite *) b->GetUserData();
//Checking whether the user data sprite tag is 5
if (tempSprite .tag==5)
{
//If YES then remove the sprite & the body!
[self removeChild:tempSprite cleanup:YES];
world->DestroyBody(b);
}
}
}
}
于 2013-04-08T12:02:07.433 回答
-1
//first get sprite by tag
b2Body *sprite = NULL;
//then give body to sprite
sprite = [(TRBox2D*)[self getChildByTag:5]body];
//then destroy by following method
_world->DestroyBody(sprite);
[self removeChildByTag:5 cleanup:YES];
于 2013-05-28T14:15:00.997 回答