整理ecs框架
This commit is contained in:
@@ -3,6 +3,9 @@ class Circle extends Shape {
|
||||
public radius: number;
|
||||
public _originalRadius: number;
|
||||
public center = new Vector2();
|
||||
public get position(){
|
||||
return new Vector2(this.parent.x, this.parent.y);
|
||||
}
|
||||
|
||||
public get bounds(){
|
||||
return new Rectangle().setEgretRect(this.getBounds());
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
///<reference path="./Shape.ts" />
|
||||
/**
|
||||
* 多边形
|
||||
*/
|
||||
class Polygon extends Shape {
|
||||
/** 组成多边形的点。它们应该是CW和凸的。 */
|
||||
public points: Vector2[];
|
||||
private _polygonCenter: Vector2;
|
||||
private _areEdgeNormalsDirty = true;
|
||||
protected _originalPoints: Vector2[];
|
||||
public center = new Vector2();
|
||||
/**
|
||||
* 多边形坐标
|
||||
* 此为内部字段 可访问
|
||||
*/
|
||||
public position: Vector2 = Vector2.zero;
|
||||
|
||||
public get bounds(){
|
||||
return new Rectangle(0, 0, this.width, this.height);
|
||||
return new Rectangle(this.position.x, this.position.y, 0, 0);
|
||||
}
|
||||
|
||||
public _edgeNormals: Vector2[];
|
||||
@@ -158,6 +167,11 @@ class Polygon extends Shape {
|
||||
return { closestPoint: closestPoint, distanceSquared: distanceSquared, edgeNormal: edgeNormal };
|
||||
}
|
||||
|
||||
public recalculateBounds(collider: Collider){
|
||||
// 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始
|
||||
|
||||
}
|
||||
|
||||
public pointCollidesWithShape(point: Vector2): CollisionResult {
|
||||
return ShapeCollisions.pointToPoly(point, this);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
abstract class Shape extends egret.DisplayObject {
|
||||
public abstract bounds: Rectangle;
|
||||
public position: Vector2 = Vector2.zero;
|
||||
public abstract center: Vector2;
|
||||
abstract class Shape {
|
||||
/** 缓存的形状边界 内部字段 */
|
||||
public bounds: Rectangle;
|
||||
/**
|
||||
* 这不是中心。这个值不一定是物体的中心。对撞机更准确。
|
||||
* 应用任何转换旋转的localOffset
|
||||
* 内部字段
|
||||
*/
|
||||
public center: Vector2;
|
||||
/**
|
||||
* 有一个单独的位置字段可以让我们改变形状的位置来进行碰撞检查,而不是改变entity.position。
|
||||
* 触发碰撞器/边界/散列更新的位置。
|
||||
* 内部字段
|
||||
*/
|
||||
public position: Vector2;
|
||||
|
||||
public abstract recalculateBounds(collider: Collider);
|
||||
public abstract pointCollidesWithShape(point: Vector2): CollisionResult;
|
||||
public abstract overlaps(other: Shape);
|
||||
public abstract collidesWithShape(other: Shape): CollisionResult;
|
||||
|
||||
Reference in New Issue
Block a user