任何人都可以在碰撞回调延迟后帮助我移除形状和身体。
通过使用 cpSpaceAddPostStepCallback(sapce, (cpPostStepFunc)postStepRemove, blockShape, NULL); 我可以安全地删除形状。但是在调用该函数之前我需要一些延迟。一旦检测到碰撞,我就会播放动画。在代码的末尾,我需要删除形状。谁能帮我提供一些示例代码。我写的代码如下。
int collisionSapusBlock(cpArbiter *arb, struct cpSpace *sapce, void *data)
{
cpShape *sapusShape, *blockShape;
cpArbiterGetShapes(arb, &sapusShape, &blockShape);
cpBody *BlockBody = blockShape->body;
cpBody *sapusBody = sapusShape->body;
CCNode *parent = (CCNode*)data;
if (cpvlength(sapusBody->v) > 45)
{
NSLog(@"Collision2 called %f",cpvlength(sapusBody->v));
CCSprite *sprite = blockShape->data;
[parent removeChild:sprite cleanup:YES];
///////
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Block2.plist"];
CCSpriteBatchNode *sheet1 = [CCSpriteBatchNode batchNodeWithFile:@"Block2.png" capacity:2];
[parent addChild:sheet1];
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
CCSprite *sapusSprite1 = [[CCSprite alloc] initWithSpriteFrameName:@"Block2001.png"];
CCAnimation *sapusAnim = [[CCAnimation alloc] initWithName:@"select" delay:0.15f];
[sapusAnim addFrame:[cache spriteFrameByName:@"Block2001.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"Block2002.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"Block2003.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"Block2004.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"Block2005.png"]];
[sapusAnim addFrame:[cache spriteFrameByName:@"Block2006.png"]];
[sapusSprite1 addAnimation: sapusAnim];
[sheet1 addChild:sapusSprite1];
CCAnimate *animate = [CCAnimate actionWithAnimation: sapusAnim restoreOriginalFrame:NO];
[sapusSprite1 runAction:animate];
blockShape->data = sapusSprite1;
/////here after playing the animation i need to delete the blockShape. Help plzzz
}
return 1;
}
谁能帮我提供一些示例代码。谢谢