如题,碰撞体检测到碰撞之后会根据碰撞位置给node加一个状态, 目前碰撞位置检测用的是官方的case代码。
代码如下:
// 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();
// 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)) {
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;
}
jumping状态是根据角色是否碰撞和碰撞的位置来判断的,然后另一个方法jump执行时会判断this.jumping的状态来决定是否执行,但是实际调试发现this.jumping的更新太慢了,导致jump的响应总会不流畅,(例如碰撞后立即通过触摸事件来响应jump方法,延迟还是挺高的,当时触摸屏幕时jumping的状态并没有更新,需要隔个半秒左右再点才会跳起来,半秒以上的反馈时间对游戏体验影响很大)目前creator有办法来提高碰撞检测的频率或者其他办法来提高this.jumping的更新速度吗?