一、cc.tween().then()
中的 call
不执行,可能的原因以下3点:
- 回调函数没有正确传入
then();
- 动画没有正确开始或者被中断了;
- 动画的时间设置有误,导致动画在不可见的帧上执行。
二、案例解析
:
let actions: any[] = []
for (let j = 1; j < this.linePos.length; j++) {
const pos = this.linePos[j]
const time = Math.floor((distances[j - 1] / this.speed) * 10000) / 10000
const action = cc.moveTo(time, pos)
actions.push(action)
const callback = cc.callFunc(() => { this.onPlayerMoving() }, this)
actions.push(callback)
}
let act = actions[0]
if (actions.length > 1) {
act = cc.sequence(actions)
}
//希望player按照act动作进行移动,移动完成后执行this.onPlayerMoved()
cc.tween(this.player).then(act).call(() => {
this.onPlayerMoved()
}).start()
action会回调执行this.onPlayerMoving()函数
onPlayerMoving() {
if (playerBox.intersects(endpointBox)) {
if (this.endpoint.name.indexOf('_touched') == -1) {
DataManager.instance.status = ENUM_GAME_STATUS.UNRUNING
if (this.coinCollected > 0) {
this.resetDraw()
this.endpoint.name = 'endpoint_touched'
this.endpoint.removeFromParent()
DataManager.instance.coins += this.coinCollected
let level = DataManager.instance.level + 1
level = Math.min(level, DataManager.instance.levels)
DataManager.instance.level = level
if (level > DataManager.instance.levelMax) {
DataManager.instance.levelMax = level
//SdkManager.instance.setRank(level)
}
DataManager.instance.save()
//跳转界面
StaticInstance.gameManager.onGameOver(ENUM_GAMEUI_TYPE.WIN)
}
else{
//跳转界面
Sta