2020-07-23 09:10:27 +08:00
|
|
|
module es {
|
|
|
|
|
export class CircleCollider extends Collider {
|
|
|
|
|
/**
|
|
|
|
|
* 创建一个有半径的圆
|
|
|
|
|
*
|
|
|
|
|
* @param radius
|
|
|
|
|
*/
|
2020-11-23 16:05:06 +08:00
|
|
|
constructor(radius: number) {
|
2020-07-23 09:10:27 +08:00
|
|
|
super();
|
2020-07-09 15:11:30 +08:00
|
|
|
|
2020-11-23 16:05:06 +08:00
|
|
|
this.shape = new Circle(radius);
|
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 {
|
|
|
|
|
let circle = this.shape as Circle;
|
|
|
|
|
if (radius != circle.radius) {
|
|
|
|
|
circle.radius = radius;
|
|
|
|
|
circle._originalRadius = radius;
|
2020-07-09 15:11:30 +08:00
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
if (this.entity && this._isParentEntityAddedToScene)
|
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
2020-07-09 15:11:30 +08:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
public toString() {
|
|
|
|
|
return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]`
|
|
|
|
|
}
|
2020-07-09 15:11:30 +08:00
|
|
|
}
|
2020-07-23 09:10:27 +08:00
|
|
|
}
|