完善shapeCollision 支持多边形
This commit is contained in:
@@ -29,7 +29,9 @@ abstract class Component {
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract initialize();
|
||||
public initialize(){
|
||||
|
||||
}
|
||||
|
||||
public onAddedToEntity(){
|
||||
|
||||
|
||||
@@ -3,7 +3,10 @@ abstract class Collider extends Component{
|
||||
public physicsLayer = 1 << 0;
|
||||
public isTrigger: boolean;
|
||||
public registeredPhysicsBounds: Rectangle;
|
||||
public shouldColliderScaleAndRotationWithTransform = true;
|
||||
public collidesWithLayers = Physics.allLayers;
|
||||
|
||||
public _localOffsetLength: number;
|
||||
protected _isParentEntityAddedToScene;
|
||||
protected _isPositionDirty = true;
|
||||
protected _isRotationDirty = true;
|
||||
@@ -32,6 +35,7 @@ abstract class Collider extends Component{
|
||||
if (this._localOffset != offset){
|
||||
this.unregisterColliderWithPhysicsSystem();
|
||||
this._localOffset = offset;
|
||||
this._localOffsetLength = this._localOffset.length();
|
||||
this._isPositionDirty = true;
|
||||
this.registerColliderWithPhysicsSystem();
|
||||
}
|
||||
@@ -51,6 +55,33 @@ abstract class Collider extends Component{
|
||||
this._isColliderRegisterd = false;
|
||||
}
|
||||
|
||||
public initialize() {
|
||||
public overlaps(other: Collider){
|
||||
return this.shape.overlaps(other.shape);
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: ComponentTransform){
|
||||
switch (comp){
|
||||
case ComponentTransform.position:
|
||||
this._isPositionDirty = true;
|
||||
break;
|
||||
case ComponentTransform.scale:
|
||||
this._isPositionDirty = true;
|
||||
break;
|
||||
case ComponentTransform.rotation:
|
||||
this._isRotationDirty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (this._isColliderRegisterd)
|
||||
Physics.updateCollider(this);
|
||||
}
|
||||
|
||||
public onEnabled(){
|
||||
this.registerColliderWithPhysicsSystem();
|
||||
this._isPositionDirty = this._isRotationDirty = true;
|
||||
}
|
||||
|
||||
public onDisabled(){
|
||||
this.unregisterColliderWithPhysicsSystem();
|
||||
}
|
||||
}
|
||||
4
source/src/ECS/Components/Physics/ITriggerListener.ts
Normal file
4
source/src/ECS/Components/Physics/ITriggerListener.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
interface ITriggerListener {
|
||||
onTriggerEnter(other: Collider, local: Collider);
|
||||
onTriggerExit(other: Collider, local: Collider);
|
||||
}
|
||||
@@ -212,6 +212,10 @@ class Entity {
|
||||
return this.components.getComponent(type, false) as T;
|
||||
}
|
||||
|
||||
public getComponents<T extends Component>(type): T[]{
|
||||
return this.components.getComponents<T>(type);
|
||||
}
|
||||
|
||||
public removeComponentForType<T extends Component>(type){
|
||||
let comp = this.getComponent<T>(type);
|
||||
if (comp){
|
||||
|
||||
@@ -120,6 +120,23 @@ class ComponentList {
|
||||
return null;
|
||||
}
|
||||
|
||||
public getComponents<T extends Component>(type): T[]{
|
||||
let components = [];
|
||||
for (let i = 0; i < this._components.length; i ++){
|
||||
let component = this._components[i];
|
||||
if (component instanceof type)
|
||||
components.push(components);
|
||||
}
|
||||
|
||||
for (let i = 0; i < this._componentsToAdd.length; i ++){
|
||||
let component = this._componentsToAdd[i];
|
||||
if (component instanceof type)
|
||||
components.push(components);
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
public update(){
|
||||
this.updateLists();
|
||||
for (let i = 0; i < this._components.length; i ++){
|
||||
|
||||
Reference in New Issue
Block a user