在CCActionSequence之后使对象消失

时间:2015-01-21 14:44:34

标签: ios objective-c iphone cocos2d-iphone

我正在制作iOS游戏,其中一部分包括一个随机生成的大理石,沿路径移动并在完成所述路径后消失。这是我用来产生和移动大理石的原因:

-(void) createMarbleObstacle :(CCTime) randomTimeInterval{
    marbleObj = (Marble *)[CCBReader load: @"Marble"];
    marbleObj.position= _cLnode.position;
    [_contentNode addChild: marbleObj];
    [marbleObj moveMarble:(randomTimeInterval*5) :_bLnode: _aLnode];
}

-(void) moveMarble: (CCTime)interval :(CCNode*)a :(CCNode*)b{
    moveM1 = [CCActionMoveTo actionWithDuration:(interval) position: a.position];
    moveM2 = [CCActionMoveTo actionWithDuration:(interval) position: b.position];

    moveM4 = [CCActionSequence actions:moveM1, moveM2, nil];

    [self runAction: moveM4];
}

然而,我无法弄清楚如何在完成CCActionSequence后让大理石消失。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

moveMarble中为您的序列添加另一个操作:

id clean = [CCActionCallBlock actionWithBlock:^{
   [_contentNode removeChild:marbleObj cleanup:YES];
}];
 moveM4 = [CCActionSequence actions:moveM1, moveM2, clean, nil];  

或类似的东西:)