// 2nd step
// forward x-axis, check whether collision on x-axis
selfPreAabb.x = selfAabb.x;
otherPreAabb.x = otherAabb.x;
//这里的赋值的目的是什么?为什么下面不直接用selfAabb otherAabb 进行碰撞对比?
//我尝试过取消了x,y轴都取消了这个赋值,直接用selfAabb otherAabb 进行碰撞对比,物体就无法
停留在平台上了,求原因?
if (cc.Intersection.rectRect(selfPreAabb, otherPreAabb)) {
if (this.speed.x < 0 && (selfPreAabb.xMax > otherPreAabb.xMax)) {
this.node.x = otherPreAabb.xMax - this.node.parent.x;
this.collisionX = -1;
}
else if (this.speed.x > 0 && (selfPreAabb.xMin < otherPreAabb.xMin)) {
this.node.x = otherPreAabb.xMin - selfPreAabb.width - this.node.parent.x;
this.collisionX = 1;
}
this.speed.x = 0;
other.touchingX = true;
return;
}