主版本(支持渲染版本移动分支至support_engine)

This commit is contained in:
yhh
2021-01-13 13:09:04 +08:00
parent 6699c32f73
commit eca9ba7b82
23 changed files with 607 additions and 2300 deletions

View File

@@ -84,14 +84,6 @@ module es {
}
}
public debugRender(batcher: IBatcher) {
let poly = this.shape as Polygon;
batcher.drawHollowRect(this.bounds, Debug.colliderBounds, 1);
batcher.drawPolygon(this.shape.position, poly.points, Debug.colliderEdge, true, 1);
batcher.drawPixel(this.entity.transform.position, Debug.colliderPosition, 4);
batcher.drawPixel(Vector2.add(this.entity.transform.position, this.shape.center), Debug.colliderCenter, 2);
}
public toString() {
return `[BoxCollider: bounds: ${this.bounds}]`;
}

View File

@@ -40,13 +40,6 @@ module es {
return this;
}
public debugRender(batcher: IBatcher) {
batcher.drawHollowRect(this.bounds, Debug.colliderBounds, 1);
batcher.drawCircle(this.shape.position, (this.shape as Circle).radius, Debug.colliderEdge, 1);
batcher.drawPixel(this.entity.transform.position, Debug.colliderPosition, 4);
batcher.drawPixel(this.shape.position, Debug.colliderCenter, 2);
}
public toString() {
return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]`
}

View File

@@ -114,32 +114,6 @@ module es {
}
public onAddedToEntity() {
if (this._colliderRequiresAutoSizing) {
Insist.isTrue(this instanceof BoxCollider || this instanceof CircleCollider, "只有框和圆的碰撞器可以自动创建");
let renderable = this.entity.getComponent<RenderableComponent>(RenderableComponent);
if (renderable == null)
console.warn("Collider没有形状也没有RenderableComponent。不知道如何确定它的大小。");
if (renderable != null) {
let renderableBounds = renderable.bounds.clone();
// 我们在这里需要大小*反比例因为当我们自动调整Collider的大小时它需要没有一个缩放的Renderable
let width = renderableBounds.width / this.entity.transform.scale.x;
let height = renderableBounds.height / this.entity.transform.scale.y;
if (this instanceof CircleCollider) {
this.radius = Math.max(width, height) * 0.5;
// 获取Renderable的中心将其转移到本地坐标并将其作为我们碰撞器的localOffset
this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position);
} else if (this instanceof BoxCollider) {
this.width = width;
this.height = height;
this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position);
}
}
}
this._isParentEntityAddedToScene = true;
this.registerColliderWithPhysicsSystem();
}

View File

@@ -23,13 +23,5 @@ module es {
Polygon.recenterPolygonVerts(points);
this.shape = new Polygon(points);
}
public debugRender(batcher: IBatcher) {
let poly = this.shape as Polygon;
batcher.drawHollowRect(this.bounds, Debug.colliderBounds, 1);
batcher.drawPolygon(this.shape.position, poly.points, Debug.colliderEdge, true, 1);
batcher.drawPixel(this.entity.transform.position, Debug.colliderPosition, 4);
batcher.drawPixel(this.shape.position, Debug.colliderCenter, 2);
}
}
}