项目出了一个小问题,有人帮忙看看吗?有偿1K

目前楼主做了一个项目,碰到点小问题
20250927_110344 - Trim (1)

如图所示
我想发射小球和回收小球,但回收小球出现了点问题
位置有时候会出现空位置。
我的目前的实现方式是设置两个数组A和B,
小球从数组A发射出来,碰到下面的管道后push到B
然后小球通过在B中的数组下标执行tween动画移动到设定好的位置,
但是发现有时候移动的位置不对。
目前发现从障碍物出现新的小球会打乱原本的数组
因为新的小球是直接push到A数组里面,然后延时一定时间会执行回收操作回收到数组B里面
有时候小球没经过任何延时就直接回到数组B里面了
甚至没执行tween动画移动到设定好的位置,导致位置不正确几个小球会叠加在一起
后面的位置又是正常的
然后中间就空了几个位置。

目前猜测的原因是某些操作导致tween动画的执行不正确

如果可以解决这个问题可以私聊楼主,我发相关代码给你

  • Creator 版本: 3.7.3

我猜你是用了对象池 然后缓动直接调用结束了导致的 可以查一下

跟我想的一样

reclaimBall(ball: Node) {

    // console.log("回收",this.nodes.length,this.nodesA.length,this.nodesB.length,this.nodes,this.nodesA,this.nodesB)

    if (!ball.getComponent(Ball).canReclaim) return;

   

    if (this.BallsID == 1) {

        this.nodesB.push(ball);

        ball.getComponent(Ball).State = GameState.RESULT;

        this.reclaimMove(ball, this.nodesB.length - 1);

        if (this.nodesB.length == this.nodes.length) {

            // console.log("从A到B",this.nodes.length,this.nodesA.length,this.nodesB.length)

            this.nodesA.length = 0;

            this.nodes = this.nodesB;

            this.BallsID = 2;

        }

    } else {

        this.nodesA.push(ball);

        ball.getComponent(Ball).State = GameState.RESULT;

        this.reclaimMove(ball, this.nodesA.length - 1);

        if (this.nodes.length == this.nodesA.length) {

            //  console.log("从B到A",this.nodes.length,this.nodesA.length,this.nodesB.length)

            this.nodesB.length = 0;

            this.nodes = this.nodesA;

            this.BallsID = 1;

        }

    }

}

reclaimMove(ball: Node, index: number) {

    let t = tween(ball);

    if (index > this.pathPoints.length - 1) {

        let Pos = this.pathPoints[this.pathPoints.length - 1];

        t = t.to(0.5, { position: v3(Pos.x + Math.random() - 0.4, Pos.y, Pos.z) })

            .call(() => {

                ball.getComponent(Ball).quivering();

                if (index == this.nodes.length - 1) {

                    this.refreshState();

                }

            });

        t.start();

        return;

    }

    for (let i = this.pathPoints.length - 1; i >= index; i--) {

        t = t.to(0.06, { position: this.pathPoints[i] });

    }

    t.call(() => {

        //console.log("所有tween执行完毕!", index);

        ball.getComponent(Ball).quivering();

        if (index == this.nodes.length - 1) {

            this.refreshState();

        }

    })

    t.start();

}

这是小球的回收和移动代码,移动的缓动没有采用对象池呃

那得看到运行效果然后再结合项目代码去研究吧 这只言片语看不懂啊

每次执行tween之前,执行一下 Tween.stopAllByTarget(node),回收到对象池之前,也执行一下Tween.stopAllByTarget试试

我看了他的描述, 猜测问题就是出在这里

我直接给说结论。你这种情况下,想要计算小球的位置就是自己每一帧去算。把是所有的tween去掉。保证不容出错。