我根据碰撞检测把两个物体的速度全都设置为0,可以同步,但是有个问题,我这ground就是跑酷类游戏的背景地板,第一个ground已经在屏幕外,我现在想设置第一个ground的位置在第二个ground的右边,达到无缝连接。我setposition无效,改变不了位置。
for (let j = 0; j < this.mapArray.length; j++) {
const map:Node = this.mapArray[j];
const mapRigid:RigidBody2D = map.getComponent(RigidBody2D);
mapRigid.linearVelocity = v2(0, 0);
}
for (let k = 0; k < this.mapArray.length; k++) {
const map:Node = this.mapArray[k];
const map1Transform: UITransform = map.getComponent(UITransform);
console.log("map.position.x = ", map.position.x + map1Transform.width*0.5);
console.log("left x = ", -this.viewSize.width*0.5);
if (map.position.x + map1Transform.width*0.5 <= -this.viewSize.width*0.5) {
let nextMap:Node = this.mapArray[1];
if (k == 1) {
nextMap = this.mapArray[0];
}
const mapTransform: UITransform = nextMap.getComponent(UITransform);
map.setPosition(nextMap.position.x + mapTransform.width, 0, 0);
console.log("map x = ", nextMap.position.x + mapTransform.width);
}
}