修复box因缺少初始化报错问题
This commit is contained in:
@@ -3,6 +3,24 @@ class Box extends Polygon {
|
||||
public width: number;
|
||||
public height: number;
|
||||
|
||||
constructor(width: number, height: number){
|
||||
super(Box.buildBox(width, height), true);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
private static buildBox(width: number, height: number): Vector2[]{
|
||||
let halfWidth = width / 2;
|
||||
let halfHeight = height / 2;
|
||||
let verts = new Array(4);
|
||||
verts[0] = new Vector2(-halfWidth, -halfHeight);
|
||||
verts[1] = new Vector2(halfWidth, -halfHeight);
|
||||
verts[2] = new Vector2(halfWidth, halfHeight);
|
||||
verts[3] = new Vector2(-halfWidth, halfHeight);
|
||||
|
||||
return verts;
|
||||
}
|
||||
|
||||
public updateBox(width: number, height: number){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
|
||||
@@ -14,9 +14,11 @@ class Polygon extends Shape {
|
||||
}
|
||||
public isBox: boolean;
|
||||
|
||||
constructor(vertCount: number, radius: number) {
|
||||
constructor(points: Vector2[], isBox?: boolean){
|
||||
super();
|
||||
this.setPoints(Polygon.buildSymmertricalPolygon(vertCount, radius));
|
||||
|
||||
this.setPoints(points);
|
||||
this.isBox = isBox;
|
||||
}
|
||||
|
||||
private buildEdgeNormals(){
|
||||
@@ -42,8 +44,10 @@ class Polygon extends Shape {
|
||||
this.points = points;
|
||||
this.recalculateCenterAndEdgeNormals();
|
||||
|
||||
this._originalPoints = new Array(this.points.length);
|
||||
this.points.forEach(point => this._originalPoints.push(point));
|
||||
this._originalPoints = [];
|
||||
for (let i = 0; i < this.points.length; i ++){
|
||||
this._originalPoints.push(this.points[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public collidesWithShape(other: Shape){
|
||||
|
||||
Reference in New Issue
Block a user