Is there a way to make sure animation runs until finish?

I have a hand of cards that moves left or right when a selected card is hovered above them.

everything works fine except when movement is too fast and a card animation is called multiple times without the previous action has finished running.

im using typescript and not sure where i should make a topic.

my script looks like this.

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--;

    }
}
.
.
.
}

what are you trying to achieve? video could help :slight_smile:

1 Like

im not sure how to upload video here but here goes.

this is what i wanted, it is okay when done slowly

(https://webmshare.com/4Br44)

here it goes a little farther to the right when i release card before the other card animation has not finished

(https://webmshare.com/play/BjGBO)

pardon my english, it is not my mother tongue.

videos aren’t working for me :frowning:

1 Like

try youtube

1 Like

how about now, can you open the links?

if you absolutely have to use actions… use moveTo this will make sure you get to the right point each time.

call ->stopAllActions to stop the previously running … then recalculate the time required to reach the point. and start the action again. this will work smoothly

1 Like

yes the links work… nice video names :slight_smile:

1 Like

gosh, thanks. this works! stopAllAction() works. Im new to cocos and typescript or any game development for that matter. Thank you very much!