首先我在一个Canvas下见了2个节点,A和B;,A和B都添加了碰撞组件
我在A上加脚本,我鼠标监听点击屏幕左下打印this.node.y,是负值,
但是同样位置我把B放在这里,让A下落碰到B打印selfAabb.yMax,碰撞体的y最大坐标,结果是好几百??
Canvas是以中心为(0,0)的,第一个应该没错
第二个为什么是好几百呢,那个yMax是以什么为标准的;
碰撞部分代码我发上:其实就是cocoscreator自带的样例里面的一段
var otherAabb = other.world.aabb;
var otherPreAabb = other.world.preAabb.clone();
var selfAabb = self.world.aabb;
var selfPreAabb = self.world.preAabb.clone();
selfPreAabb.x = selfAabb.x;
otherPreAabb.x = otherAabb.x;
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;
}
selfPreAabb.y = selfAabb.y;
otherPreAabb.y = otherAabb.y;
if (cc.Intersection.rectRect(selfPreAabb, otherPreAabb)){
if (this.speed.y < 0 && (selfPreAabb.yMax > otherPreAabb.yMax)){//从上向下掉
this.node.y = otherPreAabb.yMax-this.node.parent.y-5;
this.jumping = false;
cc.log(selfAabb.yMax);
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;
}