typescript - 有没有办法确保 runAction(animation) 运行到完成?
问题描述
I have a hand of cards that moves left or right when a selected card is hovered above them.
一切正常,除非移动太快并且多次调用卡片动画而前一个动作没有完成运行。
我在 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--;
}
}
.
.
.
}
解决方案
我找到了一个解决方案,即在卡片分类之前制作 stopAllActions() !
推荐阅读
- excel - 需要帮助将公式插入可变长度列
- python-3.x - Python根据变量名创建对象
- swift - 我的 Swift 代码中的预期声明错误试图从文本字段中获取数字
- c# - C# WinForms ListView 不显示项目/文件/文件夹
- asynchronous - 如何设置 Labview/myRIO 以通过 UART 进行通信
- kubernetes - /healthz 端点检查失败的返回码
- python - 如何将用户链接到一个组,用户只能在Django中查看该组中其他用户的帖子
- android - 如何在 Android 中使用 Firebase?
- python - 我们如何在 Google Colab 上使用 pygame?
- java - 如何将 Java 异常映射到 HTTP 状态代码?