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

62 lines
2.3 KiB
TypeScript
Raw Normal View History

2020-07-23 09:10:27 +08:00
module es {
export class CircleCollider extends Collider {
/**
* CircleCollider
* 使RenderableComponentCircleCollider
* RenderableComponent有一个0,01.5f * renderable.width的CircleCollideroriginNormalied为中心除以缩放尺寸来偏移原点
2020-07-23 09:10:27 +08:00
*
* @param radius
*/
2021-05-27 18:32:38 +08:00
constructor(radius: number = 1) {
2020-07-23 09:10:27 +08:00
super();
this.shape = new Circle(radius);
2021-05-27 18:32:38 +08:00
if (radius == 1) {
this._colliderRequiresAutoSizing = true;
}
2020-07-23 09:10:27 +08:00
}
2020-07-28 16:25:20 +08:00
public get radius(): number {
return (this.shape as Circle).radius;
}
public set radius(value: number) {
this.setRadius(value);
}
2020-07-23 09:10:27 +08:00
/**
*
* @param radius
*/
public setRadius(radius: number): CircleCollider {
this._colliderRequiresAutoSizing = false;
2020-07-23 09:10:27 +08:00
let circle = this.shape as Circle;
if (radius != circle.radius) {
circle.radius = radius;
circle._originalRadius = radius;
this._isPositionDirty = true;
if (this.entity != null && this._isParentEntityAddedToScene)
2020-07-23 09:10:27 +08:00
Physics.updateCollider(this);
}
return this;
}
2021-05-27 18:32:38 +08:00
public debugRender(batcher: IBatcher) {
batcher.drawHollowRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height, new Color(76, 76, 76, 76), 2);
batcher.end();
batcher.drawCircle(this.shape.position, this.radius, new Color(139, 0, 0), 2);
batcher.end();
batcher.drawPixel(this.entity.transform.position, new Color(255, 255, 0), 4);
batcher.end();
batcher.drawPixel(this.shape.position, new Color(255, 0, 0), 2);
batcher.end();
}
2020-07-23 09:10:27 +08:00
public toString() {
return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]`
}
}
2020-07-23 09:10:27 +08:00
}