CCActionSequence/CCActionDelay 不拖延每一个动作?

CCActionSequence/CCActionDelay not delaying each action?

我有一个创建 CCSprite 并将其移动到屏幕上的函数:

func fireWeapon(target: CGPoint) {
    let projectile = CCBReader.load("Projectile") as! CCSprite
    projectile.position = player.position;
    self.addChild(projectile);

    let moveAction = CCActionMoveTo(duration: 1, position: target);
    let delayAction = CCActionDelay(duration: 1);
    let removeAction = CCActionCallBlock(projectile.removeFromParentAndCleanup(true));

    projectile.runAction(CCActionSequence(array: [moveAction, delayAction, removeAction]));
}

我正在尝试通过 运行 removeFromParentAndCleanup() 与移动动作一起完成移动动作后清理精灵。然而,每个动作都在序列中紧接着彼此立即触发,没有延迟。精灵在创建后立即被清理。为什么延迟不起作用?我试过使用和不使用 CCDelay 操作,我得到了相同的结果。

解决了我自己的问题。事实证明我对 CCActionCallBlock() 使用了错误的语法,你必须将你的代码块实际封装在一个 void 函数中,如下所示:

func fireWeapon(target: CGPoint) {
    let projectile = CCBReader.load("Projectile") as CCNode
    projectile.position = player.position;
    self.addChild(projectile);

    let moveAction = CCActionMoveTo(duration: 1, position: target);
    let delayAction = CCActionDelay(duration: 3);
    let removeAction = CCActionCallBlock { () -> Void in
        projectile.removeFromParentAndCleanup(true);
    }
    projectile.runAction(CCActionSequence(array: [moveAction, delayAction, removeAction]));
}

希望这对很多人有帮助,因为我看到很多人遇到这个问题,但他们从来没有得到解决方案。