有没有人可以帮我在碰撞回调延迟后移除形状和体形?
通过使用cpSpaceAddPostStepCallback(cpPostStepFunc,(PostStepRemove)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;
}有没有人可以帮我写一些示例代码。谢谢
发布于 2010-11-26 22:31:46
我还没有试过这个,但它应该可以工作。在碰撞处理程序中,将动画作为序列的一部分踢开,然后将postStepCallback作为序列中的最后一项执行:
CCSequence *finalSeq = [CCSequence actions:[CCAnimate actionWithAnimation:sapusAnim restoreOriginalFrame:NO],
[CCCallFunc actionWithTarget:self selector:@selector(removeCpShapeAndBody)], nil];
[sapusSprite1 runAction:finalSeq];然后创建一个名为removeCPShapeAndBody的方法,该方法将调用cpSpaceAddPostStepCallback。
https://stackoverflow.com/questions/4144474
复制相似问题