Typescript 有没有办法确保runAction(动画)一直运行到完成?

Typescript 有没有办法确保runAction(动画)一直运行到完成?,typescript,cocos2d-x,Typescript,Cocos2d X,我有一手牌,当选定的牌悬停在上面时,它会向左或向右移动 除了移动太快,并且在前一个动作未完成的情况下多次调用卡片动画外,其他操作都可以正常工作 我在CocosCreatorV1.9中使用typescript 我的脚本看起来像这样 onMoveCard(): void { var i: number = 0; // animation to move left or right var moveRight: cc.ActionInterval = cc.moveBy(0.

我有一手牌,当选定的牌悬停在上面时,它会向左或向右移动

除了移动太快,并且在前一个动作未完成的情况下多次调用卡片动画外,其他操作都可以正常工作

我在CocosCreatorV1.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--;

        }
    }
.
.
.
}
onMoveCard():void{
变量i:数值=0;
//要向左或向右移动的动画
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));
对于(i=0;i DragCard.originalX-(DragCard.currentHandSpacing*(i+2))){
if(DragCard.countLeft==i){
//阻止条件语句超出数组边界
如果(DragCard.currentHandIndex-(i+1)>=0){
Hand.handCards[DragCard.currentHandIndex-(i+1)].runAction(moveRight.clone());
//克隆以使每个动画独立运行
DragCard.countLeft++;
}
}
}
//如果卡移回右侧,请将下一张卡移到左侧
if(DragCard.countLeft==(i+1)&&this.node.x>DragCard.originalX-(DragCard.currentHandspace*i)){
Hand.handCards[DragCard.currentHandIndex-(i+1)].runAction(moveLeft.clone());
DragCard.countLeft--;
}
}
.
.
.
}

我找到了一个解决方案,就是在卡片分类之前进行stopAllActions()

您好,欢迎来到Stack Overflow,希望您喜欢这个网站。请包括您的代码,甚至更好的一个!