У меня есть рука карт, которая перемещается влево или вправо, когда выбранная карта находится над ними.
все работает нормально, за исключением случаев, когда движение слишком быстрое, и анимация карты вызывается несколько раз без завершения предыдущего действия.
Я использую машинопись в Cocos Creator v1.9.
Мой сценарий выглядит следующим образом.
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--;
}
}
.
.
.
}