Files
esengine/source/src/ECS/Components/Physics/Colliders/PolygonCollider.ts

22 lines
652 B
TypeScript
Raw Normal View History

/**
*
*/
class PolygonCollider extends Collider {
/**
* localOffset的差异为居中
* @param points
*/
constructor(points: Vector2[]){
super();
// 第一点和最后一点决不能相同。我们想要一个开放的多边形
let isPolygonClosed = points[0] == points[points.length - 1];
// 最后一个移除
if (isPolygonClosed)
points.splice(points.length - 1, 1);
Polygon.recenterPolygonVerts(points);
this.shape = new Polygon(points);
}
}