关于物理刚体的透明区域的判断

物理刚体有可能会是一个多边形,这样使用cc.PhysicsPolygonCollider可以勾勒出多边形的形状,但是要在这个多边形上添加点击事件,我使用的是cc.Node的on监听了TOUCH_END事件,这样就会存在透明区域点击也会触发事件回调,尝试了多种办法,包括cc.Intersection.pointInPolygon,但是貌似还是不行,请问下有没有解决方案能分享一下的吗?
下面是我写的判断方法,但是不行。

let hitTest = (pos: cc.Vec2) => {

   let hitPos = body.convertToNodeSpaceAR(pos);

   let nodeSize = body.getContentSize();

   if (body.getComponent(cc.PhysicsBoxCollider)) {

       return true;

   } else {

       let polygonCollider = body.getComponent(cc.PhysicsPolygonCollider);

       if (polygonCollider) {

           hitPos.x -= nodeSize.width / 2;

           hitPos.y -= nodeSize.height / 2;

           let bool = cc.Intersection.pointInPolygon(hitPos, polygonCollider.points);

           return bool;

       }

   }

}

使用 let imgObj = sprite.spriteFrame.getTexture().getHtmlElementObj(); 这样取到的imgObj为什么是一个undefined?而且这种方法应该只支持web,有没有更好的方法?

会不会是hitPos和polygonCollider.points的点不在同一个坐标系导致的。

这个我也考虑了,但是貌似polygonCollider.points得到的坐标集合就是body的局部坐标系,而我hitPos也是将点击的世界坐标转化为body的局部坐标系的。

image 试试这样呢

this.collider.world.points,这个world属性我愣是没找到。。。

image

我使用的是物理引擎的cc.PhysicsPolygonCollider组件,他继承于 cc.PhysicsCollider,关于这个组件它的points属性应该就是它的多边形顶点数组,

sprite.spriteFrame.getTexture().getHtmlElementObj(),这个为什么获取到的是一个undefined呢?有人能解释一下吗?