修复polygon数组错误 修复emit空注册报错

This commit is contained in:
yhh
2020-06-15 20:08:21 +08:00
parent c3120d791f
commit 5186bc0187
16 changed files with 398 additions and 32 deletions

View File

@@ -1,6 +1,5 @@
///<reference path="./Collider.ts" />
class BoxCollider extends Collider {
public get width(){
return (this.shape as Box).width;
}
@@ -21,4 +20,30 @@ class BoxCollider extends Collider {
return this;
}
public get height(){
return (this.shape as Box).height;
}
public set height(value: number){
this.setHeight(value);
}
public setHeight(height: number){
this._colliderRequiresAutoSizing = false;
let box = this.shape as Box;
if (height != box.height){
box.updateBox(box.width, height);
this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
}
constructor(){
super();
this.shape = new Box(1, 1);
this._colliderRequiresAutoSizing = true;
}
}

View File

@@ -6,12 +6,51 @@ abstract class Collider extends Component{
protected _isParentEntityAddedToScene;
protected _isPositionDirty = true;
protected _isRotationDirty = true;
protected _colliderRequiresAutoSizing;
protected _localOffset: Vector2;
protected _isColliderRegisterd;
public get bounds(): Rectangle {
if (this._isPositionDirty || this._isRotationDirty){
this.shape.recalculateBounds(this);
this._isPositionDirty = this._isRotationDirty = false;
}
return this.shape.bounds;
}
public get localOffset(){
return this._localOffset;
}
public set localOffset(value: Vector2){
this.setLocalOffset(value);
}
public setLocalOffset(offset: Vector2){
if (this._localOffset != offset){
this.unregisterColliderWithPhysicsSystem();
this._localOffset = offset;
this._isPositionDirty = true;
this.registerColliderWithPhysicsSystem();
}
}
public registerColliderWithPhysicsSystem(){
if (this._isParentEntityAddedToScene && !this._isColliderRegisterd){
Physics.addCollider(this);
this._isColliderRegisterd = true;
}
}
public unregisterColliderWithPhysicsSystem(){
if (this._isParentEntityAddedToScene && this._isColliderRegisterd){
Physics.removeCollider(this);
}
this._isColliderRegisterd = false;
}
public initialize() {
}
}