碰撞组件的示例中有这么一段代码:
请问其中的preAabb这个成员是干啥的?我console.log打出来跟aabb是一样的,不知道该怎么用。
谢谢!
onCollisionEnter: function (other, self) {
this.node.color = cc.Color.RED;
this.touchingNumber ++;// 1st step // get pre aabb, go back before collision var otherAabb = other.world.aabb; var otherPreAabb = other.world.preAabb.clone();
var selfAabb = self.world.aabb; var selfPreAabb = self.world.preAabb.clone();
console.log("otherPreAabb: ", otherPreAabb); console.log("selfPreAabb: ", selfPreAabb); // 2nd step // forward x-axis, check whether collision on x-axis selfPreAabb.x = selfAabb.x; otherPreAabb.x = otherAabb.x; console.log("otherPreAabb: ", otherPreAabb); console.log("selfPreAabb: ", selfPreAabb);
if (cc.Intersection.rectRect(selfPreAabb, otherPreAabb)) { console.log("first check"); 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; }
// 3rd step // forward y-axis, check whether collision on y-axis selfPreAabb.y = selfAabb.y; otherPreAabb.y = otherAabb.y;
if (cc.Intersection.rectRect(selfPreAabb, otherPreAabb)) { console.log("second check"); if (this.speed.y < 0 && (selfPreAabb.yMax > otherPreAabb.yMax)) { this.node.y = otherPreAabb.yMax - this.node.parent.y; this.jumping = false; this.collisionY = -1; } else if (this.speed.y > 0 && (selfPreAabb.yMin < otherPreAabb.yMin)) { this.node.y = otherPreAabb.yMin - selfPreAabb.height - this.node.parent.y; this.collisionY = 1; } this.speed.y = 0; other.touchingY = true; } },
