【问题标题】:Is there a way to make sure runAction(animation) runs until finish?有没有办法确保 runAction(animation) 运行到完成?
【发布时间】:2018-05-04 07:16:21
【问题描述】:

我有一只左或右移动时的卡片,当它们在它们上方悬停时,左右移动。

一切正常,除非移动太快并且在前一个动作没有完成运行的情况下多次调用卡片动画。

我在 cocos creator v1.9 中使用 typescript。

我的脚本是这样的。

onMoveCard(): void {

    var i: number = 0;
    // animation to move left or right
    var moveRight: cc.ActionInterval = cc.moveBy(0.1, cc.p(DragCard.currentHandSpacing, 0));
    var moveLeft: cc.ActionInterval = cc.moveBy(0.1, cc.p(-DragCard.currentHandSpacing, 0));

    for (i = 0; i <= Hand.handCards.length - 2; i++) {

        // if card moved one spacing to the left, move the previous card to the right
        if (this.node.x < DragCard.originalX - (DragCard.currentHandSpacing * (i + 1))
            && this.node.x > DragCard.originalX - (DragCard.currentHandSpacing * (i + 2))) {

            if (DragCard.countLeft === i) {
                // prevent conditional statement goes out of array bounds

                if (DragCard.currentHandIndex - (i + 1) >= 0) {
                    Hand.handCards[DragCard.currentHandIndex - (i + 1)].runAction(moveRight.clone()); 
                    // clone so that each animation is run independently
                    DragCard.countLeft++;
                }
            }
        }
        // if the card moved back to the right, move the next card to the left
        if (DragCard.countLeft === (i + 1) && this.node.x > DragCard.originalX - (DragCard.currentHandSpacing * i)) {

            Hand.handCards[DragCard.currentHandIndex - (i + 1)].runAction(moveLeft.clone());
            DragCard.countLeft--;

        }
    }
.
.
.
}

【问题讨论】:

标签: typescript cocos2d-x


【解决方案1】:

我找到了一个解决方案,即在卡片排序之前执行 stopAllActions()!

【讨论】:

    最近更新 更多