关于runAction的传入参数问题

    let delayTime = 0;
    let action1 = cc.sequence(
            action,
            cc.callFunc(() => {
                delayTime += 1;
            }),
            cc.delayTime(delayTime)
        )
    this.node.runAction(cc.repeat(action1,10));

大致问题就是,这个delay time需要动态获取,他是根据repeat的次数改变的。这种情况该怎么写呢?

建议使用tween

用tween怎么写呢,我用tween试了试,这个delaytime还是不会变

this.delaytime = 1;
let than = this;
cc.tween(this.node)
.call(() => {
cc.log(new Date())
than.delaytime += 1;
cc.log(than.delaytime)
})
.delay(than.delaytime)
.union()
.repeat(_cnt)
.start()

delaytime一直都是1s

image

希望我没有猜错你的动画意思

好像有点道理,回避了repeat的问题。但是假设需求是repeat Forever咋办。。。虽然我暂时没有这个需求

这个好像也没解决问题,这个会把这10次都执行吧

需求其实就是,一个逻辑执行后停1s,再执行这段逻辑,然后停2s再执行逻辑,停的时长是递增的

那你自己写一个递归就行了 每次 递归等待时间 + 1就行了

        this.delaytime = 5;
        let action = cc.sequence(
            cc.callFunc(() => {
                cc.log(new Date())
                this._fingerObj = action_obj.shift();
          
                if (action_obj.length > 0) {
           
                    this.delaytime +=1;
                    cc.log(this.delaytime)
                }
            }),
            cc.delayTime(this.delaytime),
            cc.callFunc(() => {
                if (action_obj.length > 0) {
                    this.node.stopAllActions();
                    this.node.runAction(action);
                }
            })
        )
        this.node.runAction(action);

大哥的意思是这样递归吗,但是结果delayTime依旧是5s,我不理解

start () {

    this.test();

}

// update (dt) {}

test()

{

    console.error("延迟时间",this.detaTime);

    cc.tween(this.node).to(1,{x : 0}).delay(this.detaTime).call(()=>

    {

        this.detaTime += 1;

        this.test();

    }).start();

}

}image

你传入不能只传一次 他只会保存你的值 不会保存你的引用 你应该多次调用递归

用runAction 也是一样的用法 只是把tween换成runAction 递归多次调用 到达一个条件跳出去就行了

了解了,多谢大哥。