关于Tween组件使用疑问

image
像这样写会一直向右边移动,请问一下,我想每次移动一个单位后改变方向要怎么处理呢?就比如先向右然后改变这个dir,一直根据我修改的这个dir移动下去,我试了在oncomplete重设dir但是没有效果,请问各位这个该怎么处理呢?

image

不知道这样是不是一想要的,你的代码不行是因为tween的动作在第一次赋值的时候就已经确定了(所以后面修改没用)

以下是repeateForever的源码
/**
* @en
* Add an repeat forever action.
* This action will integrate before actions to a sequence action as their parameters.
* @zh
* 添加一个永久重复 action,这个 action 会将前一个动作作为他的参数。
* @method repeatForever
* @param {Tween} embedTween 可选,嵌入 Tween
*/
repeatForever (embedTween?: Tween): Tween {
const actions = this._actions;
let action: any;

    if (embedTween instanceof Tween) {
        action = embedTween._union();
    } else {
        action = actions.pop();
    }

    actions.push(repeatForever(action as ActionInterval));
    return this;
}

谢谢,我研究一下哈,主要是想在移动到一个单位后,我能在回调里设置dir值,修改下次移动的方向。

我那个代码就可以在call回调里面调整dir

我看每个缓动有个OnComplete这个参数,一个缓动动作完成需要处理的逻辑在这个OnComplete和Call里面写是不是效果一样的?

。。。。update它不香吗?3.0难道取消了update?

1赞

tween里面传递过去的prop又没有重新拷贝,你onComplete修改dir的时候只修改dir的属性就可以了,如果重新给dir赋一个向量,那肯定不会变化了啊。

tween(this.node)

.by(1, {position:this.dir},{onComplete: () => {

    this.dir.x = -this.dir.x

}})

.repeatForever()

.start()

感谢感谢感谢