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();
}
这是小球的回收和移动代码,移动的缓动没有采用对象池呃