diff --git a/demo/index.html b/demo/index.html
index f740eccf..b68cb631 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -27,7 +27,7 @@
data-entry-class="Main"
data-orientation="auto"
data-scale-mode="fixedWidth"
- data-frame-rate="30"
+ data-frame-rate="60"
data-content-width="640"
data-content-height="1136"
data-multi-fingered="2"
diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts
index 1ca79471..a8d146ad 100644
--- a/demo/libs/framework/framework.d.ts
+++ b/demo/libs/framework/framework.d.ts
@@ -32,22 +32,22 @@ declare class AStarNode extends PriorityQueueNode {
data: T;
constructor(data: T);
}
-declare class AstarGridGraph implements IAstarGraph {
- dirs: Point[];
- walls: Point[];
- weightedNodes: Point[];
+declare class AstarGridGraph implements IAstarGraph {
+ dirs: Vector2[];
+ walls: Vector2[];
+ weightedNodes: Vector2[];
defaultWeight: number;
weightedNodeWeight: number;
private _width;
private _height;
private _neighbors;
constructor(width: number, height: number);
- isNodeInBounds(node: Point): boolean;
- isNodePassable(node: Point): boolean;
- search(start: Point, goal: Point): Point[];
- getNeighbors(node: Point): Point[];
- cost(from: Point, to: Point): number;
- heuristic(node: Point, goal: Point): number;
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ search(start: Vector2, goal: Vector2): Vector2[];
+ getNeighbors(node: Vector2): Vector2[];
+ cost(from: Vector2, to: Vector2): number;
+ heuristic(node: Vector2, goal: Vector2): number;
}
interface IAstarGraph {
getNeighbors(node: T): Array;
@@ -84,34 +84,57 @@ declare class UnweightedGraph implements IUnweightedGraph {
addEdgesForNode(node: T, edges: T[]): this;
getNeighbors(node: T): T[];
}
-declare class Point {
+declare class Vector2 {
x: number;
y: number;
+ private static readonly unitYVector;
+ private static readonly unitXVector;
+ private static readonly unitVector2;
+ private static readonly zeroVector2;
+ static readonly zero: Vector2;
+ static readonly one: Vector2;
+ static readonly unitX: Vector2;
+ static readonly unitY: Vector2;
constructor(x?: number, y?: number);
+ static add(value1: Vector2, value2: Vector2): Vector2;
+ static divide(value1: Vector2, value2: Vector2): Vector2;
+ static multiply(value1: Vector2, value2: Vector2): Vector2;
+ static subtract(value1: Vector2, value2: Vector2): Vector2;
+ normalize(): void;
+ length(): number;
+ round(): Vector2;
+ static normalize(value: Vector2): Vector2;
+ static dot(value1: Vector2, value2: Vector2): number;
+ static distanceSquared(value1: Vector2, value2: Vector2): number;
+ static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
+ static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
+ static transform(position: Vector2, matrix: Matrix2D): Vector2;
+ static distance(value1: Vector2, value2: Vector2): number;
+ static negate(value: Vector2): Vector2;
}
-declare class UnweightedGridGraph implements IUnweightedGraph {
+declare class UnweightedGridGraph implements IUnweightedGraph {
private static readonly CARDINAL_DIRS;
private static readonly COMPASS_DIRS;
- walls: Point[];
+ walls: Vector2[];
private _width;
private _hegiht;
private _dirs;
private _neighbors;
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
- isNodeInBounds(node: Point): boolean;
- isNodePassable(node: Point): boolean;
- getNeighbors(node: Point): Point[];
- search(start: Point, goal: Point): Point[];
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ getNeighbors(node: Vector2): Vector2[];
+ search(start: Vector2, goal: Vector2): Vector2[];
}
interface IWeightedGraph {
getNeighbors(node: T): T[];
cost(from: T, to: T): number;
}
-declare class WeightedGridGraph implements IWeightedGraph {
- static readonly CARDINAL_DIRS: Point[];
+declare class WeightedGridGraph implements IWeightedGraph {
+ static readonly CARDINAL_DIRS: Vector2[];
private static readonly COMPASS_DIRS;
- walls: Point[];
- weightedNodes: Point[];
+ walls: Vector2[];
+ weightedNodes: Vector2[];
defaultWeight: number;
weightedNodeWeight: number;
private _width;
@@ -119,11 +142,11 @@ declare class WeightedGridGraph implements IWeightedGraph {
private _dirs;
private _neighbors;
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
- isNodeInBounds(node: Point): boolean;
- isNodePassable(node: Point): boolean;
- search(start: Point, goal: Point): Point[];
- getNeighbors(node: Point): Point[];
- cost(from: Point, to: Point): number;
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ search(start: Vector2, goal: Vector2): Vector2[];
+ getNeighbors(node: Vector2): Vector2[];
+ cost(from: Vector2, to: Vector2): number;
}
declare class WeightedNode extends PriorityQueueNode {
data: T;
@@ -153,12 +176,12 @@ declare abstract class Component extends egret.DisplayObjectContainer {
onDisabled(): void;
update(): void;
debugRender(): void;
+ onEntityTransformChanged(comp: TransformComponent): void;
registerComponent(): void;
deregisterComponent(): void;
}
declare class Entity extends egret.DisplayObjectContainer {
private static _idGenerator;
- private _position;
name: string;
readonly id: number;
scene: Scene;
@@ -171,6 +194,7 @@ declare class Entity extends egret.DisplayObjectContainer {
readonly isDestoryed: boolean;
position: Vector2;
scale: Vector2;
+ rotation: number;
enabled: boolean;
setEnabled(isEnabled: boolean): this;
tag: number;
@@ -187,6 +211,7 @@ declare class Entity extends egret.DisplayObjectContainer {
getOrCreateComponent(type: T): T;
getComponent(type: any): T;
getComponents(typeName: string | any, componentList?: any): any;
+ private onEntityTransformChanged;
removeComponentForType(type: any): boolean;
removeComponent(component: Component): void;
removeAllComponents(): void;
@@ -195,6 +220,11 @@ declare class Entity extends egret.DisplayObjectContainer {
onRemovedFromScene(): void;
destroy(): void;
}
+declare enum TransformComponent {
+ rotation = 0,
+ scale = 1,
+ position = 2
+}
declare class Scene extends egret.DisplayObjectContainer {
camera: Camera;
readonly entities: EntityList;
@@ -244,6 +274,7 @@ declare class Camera extends Component {
private _origin;
private _minimumZoom;
private _maximumZoom;
+ private _position;
followLerp: number;
deadzone: Rectangle;
focusOffset: Vector2;
@@ -259,6 +290,8 @@ declare class Camera extends Component {
maximumZoom: number;
origin: Vector2;
position: Vector2;
+ x: number;
+ y: number;
constructor();
onSceneSizeChanged(newWidth: number, newHeight: number): void;
setMinimumZoom(minZoom: number): Camera;
@@ -312,11 +345,8 @@ declare class Mesh extends RenderableComponent {
reset(): void;
}
declare class SpriteRenderer extends RenderableComponent {
- private _origin;
private _sprite;
protected bitmap: egret.Bitmap;
- origin: Vector2;
- setOrigin(origin: Vector2): this;
sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer;
setColor(color: number): SpriteRenderer;
@@ -406,11 +436,9 @@ declare abstract class Collider extends Component {
physicsLayer: number;
isTrigger: boolean;
registeredPhysicsBounds: Rectangle;
- shouldColliderScaleAndRotationWithTransform: boolean;
+ shouldColliderScaleAndRotateWithTransform: boolean;
collidesWithLayers: number;
_localOffsetLength: number;
- _isPositionDirty: boolean;
- _isRotationDirty: boolean;
protected _isParentEntityAddedToScene: any;
protected _colliderRequiresAutoSizing: any;
protected _localOffset: Vector2;
@@ -426,6 +454,7 @@ declare abstract class Collider extends Component {
onRemovedFromEntity(): void;
onEnabled(): void;
onDisabled(): void;
+ onEntityTransformChanged(comp: TransformComponent): void;
}
declare class BoxCollider extends Collider {
width: number;
@@ -501,6 +530,7 @@ declare class ComponentList {
deregisterAllComponents(): void;
registerAllComponents(): void;
updateLists(): void;
+ onEntityTransformChanged(comp: TransformComponent): void;
private handleRemove;
getComponent(type: any, onlyReturnInitializedComponents: boolean): T;
getComponents(typeName: string | any, components?: any): any;
@@ -743,68 +773,29 @@ declare class Matrix2D {
static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
determinant(): number;
static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
- static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D): Matrix2D;
+ static createTranslation(xPosition: number, yPosition: number): Matrix2D;
+ static createTranslationVector(position: Vector2): Matrix2D;
static createRotation(radians: number, result?: Matrix2D): Matrix2D;
static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
toEgretMatrix(): egret.Matrix;
}
-declare class Rectangle {
- x: number;
- y: number;
- width: number;
- height: number;
- private _tempMat;
- private _transformMat;
+declare class Rectangle extends egret.Rectangle {
readonly max: Vector2;
- readonly left: number;
- readonly right: number;
- readonly top: number;
- readonly bottom: number;
readonly center: Vector2;
location: Vector2;
size: Vector2;
- constructor(x?: number, y?: number, width?: number, height?: number);
- intersects(value: Rectangle): boolean;
- contains(value: Vector2): boolean;
+ intersects(value: egret.Rectangle): boolean;
+ containsInVec(value: Vector2): boolean;
containsRect(value: Rectangle): boolean;
getHalfSize(): Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
- getClosestPointOnRectangleBorderToPoint(point: Point): {
+ getClosestPointOnRectangleBorderToPoint(point: Vector2): {
res: Vector2;
edgeNormal: Vector2;
};
getClosestPointOnBoundsToOrigin(): Vector2;
- calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
static rectEncompassingPoints(points: Vector2[]): Rectangle;
}
-declare class Vector2 {
- x: number;
- y: number;
- private static readonly unitYVector;
- private static readonly unitXVector;
- private static readonly unitVector2;
- private static readonly zeroVector2;
- static readonly zero: Vector2;
- static readonly one: Vector2;
- static readonly unitX: Vector2;
- static readonly unitY: Vector2;
- constructor(x?: number, y?: number);
- static add(value1: Vector2, value2: Vector2): Vector2;
- static divide(value1: Vector2, value2: Vector2): Vector2;
- static multiply(value1: Vector2, value2: Vector2): Vector2;
- static subtract(value1: Vector2, value2: Vector2): Vector2;
- normalize(): void;
- length(): number;
- round(): Vector2;
- static normalize(value: Vector2): Vector2;
- static dot(value1: Vector2, value2: Vector2): number;
- static distanceSquared(value1: Vector2, value2: Vector2): number;
- static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
- static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
- static transform(position: Vector2, matrix: Matrix2D): Vector2;
- static distance(value1: Vector2, value2: Vector2): number;
- static negate(value: Vector2): Vector2;
-}
declare class Vector3 {
x: number;
y: number;
@@ -937,7 +928,7 @@ declare class ShapeCollisions {
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
static circleToCircle(first: Circle, second: Circle): CollisionResult;
- static boxToBox(first: Box, second: Box): false | CollisionResult;
+ static boxToBox(first: Box, second: Box): CollisionResult;
private static minkowskiDifference;
}
declare class SpatialHash {
@@ -1044,7 +1035,7 @@ declare class Pair {
equals(other: Pair): boolean;
}
declare class RectangleExt {
- static union(first: Rectangle, point: Point): Rectangle;
+ static union(first: Rectangle, point: Vector2): Rectangle;
static unionR(value1: Rectangle, value2: Rectangle): Rectangle;
}
declare class Triangulator {
diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js
index 230da8d3..fb3d7c1e 100644
--- a/demo/libs/framework/framework.js
+++ b/demo/libs/framework/framework.js
@@ -361,10 +361,10 @@ var AStarNode = (function (_super) {
var AstarGridGraph = (function () {
function AstarGridGraph(width, height) {
this.dirs = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, 1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, 1)
];
this.walls = [];
this.weightedNodes = [];
@@ -387,7 +387,7 @@ var AstarGridGraph = (function () {
var _this = this;
this._neighbors.length = 0;
this.dirs.forEach(function (dir) {
- var next = new Point(node.x + dir.x, node.y + dir.y);
+ var next = new Vector2(node.x + dir.x, node.y + dir.y);
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
_this._neighbors.push(next);
});
@@ -583,12 +583,113 @@ var UnweightedGraph = (function () {
};
return UnweightedGraph;
}());
-var Point = (function () {
- function Point(x, y) {
+var Vector2 = (function () {
+ function Vector2(x, y) {
+ this.x = 0;
+ this.y = 0;
this.x = x ? x : 0;
this.y = y ? y : this.x;
}
- return Point;
+ Object.defineProperty(Vector2, "zero", {
+ get: function () {
+ return Vector2.zeroVector2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "one", {
+ get: function () {
+ return Vector2.unitVector2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "unitX", {
+ get: function () {
+ return Vector2.unitXVector;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "unitY", {
+ get: function () {
+ return Vector2.unitYVector;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Vector2.add = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x + value2.x;
+ result.y = value1.y + value2.y;
+ return result;
+ };
+ Vector2.divide = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x / value2.x;
+ result.y = value1.y / value2.y;
+ return result;
+ };
+ Vector2.multiply = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x * value2.x;
+ result.y = value1.y * value2.y;
+ return result;
+ };
+ Vector2.subtract = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x - value2.x;
+ result.y = value1.y - value2.y;
+ return result;
+ };
+ Vector2.prototype.normalize = function () {
+ var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
+ this.x *= val;
+ this.y *= val;
+ };
+ Vector2.prototype.length = function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vector2.prototype.round = function () {
+ return new Vector2(Math.round(this.x), Math.round(this.y));
+ };
+ Vector2.normalize = function (value) {
+ var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
+ value.x *= val;
+ value.y *= val;
+ return value;
+ };
+ Vector2.dot = function (value1, value2) {
+ return (value1.x * value2.x) + (value1.y * value2.y);
+ };
+ Vector2.distanceSquared = function (value1, value2) {
+ var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
+ return (v1 * v1) + (v2 * v2);
+ };
+ Vector2.clamp = function (value1, min, max) {
+ return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y));
+ };
+ Vector2.lerp = function (value1, value2, amount) {
+ return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
+ };
+ Vector2.transform = function (position, matrix) {
+ return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22));
+ };
+ Vector2.distance = function (value1, value2) {
+ var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
+ return Math.sqrt((v1 * v1) + (v2 * v2));
+ };
+ Vector2.negate = function (value) {
+ var result = new Vector2();
+ result.x = -value.x;
+ result.y = -value.y;
+ return result;
+ };
+ Vector2.unitYVector = new Vector2(0, 1);
+ Vector2.unitXVector = new Vector2(1, 0);
+ Vector2.unitVector2 = new Vector2(1, 1);
+ Vector2.zeroVector2 = new Vector2(0, 0);
+ return Vector2;
}());
var UnweightedGridGraph = (function () {
function UnweightedGridGraph(width, height, allowDiagonalSearch) {
@@ -609,7 +710,7 @@ var UnweightedGridGraph = (function () {
var _this = this;
this._neighbors.length = 0;
this._dirs.forEach(function (dir) {
- var next = new Point(node.x + dir.x, node.y + dir.y);
+ var next = new Vector2(node.x + dir.x, node.y + dir.y);
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
_this._neighbors.push(next);
});
@@ -619,20 +720,20 @@ var UnweightedGridGraph = (function () {
return BreadthFirstPathfinder.search(this, start, goal);
};
UnweightedGridGraph.CARDINAL_DIRS = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, -1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, -1)
];
UnweightedGridGraph.COMPASS_DIRS = [
- new Point(1, 0),
- new Point(1, -1),
- new Point(0, -1),
- new Point(-1, -1),
- new Point(-1, 0),
- new Point(-1, 1),
- new Point(0, 1),
- new Point(1, 1),
+ new Vector2(1, 0),
+ new Vector2(1, -1),
+ new Vector2(0, -1),
+ new Vector2(-1, -1),
+ new Vector2(-1, 0),
+ new Vector2(-1, 1),
+ new Vector2(0, 1),
+ new Vector2(1, 1),
];
return UnweightedGridGraph;
}());
@@ -661,7 +762,7 @@ var WeightedGridGraph = (function () {
var _this = this;
this._neighbors.length = 0;
this._dirs.forEach(function (dir) {
- var next = new Point(node.x + dir.x, node.y + dir.y);
+ var next = new Vector2(node.x + dir.x, node.y + dir.y);
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
_this._neighbors.push(next);
});
@@ -671,20 +772,20 @@ var WeightedGridGraph = (function () {
return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
};
WeightedGridGraph.CARDINAL_DIRS = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, 1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, 1)
];
WeightedGridGraph.COMPASS_DIRS = [
- new Point(1, 0),
- new Point(1, -1),
- new Point(0, -1),
- new Point(-1, -1),
- new Point(-1, 0),
- new Point(-1, 1),
- new Point(0, 1),
- new Point(1, 1),
+ new Vector2(1, 0),
+ new Vector2(1, -1),
+ new Vector2(0, -1),
+ new Vector2(-1, -1),
+ new Vector2(-1, 0),
+ new Vector2(-1, 1),
+ new Vector2(0, 1),
+ new Vector2(1, 1),
];
return WeightedGridGraph;
}());
@@ -816,6 +917,8 @@ var Component = (function (_super) {
};
Component.prototype.debugRender = function () {
};
+ Component.prototype.onEntityTransformChanged = function (comp) {
+ };
Component.prototype.registerComponent = function () {
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
this.entity.scene.entityProcessors.onComponentAdded(this.entity);
@@ -830,7 +933,6 @@ var Entity = (function (_super) {
__extends(Entity, _super);
function Entity(name) {
var _this = _super.call(this) || this;
- _this._position = Vector2.zero;
_this._updateOrder = 0;
_this._enabled = true;
_this._tag = 0;
@@ -849,10 +951,12 @@ var Entity = (function (_super) {
});
Object.defineProperty(Entity.prototype, "position", {
get: function () {
- return this._position;
+ return new Vector2(this.x, this.y);
},
set: function (value) {
- this._position = value;
+ this.$setX(value.x);
+ this.$setY(value.y);
+ this.onEntityTransformChanged(TransformComponent.position);
},
enumerable: true,
configurable: true
@@ -862,8 +966,17 @@ var Entity = (function (_super) {
return new Vector2(this.scaleX, this.scaleY);
},
set: function (value) {
- this.scaleX = value.x;
- this.scaleY = value.y;
+ this.$setScaleX(value.x);
+ this.$setScaleY(value.y);
+ this.onEntityTransformChanged(TransformComponent.scale);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "rotation", {
+ set: function (value) {
+ this.$setRotation(value);
+ this.onEntityTransformChanged(TransformComponent.rotation);
},
enumerable: true,
configurable: true
@@ -973,6 +1086,9 @@ var Entity = (function (_super) {
Entity.prototype.getComponents = function (typeName, componentList) {
return this.components.getComponents(typeName, componentList);
};
+ Entity.prototype.onEntityTransformChanged = function (comp) {
+ this.components.onEntityTransformChanged(comp);
+ };
Entity.prototype.removeComponentForType = function (type) {
var comp = this.getComponent(type);
if (comp) {
@@ -1009,6 +1125,12 @@ var Entity = (function (_super) {
};
return Entity;
}(egret.DisplayObjectContainer));
+var TransformComponent;
+(function (TransformComponent) {
+ TransformComponent[TransformComponent["rotation"] = 0] = "rotation";
+ TransformComponent[TransformComponent["scale"] = 1] = "scale";
+ TransformComponent[TransformComponent["position"] = 2] = "position";
+})(TransformComponent || (TransformComponent = {}));
var Scene = (function (_super) {
__extends(Scene, _super);
function Scene() {
@@ -1112,6 +1234,8 @@ var Scene = (function (_super) {
if (this.entityProcessors)
this.entityProcessors.end();
this.unload();
+ if (this.parent)
+ this.parent.removeChild(this);
};
Scene.prototype.onStart = function () {
return __awaiter(this, void 0, void 0, function () {
@@ -1251,6 +1375,7 @@ var Camera = (function (_super) {
_this._origin = Vector2.zero;
_this._minimumZoom = 0.3;
_this._maximumZoom = 3;
+ _this._position = Vector2.zero;
_this.followLerp = 0.1;
_this.deadzone = new Rectangle();
_this.focusOffset = new Vector2();
@@ -1312,10 +1437,30 @@ var Camera = (function (_super) {
});
Object.defineProperty(Camera.prototype, "position", {
get: function () {
- return this.entity.position;
+ return this._position;
},
set: function (value) {
- this.entity.position = value;
+ this._position = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "x", {
+ get: function () {
+ return this._position.x;
+ },
+ set: function (value) {
+ this._position.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "y", {
+ get: function () {
+ return this._position.y;
+ },
+ set: function (value) {
+ this._position.y = value;
},
enumerable: true,
configurable: true
@@ -1553,22 +1698,6 @@ var SpriteRenderer = (function (_super) {
function SpriteRenderer() {
return _super !== null && _super.apply(this, arguments) || this;
}
- Object.defineProperty(SpriteRenderer.prototype, "origin", {
- get: function () {
- return this._origin;
- },
- set: function (value) {
- this.setOrigin(value);
- },
- enumerable: true,
- configurable: true
- });
- SpriteRenderer.prototype.setOrigin = function (origin) {
- if (this._origin != origin) {
- this._origin = origin;
- }
- return this;
- };
Object.defineProperty(SpriteRenderer.prototype, "sprite", {
get: function () {
return this._sprite;
@@ -1582,8 +1711,10 @@ var SpriteRenderer = (function (_super) {
SpriteRenderer.prototype.setSprite = function (sprite) {
this.removeChildren();
this._sprite = sprite;
- if (this._sprite)
- this._origin = this._sprite.origin;
+ if (this._sprite) {
+ this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width;
+ this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height;
+ }
this.bitmap = new egret.Bitmap(sprite.texture2D);
this.addChild(this.bitmap);
return this;
@@ -1608,8 +1739,8 @@ var SpriteRenderer = (function (_super) {
return this.isVisible;
};
SpriteRenderer.prototype.render = function (camera) {
- this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x;
- this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y;
+ this.x = -camera.position.x + camera.origin.x;
+ this.y = -camera.position.y + camera.origin.y;
};
SpriteRenderer.prototype.onRemovedFromEntity = function () {
if (this.parent)
@@ -1874,27 +2005,23 @@ var Collider = (function (_super) {
function Collider() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.physicsLayer = 1 << 0;
- _this.shouldColliderScaleAndRotationWithTransform = true;
+ _this.registeredPhysicsBounds = new Rectangle();
+ _this.shouldColliderScaleAndRotateWithTransform = true;
_this.collidesWithLayers = Physics.allLayers;
- _this._isPositionDirty = true;
- _this._isRotationDirty = true;
_this._localOffset = new Vector2(0, 0);
return _this;
}
Object.defineProperty(Collider.prototype, "bounds", {
get: function () {
- if (this._isPositionDirty || this._isRotationDirty) {
- this.shape.recalculateBounds(this);
- this._isPositionDirty = this._isRotationDirty = false;
- }
- return this.shape.bounds;
+ var bds = this.entity.getBounds();
+ return new Rectangle(bds.x, bds.y, bds.width, bds.height);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Collider.prototype, "localOffset", {
get: function () {
- return this._localOffset;
+ return new Vector2(this.x, this.y);
},
set: function (value) {
this.setLocalOffset(value);
@@ -1905,9 +2032,9 @@ var Collider = (function (_super) {
Collider.prototype.setLocalOffset = function (offset) {
if (this._localOffset != offset) {
this.unregisterColliderWithPhysicsSystem();
- this._localOffset = offset;
+ this.$setX(offset.x);
+ this.$setY(offset.y);
this._localOffsetLength = this._localOffset.length();
- this._isPositionDirty = true;
this.registerColliderWithPhysicsSystem();
}
};
@@ -1940,17 +2067,15 @@ var Collider = (function (_super) {
if (!(this instanceof BoxCollider)) {
console.error("Only box and circle colliders can be created automatically");
}
- var renderable = this.entity.getComponent(RenderableComponent);
- if (renderable) {
- var renderbaleBounds = renderable.bounds;
- var width = renderbaleBounds.width / this.entity.scale.x;
- var height = renderbaleBounds.height / this.entity.scale.y;
- if (this instanceof BoxCollider) {
- var boxCollider = this;
- boxCollider.width = width;
- boxCollider.height = height;
- this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
- }
+ var bounds = this.entity.getBounds();
+ var renderbaleBounds = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
+ var width = renderbaleBounds.width / this.entity.scale.x;
+ var height = renderbaleBounds.height / this.entity.scale.y;
+ if (this instanceof BoxCollider) {
+ var boxCollider = this;
+ boxCollider.width = width;
+ boxCollider.height = height;
+ this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
}
}
this._isParentEntityAddedToScene = true;
@@ -1962,11 +2087,14 @@ var Collider = (function (_super) {
};
Collider.prototype.onEnabled = function () {
this.registerColliderWithPhysicsSystem();
- this._isPositionDirty = this._isRotationDirty = true;
};
Collider.prototype.onDisabled = function () {
this.unregisterColliderWithPhysicsSystem();
};
+ Collider.prototype.onEntityTransformChanged = function (comp) {
+ if (this._isColliderRegistered)
+ Physics.updateCollider(this);
+ };
return Collider;
}(Component));
var BoxCollider = (function (_super) {
@@ -1992,7 +2120,6 @@ var BoxCollider = (function (_super) {
var box = this.shape;
if (width != box.width) {
box.updateBox(width, box.height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -2013,7 +2140,6 @@ var BoxCollider = (function (_super) {
var box = this.shape;
if (height != box.height) {
box.updateBox(box.width, height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -2023,7 +2149,6 @@ var BoxCollider = (function (_super) {
var box = this.shape;
if (width != box.width || height != box.height) {
box.updateBox(width, height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -2334,6 +2459,16 @@ var ComponentList = (function () {
this._tempBufferList.length = 0;
}
};
+ ComponentList.prototype.onEntityTransformChanged = function (comp) {
+ for (var i = 0; i < this._components.length; i++) {
+ if (this._components[i].enabled)
+ this._components[i].onEntityTransformChanged(comp);
+ }
+ for (var i = 0; i < this._componentsToAdd.length; i++) {
+ if (this._componentsToAdd[i].enabled)
+ this._componentsToAdd[i].onEntityTransformChanged(comp);
+ }
+ };
ComponentList.prototype.handleRemove = function (component) {
if (component instanceof RenderableComponent)
this._entity.scene.renderableComponents.remove(component);
@@ -3340,8 +3475,8 @@ var Matrix2D = (function () {
result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det;
return result;
};
- Matrix2D.createTranslation = function (xPosition, yPosition, result) {
- result = result ? result : new Matrix2D();
+ Matrix2D.createTranslation = function (xPosition, yPosition) {
+ var result = new Matrix2D();
result.m11 = 1;
result.m12 = 0;
result.m21 = 0;
@@ -3350,6 +3485,9 @@ var Matrix2D = (function () {
result.m32 = yPosition;
return result;
};
+ Matrix2D.createTranslationVector = function (position) {
+ return this.createTranslation(position.x, position.y);
+ };
Matrix2D.createRotation = function (radians, result) {
result = new Matrix2D();
var val1 = Math.cos(radians);
@@ -3377,12 +3515,10 @@ var Matrix2D = (function () {
Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0);
return Matrix2D;
}());
-var Rectangle = (function () {
- function Rectangle(x, y, width, height) {
- this.x = x ? x : 0;
- this.y = y ? y : 0;
- this.width = width ? width : 0;
- this.height = height ? height : 0;
+var Rectangle = (function (_super) {
+ __extends(Rectangle, _super);
+ function Rectangle() {
+ return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(Rectangle.prototype, "max", {
get: function () {
@@ -3391,34 +3527,6 @@ var Rectangle = (function () {
enumerable: true,
configurable: true
});
- Object.defineProperty(Rectangle.prototype, "left", {
- get: function () {
- return this.x;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "right", {
- get: function () {
- return this.x + this.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "top", {
- get: function () {
- return this.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottom", {
- get: function () {
- return this.y + this.height;
- },
- enumerable: true,
- configurable: true
- });
Object.defineProperty(Rectangle.prototype, "center", {
get: function () {
return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
@@ -3454,7 +3562,7 @@ var Rectangle = (function () {
value.top < this.bottom &&
this.top < value.bottom;
};
- Rectangle.prototype.contains = function (value) {
+ Rectangle.prototype.containsInVec = function (value) {
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
(this.y <= value.y)) &&
(value.y < (this.y + this.height)));
@@ -3471,11 +3579,11 @@ var Rectangle = (function () {
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
};
Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) {
- var edgeNormal = new Vector2(0, 0);
- var res = new Vector2(0, 0);
+ var edgeNormal = Vector2.zero;
+ var res = new Vector2();
res.x = MathHelper.clamp(point.x, this.left, this.right);
res.y = MathHelper.clamp(point.y, this.top, this.bottom);
- if (this.contains(res)) {
+ if (this.containsInVec(res)) {
var dl = res.x - this.left;
var dr = this.right - res.x;
var dt = res.y - this.top;
@@ -3499,18 +3607,14 @@ var Rectangle = (function () {
}
}
else {
- if (res.x == this.left) {
+ if (res.x == this.left)
edgeNormal.x = -1;
- }
- if (res.x == this.right) {
+ if (res.x == this.right)
edgeNormal.x = 1;
- }
- if (res.y == this.top) {
+ if (res.y == this.top)
edgeNormal.y = -1;
- }
- if (res.y == this.bottom) {
+ if (res.y == this.bottom)
edgeNormal.y = 1;
- }
}
return { res: res, edgeNormal: edgeNormal };
};
@@ -3535,40 +3639,6 @@ var Rectangle = (function () {
}
return boundsPoint;
};
- Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) {
- if (rotation == 0) {
- this.x = parentPosition.x + position.x - origin.x * scale.x;
- this.y = parentPosition.y + position.y - origin.y * scale.y;
- this.width = width * scale.x;
- this.height = height * scale.y;
- }
- else {
- var worldPosX = parentPosition.x + position.x;
- var worldPosY = parentPosition.y + position.y;
- this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y);
- this._tempMat = Matrix2D.createScale(scale.x, scale.y);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- this._tempMat = Matrix2D.createRotation(rotation);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- var topLeft = new Vector2(worldPosX, worldPosY);
- var topRight = new Vector2(worldPosX + width, worldPosY);
- var bottomLeft = new Vector2(worldPosX, worldPosY + height);
- var bottomRight = new Vector2(worldPosX + width, worldPosY + height);
- topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
- topRight = Vector2Ext.transformR(topRight, this._transformMat);
- bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
- bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
- var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
- var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
- var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
- var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
- this.location = new Vector2(minX, minY);
- this.width = maxX - minX;
- this.height = maxY - minY;
- }
- };
Rectangle.rectEncompassingPoints = function (points) {
var minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
@@ -3576,131 +3646,19 @@ var Rectangle = (function () {
var maxY = Number.NEGATIVE_INFINITY;
for (var i = 0; i < points.length; i++) {
var pt = points[i];
- if (pt.x < minX) {
+ if (pt.x < minX)
minX = pt.x;
- }
- if (pt.x > maxX) {
+ if (pt.x > maxX)
maxX = pt.x;
- }
- if (pt.y < minY) {
+ if (pt.y < minY)
minY = pt.y;
- }
- if (pt.y > maxY) {
+ if (pt.y > maxY)
maxY = pt.y;
- }
}
return this.fromMinMax(minX, minY, maxX, maxY);
};
return Rectangle;
-}());
-var Vector2 = (function () {
- function Vector2(x, y) {
- this.x = 0;
- this.y = 0;
- this.x = x ? x : 0;
- this.y = y ? y : this.x;
- }
- Object.defineProperty(Vector2, "zero", {
- get: function () {
- return Vector2.zeroVector2;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "one", {
- get: function () {
- return Vector2.unitVector2;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "unitX", {
- get: function () {
- return Vector2.unitXVector;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "unitY", {
- get: function () {
- return Vector2.unitYVector;
- },
- enumerable: true,
- configurable: true
- });
- Vector2.add = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x + value2.x;
- result.y = value1.y + value2.y;
- return result;
- };
- Vector2.divide = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x / value2.x;
- result.y = value1.y / value2.y;
- return result;
- };
- Vector2.multiply = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x * value2.x;
- result.y = value1.y * value2.y;
- return result;
- };
- Vector2.subtract = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x - value2.x;
- result.y = value1.y - value2.y;
- return result;
- };
- Vector2.prototype.normalize = function () {
- var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
- this.x *= val;
- this.y *= val;
- };
- Vector2.prototype.length = function () {
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
- };
- Vector2.prototype.round = function () {
- return new Vector2(Math.round(this.x), Math.round(this.y));
- };
- Vector2.normalize = function (value) {
- var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
- value.x *= val;
- value.y *= val;
- return value;
- };
- Vector2.dot = function (value1, value2) {
- return (value1.x * value2.x) + (value1.y * value2.y);
- };
- Vector2.distanceSquared = function (value1, value2) {
- var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
- return (v1 * v1) + (v2 * v2);
- };
- Vector2.clamp = function (value1, min, max) {
- return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y));
- };
- Vector2.lerp = function (value1, value2, amount) {
- return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
- };
- Vector2.transform = function (position, matrix) {
- return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22));
- };
- Vector2.distance = function (value1, value2) {
- var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
- return Math.sqrt((v1 * v1) + (v2 * v2));
- };
- Vector2.negate = function (value) {
- var result = new Vector2();
- result.x = -value.x;
- result.y = -value.y;
- return result;
- };
- Vector2.unitYVector = new Vector2(0, 1);
- Vector2.unitXVector = new Vector2(1, 0);
- Vector2.unitVector2 = new Vector2(1, 1);
- Vector2.zeroVector2 = new Vector2(0, 0);
- return Vector2;
-}());
+}(egret.Rectangle));
var Vector3 = (function () {
function Vector3(x, y, z) {
this.x = x;
@@ -4099,7 +4057,7 @@ var Polygon = (function (_super) {
};
Polygon.prototype.recalculateBounds = function (collider) {
this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotationWithTransform) {
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
var hasUnitScale = true;
var tempMat = void 0;
var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
@@ -4111,7 +4069,7 @@ var Polygon = (function (_super) {
this.center = scaledOffset;
}
if (collider.entity.rotation != 0) {
- tempMat = Matrix2D.createRotation(collider.entity.rotation);
+ tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat);
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
@@ -4121,8 +4079,6 @@ var Polygon = (function (_super) {
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
this.isUnrotated = collider.entity.rotation == 0;
- if (collider._isRotationDirty)
- this._areEdgeNormalsDirty = true;
}
this.position = Vector2.add(collider.entity.position, this.center);
this.bounds = Rectangle.rectEncompassingPoints(this.points);
@@ -4177,7 +4133,7 @@ var Box = (function (_super) {
};
Box.prototype.containsPoint = function (point) {
if (this.isUnrotated)
- return this.bounds.contains(point);
+ return this.bounds.containsInVec(point);
return _super.prototype.containsPoint.call(this, point);
};
return Box;
@@ -4207,7 +4163,7 @@ var Circle = (function (_super) {
};
Circle.prototype.recalculateBounds = function (collider) {
this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotationWithTransform) {
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
var scale = collider.entity.scale;
var hasUnitScale = scale.x == 1 && scale.y == 1;
var maxScale = Math.max(scale.x, scale.y);
@@ -4291,7 +4247,7 @@ var ShapeCollisions = (function () {
}
}
result.normal = translationAxis;
- result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance));
+ result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance));
return result;
};
ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) {
@@ -4414,10 +4370,10 @@ var ShapeCollisions = (function () {
ShapeCollisions.boxToBox = function (first, second) {
var result = new CollisionResult();
var minkowskiDiff = this.minkowskiDifference(first, second);
- if (minkowskiDiff.contains(new Vector2(0, 0))) {
+ if (minkowskiDiff.containsInVec(new Vector2(0, 0))) {
result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
- if (result.minimumTranslationVector == Vector2.zero)
- return false;
+ if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0)
+ return null;
result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y);
result.normal.normalize();
return result;
@@ -4436,6 +4392,7 @@ var SpatialHash = (function () {
function SpatialHash(cellSize) {
if (cellSize === void 0) { cellSize = 100; }
this.gridBounds = new Rectangle();
+ this._overlapTestCircle = new Circle(0);
this._tempHashSet = [];
this._cellDict = new NumberDictionary();
this._cellSize = cellSize;
@@ -4461,10 +4418,10 @@ var SpatialHash = (function () {
collider.registeredPhysicsBounds = bounds;
var p1 = this.cellCoords(bounds.x, bounds.y);
var p2 = this.cellCoords(bounds.right, bounds.bottom);
- if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) {
+ if (!this.gridBounds.containsInVec(new Vector2(p1.x, p1.y))) {
this.gridBounds = RectangleExt.union(this.gridBounds, p1);
}
- if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) {
+ if (!this.gridBounds.containsInVec(new Vector2(p2.x, p2.y))) {
this.gridBounds = RectangleExt.union(this.gridBounds, p2);
}
for (var x = p1.x; x <= p2.x; x++) {
@@ -4533,7 +4490,7 @@ var SpatialHash = (function () {
return cell;
};
SpatialHash.prototype.cellCoords = function (x, y) {
- return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
+ return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
};
return SpatialHash;
}());
diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js
index acd75eeb..e9723556 100644
--- a/demo/libs/framework/framework.min.js
+++ b/demo/libs/framework/framework.min.js
@@ -1 +1 @@
-window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._position=Vector2.zero,i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.scaleX=t.x,this.scaleY=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer),Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),e.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t),this},Object.defineProperty(e.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=this.entity.position.x-this.origin.x-t.position.x+t.origin.x,this.y=this.entity.position.y-this.origin.y-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var o=Math.floor(i/e),r=t.sprites.length;if(r>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=r-1;this.currentFrame=s-Math.abs(s-o%(2*s))}else this.currentFrame=o%r;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.Bitmap(this.sprite.texture2D),o=new egret.Rectangle(this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height);n.drawToTexture(i,o),this.bitmap.texture=n}},e}(SpriteRenderer),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return(i=i||new t).m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,n,i){this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0}return Object.defineProperty(t.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*o.y-a.y*o.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return o;var u=(c.x*r.y-c.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(h*r.x,h*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],c=e[r],h=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var o=Math.floor(i/e),r=t.sprites.length;if(r>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=r-1;this.currentFrame=s-Math.abs(s-o%(2*s))}else this.currentFrame=o%r;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.Bitmap(this.sprite.texture2D),o=new egret.Rectangle(this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height);n.drawToTexture(i,o),this.bitmap.texture=n}},e}(SpriteRenderer),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*o.y-a.y*o.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return o;var u=(c.x*r.y-c.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(h*r.x,h*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],c=e[r],h=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s this.spriteRenderer.x){
- moveLeft = 1;
- }
+ // let camera = SceneManager.scene.camera;
+ // let moveLeft: number = 0;
+ // let moveRight: number = 0;
+ // let speed = 100;
+ // let worldPos = Input.touchPosition;
+ // if (worldPos.x < this.spriteRenderer.x){
+ // moveLeft = -1;
+ // } else if(worldPos.x > this.spriteRenderer.x){
+ // moveLeft = 1;
+ // }
- if (worldPos.y < this.spriteRenderer.y){
- moveRight = -1;
- } else if(worldPos.y > this.spriteRenderer.y){
- moveRight = 1;
- }
- this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
+ // if (worldPos.y < this.spriteRenderer.y){
+ // moveRight = -1;
+ // } else if(worldPos.y > this.spriteRenderer.y){
+ // moveRight = 1;
+ // }
+ this.mover.move(new Vector2(-1, -1));
}
}
}
\ No newline at end of file
diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts
index 1ca79471..a8d146ad 100644
--- a/source/bin/framework.d.ts
+++ b/source/bin/framework.d.ts
@@ -32,22 +32,22 @@ declare class AStarNode extends PriorityQueueNode {
data: T;
constructor(data: T);
}
-declare class AstarGridGraph implements IAstarGraph {
- dirs: Point[];
- walls: Point[];
- weightedNodes: Point[];
+declare class AstarGridGraph implements IAstarGraph {
+ dirs: Vector2[];
+ walls: Vector2[];
+ weightedNodes: Vector2[];
defaultWeight: number;
weightedNodeWeight: number;
private _width;
private _height;
private _neighbors;
constructor(width: number, height: number);
- isNodeInBounds(node: Point): boolean;
- isNodePassable(node: Point): boolean;
- search(start: Point, goal: Point): Point[];
- getNeighbors(node: Point): Point[];
- cost(from: Point, to: Point): number;
- heuristic(node: Point, goal: Point): number;
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ search(start: Vector2, goal: Vector2): Vector2[];
+ getNeighbors(node: Vector2): Vector2[];
+ cost(from: Vector2, to: Vector2): number;
+ heuristic(node: Vector2, goal: Vector2): number;
}
interface IAstarGraph {
getNeighbors(node: T): Array;
@@ -84,34 +84,57 @@ declare class UnweightedGraph implements IUnweightedGraph {
addEdgesForNode(node: T, edges: T[]): this;
getNeighbors(node: T): T[];
}
-declare class Point {
+declare class Vector2 {
x: number;
y: number;
+ private static readonly unitYVector;
+ private static readonly unitXVector;
+ private static readonly unitVector2;
+ private static readonly zeroVector2;
+ static readonly zero: Vector2;
+ static readonly one: Vector2;
+ static readonly unitX: Vector2;
+ static readonly unitY: Vector2;
constructor(x?: number, y?: number);
+ static add(value1: Vector2, value2: Vector2): Vector2;
+ static divide(value1: Vector2, value2: Vector2): Vector2;
+ static multiply(value1: Vector2, value2: Vector2): Vector2;
+ static subtract(value1: Vector2, value2: Vector2): Vector2;
+ normalize(): void;
+ length(): number;
+ round(): Vector2;
+ static normalize(value: Vector2): Vector2;
+ static dot(value1: Vector2, value2: Vector2): number;
+ static distanceSquared(value1: Vector2, value2: Vector2): number;
+ static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
+ static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
+ static transform(position: Vector2, matrix: Matrix2D): Vector2;
+ static distance(value1: Vector2, value2: Vector2): number;
+ static negate(value: Vector2): Vector2;
}
-declare class UnweightedGridGraph implements IUnweightedGraph {
+declare class UnweightedGridGraph implements IUnweightedGraph {
private static readonly CARDINAL_DIRS;
private static readonly COMPASS_DIRS;
- walls: Point[];
+ walls: Vector2[];
private _width;
private _hegiht;
private _dirs;
private _neighbors;
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
- isNodeInBounds(node: Point): boolean;
- isNodePassable(node: Point): boolean;
- getNeighbors(node: Point): Point[];
- search(start: Point, goal: Point): Point[];
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ getNeighbors(node: Vector2): Vector2[];
+ search(start: Vector2, goal: Vector2): Vector2[];
}
interface IWeightedGraph {
getNeighbors(node: T): T[];
cost(from: T, to: T): number;
}
-declare class WeightedGridGraph implements IWeightedGraph {
- static readonly CARDINAL_DIRS: Point[];
+declare class WeightedGridGraph implements IWeightedGraph {
+ static readonly CARDINAL_DIRS: Vector2[];
private static readonly COMPASS_DIRS;
- walls: Point[];
- weightedNodes: Point[];
+ walls: Vector2[];
+ weightedNodes: Vector2[];
defaultWeight: number;
weightedNodeWeight: number;
private _width;
@@ -119,11 +142,11 @@ declare class WeightedGridGraph implements IWeightedGraph {
private _dirs;
private _neighbors;
constructor(width: number, height: number, allowDiagonalSearch?: boolean);
- isNodeInBounds(node: Point): boolean;
- isNodePassable(node: Point): boolean;
- search(start: Point, goal: Point): Point[];
- getNeighbors(node: Point): Point[];
- cost(from: Point, to: Point): number;
+ isNodeInBounds(node: Vector2): boolean;
+ isNodePassable(node: Vector2): boolean;
+ search(start: Vector2, goal: Vector2): Vector2[];
+ getNeighbors(node: Vector2): Vector2[];
+ cost(from: Vector2, to: Vector2): number;
}
declare class WeightedNode extends PriorityQueueNode {
data: T;
@@ -153,12 +176,12 @@ declare abstract class Component extends egret.DisplayObjectContainer {
onDisabled(): void;
update(): void;
debugRender(): void;
+ onEntityTransformChanged(comp: TransformComponent): void;
registerComponent(): void;
deregisterComponent(): void;
}
declare class Entity extends egret.DisplayObjectContainer {
private static _idGenerator;
- private _position;
name: string;
readonly id: number;
scene: Scene;
@@ -171,6 +194,7 @@ declare class Entity extends egret.DisplayObjectContainer {
readonly isDestoryed: boolean;
position: Vector2;
scale: Vector2;
+ rotation: number;
enabled: boolean;
setEnabled(isEnabled: boolean): this;
tag: number;
@@ -187,6 +211,7 @@ declare class Entity extends egret.DisplayObjectContainer {
getOrCreateComponent(type: T): T;
getComponent(type: any): T;
getComponents(typeName: string | any, componentList?: any): any;
+ private onEntityTransformChanged;
removeComponentForType(type: any): boolean;
removeComponent(component: Component): void;
removeAllComponents(): void;
@@ -195,6 +220,11 @@ declare class Entity extends egret.DisplayObjectContainer {
onRemovedFromScene(): void;
destroy(): void;
}
+declare enum TransformComponent {
+ rotation = 0,
+ scale = 1,
+ position = 2
+}
declare class Scene extends egret.DisplayObjectContainer {
camera: Camera;
readonly entities: EntityList;
@@ -244,6 +274,7 @@ declare class Camera extends Component {
private _origin;
private _minimumZoom;
private _maximumZoom;
+ private _position;
followLerp: number;
deadzone: Rectangle;
focusOffset: Vector2;
@@ -259,6 +290,8 @@ declare class Camera extends Component {
maximumZoom: number;
origin: Vector2;
position: Vector2;
+ x: number;
+ y: number;
constructor();
onSceneSizeChanged(newWidth: number, newHeight: number): void;
setMinimumZoom(minZoom: number): Camera;
@@ -312,11 +345,8 @@ declare class Mesh extends RenderableComponent {
reset(): void;
}
declare class SpriteRenderer extends RenderableComponent {
- private _origin;
private _sprite;
protected bitmap: egret.Bitmap;
- origin: Vector2;
- setOrigin(origin: Vector2): this;
sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer;
setColor(color: number): SpriteRenderer;
@@ -406,11 +436,9 @@ declare abstract class Collider extends Component {
physicsLayer: number;
isTrigger: boolean;
registeredPhysicsBounds: Rectangle;
- shouldColliderScaleAndRotationWithTransform: boolean;
+ shouldColliderScaleAndRotateWithTransform: boolean;
collidesWithLayers: number;
_localOffsetLength: number;
- _isPositionDirty: boolean;
- _isRotationDirty: boolean;
protected _isParentEntityAddedToScene: any;
protected _colliderRequiresAutoSizing: any;
protected _localOffset: Vector2;
@@ -426,6 +454,7 @@ declare abstract class Collider extends Component {
onRemovedFromEntity(): void;
onEnabled(): void;
onDisabled(): void;
+ onEntityTransformChanged(comp: TransformComponent): void;
}
declare class BoxCollider extends Collider {
width: number;
@@ -501,6 +530,7 @@ declare class ComponentList {
deregisterAllComponents(): void;
registerAllComponents(): void;
updateLists(): void;
+ onEntityTransformChanged(comp: TransformComponent): void;
private handleRemove;
getComponent(type: any, onlyReturnInitializedComponents: boolean): T;
getComponents(typeName: string | any, components?: any): any;
@@ -743,68 +773,29 @@ declare class Matrix2D {
static multiplyTranslation(matrix: Matrix2D, x: number, y: number): Matrix2D;
determinant(): number;
static invert(matrix: Matrix2D, result?: Matrix2D): Matrix2D;
- static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D): Matrix2D;
+ static createTranslation(xPosition: number, yPosition: number): Matrix2D;
+ static createTranslationVector(position: Vector2): Matrix2D;
static createRotation(radians: number, result?: Matrix2D): Matrix2D;
static createScale(xScale: number, yScale: number, result?: Matrix2D): Matrix2D;
toEgretMatrix(): egret.Matrix;
}
-declare class Rectangle {
- x: number;
- y: number;
- width: number;
- height: number;
- private _tempMat;
- private _transformMat;
+declare class Rectangle extends egret.Rectangle {
readonly max: Vector2;
- readonly left: number;
- readonly right: number;
- readonly top: number;
- readonly bottom: number;
readonly center: Vector2;
location: Vector2;
size: Vector2;
- constructor(x?: number, y?: number, width?: number, height?: number);
- intersects(value: Rectangle): boolean;
- contains(value: Vector2): boolean;
+ intersects(value: egret.Rectangle): boolean;
+ containsInVec(value: Vector2): boolean;
containsRect(value: Rectangle): boolean;
getHalfSize(): Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
- getClosestPointOnRectangleBorderToPoint(point: Point): {
+ getClosestPointOnRectangleBorderToPoint(point: Vector2): {
res: Vector2;
edgeNormal: Vector2;
};
getClosestPointOnBoundsToOrigin(): Vector2;
- calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2, rotation: number, width: number, height: number): void;
static rectEncompassingPoints(points: Vector2[]): Rectangle;
}
-declare class Vector2 {
- x: number;
- y: number;
- private static readonly unitYVector;
- private static readonly unitXVector;
- private static readonly unitVector2;
- private static readonly zeroVector2;
- static readonly zero: Vector2;
- static readonly one: Vector2;
- static readonly unitX: Vector2;
- static readonly unitY: Vector2;
- constructor(x?: number, y?: number);
- static add(value1: Vector2, value2: Vector2): Vector2;
- static divide(value1: Vector2, value2: Vector2): Vector2;
- static multiply(value1: Vector2, value2: Vector2): Vector2;
- static subtract(value1: Vector2, value2: Vector2): Vector2;
- normalize(): void;
- length(): number;
- round(): Vector2;
- static normalize(value: Vector2): Vector2;
- static dot(value1: Vector2, value2: Vector2): number;
- static distanceSquared(value1: Vector2, value2: Vector2): number;
- static clamp(value1: Vector2, min: Vector2, max: Vector2): Vector2;
- static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
- static transform(position: Vector2, matrix: Matrix2D): Vector2;
- static distance(value1: Vector2, value2: Vector2): number;
- static negate(value: Vector2): Vector2;
-}
declare class Vector3 {
x: number;
y: number;
@@ -937,7 +928,7 @@ declare class ShapeCollisions {
static closestPointOnLine(lineA: Vector2, lineB: Vector2, closestTo: Vector2): Vector2;
static pointToPoly(point: Vector2, poly: Polygon): CollisionResult;
static circleToCircle(first: Circle, second: Circle): CollisionResult;
- static boxToBox(first: Box, second: Box): false | CollisionResult;
+ static boxToBox(first: Box, second: Box): CollisionResult;
private static minkowskiDifference;
}
declare class SpatialHash {
@@ -1044,7 +1035,7 @@ declare class Pair {
equals(other: Pair): boolean;
}
declare class RectangleExt {
- static union(first: Rectangle, point: Point): Rectangle;
+ static union(first: Rectangle, point: Vector2): Rectangle;
static unionR(value1: Rectangle, value2: Rectangle): Rectangle;
}
declare class Triangulator {
diff --git a/source/bin/framework.js b/source/bin/framework.js
index c5fa6467..b8d3301d 100644
--- a/source/bin/framework.js
+++ b/source/bin/framework.js
@@ -361,10 +361,10 @@ var AStarNode = (function (_super) {
var AstarGridGraph = (function () {
function AstarGridGraph(width, height) {
this.dirs = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, 1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, 1)
];
this.walls = [];
this.weightedNodes = [];
@@ -387,7 +387,7 @@ var AstarGridGraph = (function () {
var _this = this;
this._neighbors.length = 0;
this.dirs.forEach(function (dir) {
- var next = new Point(node.x + dir.x, node.y + dir.y);
+ var next = new Vector2(node.x + dir.x, node.y + dir.y);
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
_this._neighbors.push(next);
});
@@ -583,12 +583,113 @@ var UnweightedGraph = (function () {
};
return UnweightedGraph;
}());
-var Point = (function () {
- function Point(x, y) {
+var Vector2 = (function () {
+ function Vector2(x, y) {
+ this.x = 0;
+ this.y = 0;
this.x = x ? x : 0;
this.y = y ? y : this.x;
}
- return Point;
+ Object.defineProperty(Vector2, "zero", {
+ get: function () {
+ return Vector2.zeroVector2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "one", {
+ get: function () {
+ return Vector2.unitVector2;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "unitX", {
+ get: function () {
+ return Vector2.unitXVector;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Vector2, "unitY", {
+ get: function () {
+ return Vector2.unitYVector;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Vector2.add = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x + value2.x;
+ result.y = value1.y + value2.y;
+ return result;
+ };
+ Vector2.divide = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x / value2.x;
+ result.y = value1.y / value2.y;
+ return result;
+ };
+ Vector2.multiply = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x * value2.x;
+ result.y = value1.y * value2.y;
+ return result;
+ };
+ Vector2.subtract = function (value1, value2) {
+ var result = new Vector2(0, 0);
+ result.x = value1.x - value2.x;
+ result.y = value1.y - value2.y;
+ return result;
+ };
+ Vector2.prototype.normalize = function () {
+ var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
+ this.x *= val;
+ this.y *= val;
+ };
+ Vector2.prototype.length = function () {
+ return Math.sqrt((this.x * this.x) + (this.y * this.y));
+ };
+ Vector2.prototype.round = function () {
+ return new Vector2(Math.round(this.x), Math.round(this.y));
+ };
+ Vector2.normalize = function (value) {
+ var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
+ value.x *= val;
+ value.y *= val;
+ return value;
+ };
+ Vector2.dot = function (value1, value2) {
+ return (value1.x * value2.x) + (value1.y * value2.y);
+ };
+ Vector2.distanceSquared = function (value1, value2) {
+ var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
+ return (v1 * v1) + (v2 * v2);
+ };
+ Vector2.clamp = function (value1, min, max) {
+ return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y));
+ };
+ Vector2.lerp = function (value1, value2, amount) {
+ return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
+ };
+ Vector2.transform = function (position, matrix) {
+ return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22));
+ };
+ Vector2.distance = function (value1, value2) {
+ var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
+ return Math.sqrt((v1 * v1) + (v2 * v2));
+ };
+ Vector2.negate = function (value) {
+ var result = new Vector2();
+ result.x = -value.x;
+ result.y = -value.y;
+ return result;
+ };
+ Vector2.unitYVector = new Vector2(0, 1);
+ Vector2.unitXVector = new Vector2(1, 0);
+ Vector2.unitVector2 = new Vector2(1, 1);
+ Vector2.zeroVector2 = new Vector2(0, 0);
+ return Vector2;
}());
var UnweightedGridGraph = (function () {
function UnweightedGridGraph(width, height, allowDiagonalSearch) {
@@ -609,7 +710,7 @@ var UnweightedGridGraph = (function () {
var _this = this;
this._neighbors.length = 0;
this._dirs.forEach(function (dir) {
- var next = new Point(node.x + dir.x, node.y + dir.y);
+ var next = new Vector2(node.x + dir.x, node.y + dir.y);
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
_this._neighbors.push(next);
});
@@ -619,20 +720,20 @@ var UnweightedGridGraph = (function () {
return BreadthFirstPathfinder.search(this, start, goal);
};
UnweightedGridGraph.CARDINAL_DIRS = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, -1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, -1)
];
UnweightedGridGraph.COMPASS_DIRS = [
- new Point(1, 0),
- new Point(1, -1),
- new Point(0, -1),
- new Point(-1, -1),
- new Point(-1, 0),
- new Point(-1, 1),
- new Point(0, 1),
- new Point(1, 1),
+ new Vector2(1, 0),
+ new Vector2(1, -1),
+ new Vector2(0, -1),
+ new Vector2(-1, -1),
+ new Vector2(-1, 0),
+ new Vector2(-1, 1),
+ new Vector2(0, 1),
+ new Vector2(1, 1),
];
return UnweightedGridGraph;
}());
@@ -661,7 +762,7 @@ var WeightedGridGraph = (function () {
var _this = this;
this._neighbors.length = 0;
this._dirs.forEach(function (dir) {
- var next = new Point(node.x + dir.x, node.y + dir.y);
+ var next = new Vector2(node.x + dir.x, node.y + dir.y);
if (_this.isNodeInBounds(next) && _this.isNodePassable(next))
_this._neighbors.push(next);
});
@@ -671,20 +772,20 @@ var WeightedGridGraph = (function () {
return this.weightedNodes.find(function (t) { return JSON.stringify(t) == JSON.stringify(to); }) ? this.weightedNodeWeight : this.defaultWeight;
};
WeightedGridGraph.CARDINAL_DIRS = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, 1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, 1)
];
WeightedGridGraph.COMPASS_DIRS = [
- new Point(1, 0),
- new Point(1, -1),
- new Point(0, -1),
- new Point(-1, -1),
- new Point(-1, 0),
- new Point(-1, 1),
- new Point(0, 1),
- new Point(1, 1),
+ new Vector2(1, 0),
+ new Vector2(1, -1),
+ new Vector2(0, -1),
+ new Vector2(-1, -1),
+ new Vector2(-1, 0),
+ new Vector2(-1, 1),
+ new Vector2(0, 1),
+ new Vector2(1, 1),
];
return WeightedGridGraph;
}());
@@ -816,6 +917,8 @@ var Component = (function (_super) {
};
Component.prototype.debugRender = function () {
};
+ Component.prototype.onEntityTransformChanged = function (comp) {
+ };
Component.prototype.registerComponent = function () {
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
this.entity.scene.entityProcessors.onComponentAdded(this.entity);
@@ -830,7 +933,6 @@ var Entity = (function (_super) {
__extends(Entity, _super);
function Entity(name) {
var _this = _super.call(this) || this;
- _this._position = Vector2.zero;
_this._updateOrder = 0;
_this._enabled = true;
_this._tag = 0;
@@ -849,10 +951,12 @@ var Entity = (function (_super) {
});
Object.defineProperty(Entity.prototype, "position", {
get: function () {
- return this._position;
+ return new Vector2(this.x, this.y);
},
set: function (value) {
- this._position = value;
+ this.$setX(value.x);
+ this.$setY(value.y);
+ this.onEntityTransformChanged(TransformComponent.position);
},
enumerable: true,
configurable: true
@@ -862,8 +966,17 @@ var Entity = (function (_super) {
return new Vector2(this.scaleX, this.scaleY);
},
set: function (value) {
- this.scaleX = value.x;
- this.scaleY = value.y;
+ this.$setScaleX(value.x);
+ this.$setScaleY(value.y);
+ this.onEntityTransformChanged(TransformComponent.scale);
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Entity.prototype, "rotation", {
+ set: function (value) {
+ this.$setRotation(value);
+ this.onEntityTransformChanged(TransformComponent.rotation);
},
enumerable: true,
configurable: true
@@ -973,6 +1086,9 @@ var Entity = (function (_super) {
Entity.prototype.getComponents = function (typeName, componentList) {
return this.components.getComponents(typeName, componentList);
};
+ Entity.prototype.onEntityTransformChanged = function (comp) {
+ this.components.onEntityTransformChanged(comp);
+ };
Entity.prototype.removeComponentForType = function (type) {
var comp = this.getComponent(type);
if (comp) {
@@ -1009,6 +1125,12 @@ var Entity = (function (_super) {
};
return Entity;
}(egret.DisplayObjectContainer));
+var TransformComponent;
+(function (TransformComponent) {
+ TransformComponent[TransformComponent["rotation"] = 0] = "rotation";
+ TransformComponent[TransformComponent["scale"] = 1] = "scale";
+ TransformComponent[TransformComponent["position"] = 2] = "position";
+})(TransformComponent || (TransformComponent = {}));
var Scene = (function (_super) {
__extends(Scene, _super);
function Scene() {
@@ -1112,6 +1234,8 @@ var Scene = (function (_super) {
if (this.entityProcessors)
this.entityProcessors.end();
this.unload();
+ if (this.parent)
+ this.parent.removeChild(this);
};
Scene.prototype.onStart = function () {
return __awaiter(this, void 0, void 0, function () {
@@ -1251,6 +1375,7 @@ var Camera = (function (_super) {
_this._origin = Vector2.zero;
_this._minimumZoom = 0.3;
_this._maximumZoom = 3;
+ _this._position = Vector2.zero;
_this.followLerp = 0.1;
_this.deadzone = new Rectangle();
_this.focusOffset = new Vector2();
@@ -1312,10 +1437,30 @@ var Camera = (function (_super) {
});
Object.defineProperty(Camera.prototype, "position", {
get: function () {
- return this.entity.position;
+ return this._position;
},
set: function (value) {
- this.entity.position = value;
+ this._position = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "x", {
+ get: function () {
+ return this._position.x;
+ },
+ set: function (value) {
+ this._position.x = value;
+ },
+ enumerable: true,
+ configurable: true
+ });
+ Object.defineProperty(Camera.prototype, "y", {
+ get: function () {
+ return this._position.y;
+ },
+ set: function (value) {
+ this._position.y = value;
},
enumerable: true,
configurable: true
@@ -1553,22 +1698,6 @@ var SpriteRenderer = (function (_super) {
function SpriteRenderer() {
return _super !== null && _super.apply(this, arguments) || this;
}
- Object.defineProperty(SpriteRenderer.prototype, "origin", {
- get: function () {
- return this._origin;
- },
- set: function (value) {
- this.setOrigin(value);
- },
- enumerable: true,
- configurable: true
- });
- SpriteRenderer.prototype.setOrigin = function (origin) {
- if (this._origin != origin) {
- this._origin = origin;
- }
- return this;
- };
Object.defineProperty(SpriteRenderer.prototype, "sprite", {
get: function () {
return this._sprite;
@@ -1582,8 +1711,10 @@ var SpriteRenderer = (function (_super) {
SpriteRenderer.prototype.setSprite = function (sprite) {
this.removeChildren();
this._sprite = sprite;
- if (this._sprite)
- this._origin = this._sprite.origin;
+ if (this._sprite) {
+ this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width;
+ this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height;
+ }
this.bitmap = new egret.Bitmap(sprite.texture2D);
this.addChild(this.bitmap);
return this;
@@ -1608,8 +1739,8 @@ var SpriteRenderer = (function (_super) {
return this.isVisible;
};
SpriteRenderer.prototype.render = function (camera) {
- this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x;
- this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y;
+ this.x = -camera.position.x + camera.origin.x;
+ this.y = -camera.position.y + camera.origin.y;
};
SpriteRenderer.prototype.onRemovedFromEntity = function () {
if (this.parent)
@@ -1874,27 +2005,23 @@ var Collider = (function (_super) {
function Collider() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.physicsLayer = 1 << 0;
- _this.shouldColliderScaleAndRotationWithTransform = true;
+ _this.registeredPhysicsBounds = new Rectangle();
+ _this.shouldColliderScaleAndRotateWithTransform = true;
_this.collidesWithLayers = Physics.allLayers;
- _this._isPositionDirty = true;
- _this._isRotationDirty = true;
_this._localOffset = new Vector2(0, 0);
return _this;
}
Object.defineProperty(Collider.prototype, "bounds", {
get: function () {
- if (this._isPositionDirty || this._isRotationDirty) {
- this.shape.recalculateBounds(this);
- this._isPositionDirty = this._isRotationDirty = false;
- }
- return this.shape.bounds;
+ var bds = this.entity.getBounds();
+ return new Rectangle(bds.x, bds.y, bds.width, bds.height);
},
enumerable: true,
configurable: true
});
Object.defineProperty(Collider.prototype, "localOffset", {
get: function () {
- return this._localOffset;
+ return new Vector2(this.x, this.y);
},
set: function (value) {
this.setLocalOffset(value);
@@ -1905,9 +2032,9 @@ var Collider = (function (_super) {
Collider.prototype.setLocalOffset = function (offset) {
if (this._localOffset != offset) {
this.unregisterColliderWithPhysicsSystem();
- this._localOffset = offset;
+ this.$setX(offset.x);
+ this.$setY(offset.y);
this._localOffsetLength = this._localOffset.length();
- this._isPositionDirty = true;
this.registerColliderWithPhysicsSystem();
}
};
@@ -1940,17 +2067,15 @@ var Collider = (function (_super) {
if (!(this instanceof BoxCollider)) {
console.error("Only box and circle colliders can be created automatically");
}
- var renderable = this.entity.getComponent(RenderableComponent);
- if (renderable) {
- var renderbaleBounds = renderable.bounds;
- var width = renderbaleBounds.width / this.entity.scale.x;
- var height = renderbaleBounds.height / this.entity.scale.y;
- if (this instanceof BoxCollider) {
- var boxCollider = this;
- boxCollider.width = width;
- boxCollider.height = height;
- this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
- }
+ var bounds = this.entity.getBounds();
+ var renderbaleBounds = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
+ var width = renderbaleBounds.width / this.entity.scale.x;
+ var height = renderbaleBounds.height / this.entity.scale.y;
+ if (this instanceof BoxCollider) {
+ var boxCollider = this;
+ boxCollider.width = width;
+ boxCollider.height = height;
+ this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
}
}
this._isParentEntityAddedToScene = true;
@@ -1962,11 +2087,14 @@ var Collider = (function (_super) {
};
Collider.prototype.onEnabled = function () {
this.registerColliderWithPhysicsSystem();
- this._isPositionDirty = this._isRotationDirty = true;
};
Collider.prototype.onDisabled = function () {
this.unregisterColliderWithPhysicsSystem();
};
+ Collider.prototype.onEntityTransformChanged = function (comp) {
+ if (this._isColliderRegistered)
+ Physics.updateCollider(this);
+ };
return Collider;
}(Component));
var BoxCollider = (function (_super) {
@@ -1992,7 +2120,6 @@ var BoxCollider = (function (_super) {
var box = this.shape;
if (width != box.width) {
box.updateBox(width, box.height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -2013,7 +2140,6 @@ var BoxCollider = (function (_super) {
var box = this.shape;
if (height != box.height) {
box.updateBox(box.width, height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -2023,7 +2149,6 @@ var BoxCollider = (function (_super) {
var box = this.shape;
if (width != box.width || height != box.height) {
box.updateBox(width, height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -2334,6 +2459,16 @@ var ComponentList = (function () {
this._tempBufferList.length = 0;
}
};
+ ComponentList.prototype.onEntityTransformChanged = function (comp) {
+ for (var i = 0; i < this._components.length; i++) {
+ if (this._components[i].enabled)
+ this._components[i].onEntityTransformChanged(comp);
+ }
+ for (var i = 0; i < this._componentsToAdd.length; i++) {
+ if (this._componentsToAdd[i].enabled)
+ this._componentsToAdd[i].onEntityTransformChanged(comp);
+ }
+ };
ComponentList.prototype.handleRemove = function (component) {
if (component instanceof RenderableComponent)
this._entity.scene.renderableComponents.remove(component);
@@ -3340,8 +3475,8 @@ var Matrix2D = (function () {
result.m32 = -(matrix.m32 * matrix.m11 - matrix.m31 * matrix.m12) * det;
return result;
};
- Matrix2D.createTranslation = function (xPosition, yPosition, result) {
- result = result ? result : new Matrix2D();
+ Matrix2D.createTranslation = function (xPosition, yPosition) {
+ var result = new Matrix2D();
result.m11 = 1;
result.m12 = 0;
result.m21 = 0;
@@ -3350,6 +3485,9 @@ var Matrix2D = (function () {
result.m32 = yPosition;
return result;
};
+ Matrix2D.createTranslationVector = function (position) {
+ return this.createTranslation(position.x, position.y);
+ };
Matrix2D.createRotation = function (radians, result) {
result = new Matrix2D();
var val1 = Math.cos(radians);
@@ -3377,12 +3515,10 @@ var Matrix2D = (function () {
Matrix2D._identity = new Matrix2D(1, 0, 0, 1, 0, 0);
return Matrix2D;
}());
-var Rectangle = (function () {
- function Rectangle(x, y, width, height) {
- this.x = x ? x : 0;
- this.y = y ? y : 0;
- this.width = width ? width : 0;
- this.height = height ? height : 0;
+var Rectangle = (function (_super) {
+ __extends(Rectangle, _super);
+ function Rectangle() {
+ return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(Rectangle.prototype, "max", {
get: function () {
@@ -3391,34 +3527,6 @@ var Rectangle = (function () {
enumerable: true,
configurable: true
});
- Object.defineProperty(Rectangle.prototype, "left", {
- get: function () {
- return this.x;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "right", {
- get: function () {
- return this.x + this.width;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "top", {
- get: function () {
- return this.y;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Rectangle.prototype, "bottom", {
- get: function () {
- return this.y + this.height;
- },
- enumerable: true,
- configurable: true
- });
Object.defineProperty(Rectangle.prototype, "center", {
get: function () {
return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
@@ -3454,7 +3562,7 @@ var Rectangle = (function () {
value.top < this.bottom &&
this.top < value.bottom;
};
- Rectangle.prototype.contains = function (value) {
+ Rectangle.prototype.containsInVec = function (value) {
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
(this.y <= value.y)) &&
(value.y < (this.y + this.height)));
@@ -3471,11 +3579,11 @@ var Rectangle = (function () {
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
};
Rectangle.prototype.getClosestPointOnRectangleBorderToPoint = function (point) {
- var edgeNormal = new Vector2(0, 0);
- var res = new Vector2(0, 0);
+ var edgeNormal = Vector2.zero;
+ var res = new Vector2();
res.x = MathHelper.clamp(point.x, this.left, this.right);
res.y = MathHelper.clamp(point.y, this.top, this.bottom);
- if (this.contains(res)) {
+ if (this.containsInVec(res)) {
var dl = res.x - this.left;
var dr = this.right - res.x;
var dt = res.y - this.top;
@@ -3499,18 +3607,14 @@ var Rectangle = (function () {
}
}
else {
- if (res.x == this.left) {
+ if (res.x == this.left)
edgeNormal.x = -1;
- }
- if (res.x == this.right) {
+ if (res.x == this.right)
edgeNormal.x = 1;
- }
- if (res.y == this.top) {
+ if (res.y == this.top)
edgeNormal.y = -1;
- }
- if (res.y == this.bottom) {
+ if (res.y == this.bottom)
edgeNormal.y = 1;
- }
}
return { res: res, edgeNormal: edgeNormal };
};
@@ -3535,40 +3639,6 @@ var Rectangle = (function () {
}
return boundsPoint;
};
- Rectangle.prototype.calculateBounds = function (parentPosition, position, origin, scale, rotation, width, height) {
- if (rotation == 0) {
- this.x = parentPosition.x + position.x - origin.x * scale.x;
- this.y = parentPosition.y + position.y - origin.y * scale.y;
- this.width = width * scale.x;
- this.height = height * scale.y;
- }
- else {
- var worldPosX = parentPosition.x + position.x;
- var worldPosY = parentPosition.y + position.y;
- this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y);
- this._tempMat = Matrix2D.createScale(scale.x, scale.y);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- this._tempMat = Matrix2D.createRotation(rotation);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- var topLeft = new Vector2(worldPosX, worldPosY);
- var topRight = new Vector2(worldPosX + width, worldPosY);
- var bottomLeft = new Vector2(worldPosX, worldPosY + height);
- var bottomRight = new Vector2(worldPosX + width, worldPosY + height);
- topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
- topRight = Vector2Ext.transformR(topRight, this._transformMat);
- bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
- bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
- var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
- var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
- var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
- var maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
- this.location = new Vector2(minX, minY);
- this.width = maxX - minX;
- this.height = maxY - minY;
- }
- };
Rectangle.rectEncompassingPoints = function (points) {
var minX = Number.POSITIVE_INFINITY;
var minY = Number.POSITIVE_INFINITY;
@@ -3576,131 +3646,19 @@ var Rectangle = (function () {
var maxY = Number.NEGATIVE_INFINITY;
for (var i = 0; i < points.length; i++) {
var pt = points[i];
- if (pt.x < minX) {
+ if (pt.x < minX)
minX = pt.x;
- }
- if (pt.x > maxX) {
+ if (pt.x > maxX)
maxX = pt.x;
- }
- if (pt.y < minY) {
+ if (pt.y < minY)
minY = pt.y;
- }
- if (pt.y > maxY) {
+ if (pt.y > maxY)
maxY = pt.y;
- }
}
return this.fromMinMax(minX, minY, maxX, maxY);
};
return Rectangle;
-}());
-var Vector2 = (function () {
- function Vector2(x, y) {
- this.x = 0;
- this.y = 0;
- this.x = x ? x : 0;
- this.y = y ? y : this.x;
- }
- Object.defineProperty(Vector2, "zero", {
- get: function () {
- return Vector2.zeroVector2;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "one", {
- get: function () {
- return Vector2.unitVector2;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "unitX", {
- get: function () {
- return Vector2.unitXVector;
- },
- enumerable: true,
- configurable: true
- });
- Object.defineProperty(Vector2, "unitY", {
- get: function () {
- return Vector2.unitYVector;
- },
- enumerable: true,
- configurable: true
- });
- Vector2.add = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x + value2.x;
- result.y = value1.y + value2.y;
- return result;
- };
- Vector2.divide = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x / value2.x;
- result.y = value1.y / value2.y;
- return result;
- };
- Vector2.multiply = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x * value2.x;
- result.y = value1.y * value2.y;
- return result;
- };
- Vector2.subtract = function (value1, value2) {
- var result = new Vector2(0, 0);
- result.x = value1.x - value2.x;
- result.y = value1.y - value2.y;
- return result;
- };
- Vector2.prototype.normalize = function () {
- var val = 1 / Math.sqrt((this.x * this.x) + (this.y * this.y));
- this.x *= val;
- this.y *= val;
- };
- Vector2.prototype.length = function () {
- return Math.sqrt((this.x * this.x) + (this.y * this.y));
- };
- Vector2.prototype.round = function () {
- return new Vector2(Math.round(this.x), Math.round(this.y));
- };
- Vector2.normalize = function (value) {
- var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
- value.x *= val;
- value.y *= val;
- return value;
- };
- Vector2.dot = function (value1, value2) {
- return (value1.x * value2.x) + (value1.y * value2.y);
- };
- Vector2.distanceSquared = function (value1, value2) {
- var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
- return (v1 * v1) + (v2 * v2);
- };
- Vector2.clamp = function (value1, min, max) {
- return new Vector2(MathHelper.clamp(value1.x, min.x, max.x), MathHelper.clamp(value1.y, min.y, max.y));
- };
- Vector2.lerp = function (value1, value2, amount) {
- return new Vector2(MathHelper.lerp(value1.x, value2.x, amount), MathHelper.lerp(value1.y, value2.y, amount));
- };
- Vector2.transform = function (position, matrix) {
- return new Vector2((position.x * matrix.m11) + (position.y * matrix.m21), (position.x * matrix.m12) + (position.y * matrix.m22));
- };
- Vector2.distance = function (value1, value2) {
- var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
- return Math.sqrt((v1 * v1) + (v2 * v2));
- };
- Vector2.negate = function (value) {
- var result = new Vector2();
- result.x = -value.x;
- result.y = -value.y;
- return result;
- };
- Vector2.unitYVector = new Vector2(0, 1);
- Vector2.unitXVector = new Vector2(1, 0);
- Vector2.unitVector2 = new Vector2(1, 1);
- Vector2.zeroVector2 = new Vector2(0, 0);
- return Vector2;
-}());
+}(egret.Rectangle));
var Vector3 = (function () {
function Vector3(x, y, z) {
this.x = x;
@@ -4099,7 +4057,7 @@ var Polygon = (function (_super) {
};
Polygon.prototype.recalculateBounds = function (collider) {
this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotationWithTransform) {
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
var hasUnitScale = true;
var tempMat = void 0;
var combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
@@ -4111,7 +4069,7 @@ var Polygon = (function (_super) {
this.center = scaledOffset;
}
if (collider.entity.rotation != 0) {
- tempMat = Matrix2D.createRotation(collider.entity.rotation);
+ tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat);
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
var offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
@@ -4121,8 +4079,6 @@ var Polygon = (function (_super) {
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
this.isUnrotated = collider.entity.rotation == 0;
- if (collider._isRotationDirty)
- this._areEdgeNormalsDirty = true;
}
this.position = Vector2.add(collider.entity.position, this.center);
this.bounds = Rectangle.rectEncompassingPoints(this.points);
@@ -4177,7 +4133,7 @@ var Box = (function (_super) {
};
Box.prototype.containsPoint = function (point) {
if (this.isUnrotated)
- return this.bounds.contains(point);
+ return this.bounds.containsInVec(point);
return _super.prototype.containsPoint.call(this, point);
};
return Box;
@@ -4207,7 +4163,7 @@ var Circle = (function (_super) {
};
Circle.prototype.recalculateBounds = function (collider) {
this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotationWithTransform) {
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
var scale = collider.entity.scale;
var hasUnitScale = scale.x == 1 && scale.y == 1;
var maxScale = Math.max(scale.x, scale.y);
@@ -4291,7 +4247,7 @@ var ShapeCollisions = (function () {
}
}
result.normal = translationAxis;
- result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance));
+ result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance));
return result;
};
ShapeCollisions.intervalDistance = function (minA, maxA, minB, maxB) {
@@ -4414,10 +4370,10 @@ var ShapeCollisions = (function () {
ShapeCollisions.boxToBox = function (first, second) {
var result = new CollisionResult();
var minkowskiDiff = this.minkowskiDifference(first, second);
- if (minkowskiDiff.contains(new Vector2(0, 0))) {
+ if (minkowskiDiff.containsInVec(new Vector2(0, 0))) {
result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
- if (result.minimumTranslationVector == Vector2.zero)
- return false;
+ if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0)
+ return null;
result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y);
result.normal.normalize();
return result;
@@ -4436,6 +4392,7 @@ var SpatialHash = (function () {
function SpatialHash(cellSize) {
if (cellSize === void 0) { cellSize = 100; }
this.gridBounds = new Rectangle();
+ this._overlapTestCircle = new Circle(0);
this._tempHashSet = [];
this._cellDict = new NumberDictionary();
this._cellSize = cellSize;
@@ -4461,10 +4418,10 @@ var SpatialHash = (function () {
collider.registeredPhysicsBounds = bounds;
var p1 = this.cellCoords(bounds.x, bounds.y);
var p2 = this.cellCoords(bounds.right, bounds.bottom);
- if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) {
+ if (!this.gridBounds.containsInVec(new Vector2(p1.x, p1.y))) {
this.gridBounds = RectangleExt.union(this.gridBounds, p1);
}
- if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) {
+ if (!this.gridBounds.containsInVec(new Vector2(p2.x, p2.y))) {
this.gridBounds = RectangleExt.union(this.gridBounds, p2);
}
for (var x = p1.x; x <= p2.x; x++) {
@@ -4533,7 +4490,7 @@ var SpatialHash = (function () {
return cell;
};
SpatialHash.prototype.cellCoords = function (x, y) {
- return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
+ return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
};
return SpatialHash;
}());
diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js
index acd75eeb..e9723556 100644
--- a/source/bin/framework.min.js
+++ b/source/bin/framework.min.js
@@ -1 +1 @@
-window.framework={},window.__extends=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}();var __awaiter=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))(function(o,r){function s(t){try{c(i.next(t))}catch(t){r(t)}}function a(t){try{c(i.throw(t))}catch(t){r(t)}}function c(t){t.done?o(t.value):new n(function(e){e(t.value)}).then(s,a)}c((i=i.apply(t,e||[])).next())})},__generator=this&&this.__generator||function(t,e){var n,i,o,r,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,i&&(o=2&r[0]?i.return:r[0]?i.throw||((o=i.return)&&o.call(i),0):i.next)&&!(o=o.call(i,r[1])).done)return o;switch(i=0,o&&(r=[2&r[0],o.value]),r[0]){case 0:case 1:o=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,i=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Point(1,0),new Point(0,-1),new Point(-1,0),new Point(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Point=function(){return function(t,e){this.x=t||0,this.y=e||this.x}}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._position=Vector2.zero,i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return this._position},set:function(t){this._position=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.scaleX=t.x,this.scaleY=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer),Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"origin",{get:function(){return this._origin},set:function(t){this.setOrigin(t)},enumerable:!0,configurable:!0}),e.prototype.setOrigin=function(t){return this._origin!=t&&(this._origin=t),this},Object.defineProperty(e.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this._origin=this._sprite.origin),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=this.entity.position.x-this.origin.x-t.position.x+t.origin.x,this.y=this.entity.position.y-this.origin.y-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var o=Math.floor(i/e),r=t.sprites.length;if(r>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=r-1;this.currentFrame=s-Math.abs(s-o%(2*s))}else this.currentFrame=o%r;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.Bitmap(this.sprite.texture2D),o=new egret.Rectangle(this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height);n.drawToTexture(i,o),this.bitmap.texture=n}},e}(SpriteRenderer),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n,i){return(i=i||new t).m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,n,i){this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0}return Object.defineProperty(t.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),t.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*o.y-a.y*o.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return o;var u=(c.x*r.y-c.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(h*r.x,h*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],c=e[r],h=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s0&&o[o.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!o||r[1]>o[0]&&r[1]-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var n=t.findIndex(e);return-1==n?null:t[n]}(this,t)},Array.prototype.find=function(t){return function(t,e){return t.firstOrDefault(e)}(this,t)},Array.prototype.where=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return e.call(arguments[2],i,o,t)&&n.push(i),n},[]);for(var n=[],i=0,o=t.length;i=0&&t.splice(n,1)}while(n>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var n=t.findIndex(function(t){return t===e});return n>=0&&(t.splice(n,1),!0)}(this,t)},Array.prototype.removeAt=function(t){return function(t,e){t.splice(e,1)}(this,t)},Array.prototype.removeRange=function(t,e){return function(t,e,n){t.splice(e,n)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(n,i,o){return n.push(e.call(arguments[2],i,o,t)),n},[]);for(var n=[],i=0,o=t.length;ir?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,n){return t.sort(function(t,i){var o=e(t),r=e(i);return n?-n(o,r):o0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),AStarNode=function(t){function e(e){var n=t.call(this)||this;return n.data=e,n}return __extends(e,t),e}(PriorityQueueNode),AstarGridGraph=function(){function t(t,e){this.dirs=[new Vector2(1,0),new Vector2(0,-1),new Vector2(-1,0),new Vector2(0,1)],this.walls=[],this.weightedNodes=[],this.defaultWeight=1,this.weightedNodeWeight=5,this._neighbors=new Array(4),this._width=t,this._height=e}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0&&this.hasHigherPriority(t,n)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,n=t.queueIndex;;){e=t;var i=2*n;if(i>this._numNodes){t.queueIndex=n,this._nodes[n]=t;break}var o=this._nodes[i];this.hasHigherPriority(o,e)&&(e=o);var r=i+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=n,this._nodes[n]=t;break}this._nodes[n]=e;var a=e.queueIndex;e.queueIndex=n,n=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var n=this._nodes[e];if(this.hasHigherPriority(n,t))break;this.swap(t,n),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var n=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=n},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t}(),UnweightedGraph=function(){function t(){this.edges=new Map}return t.prototype.addEdgesForNode=function(t,e){return this.edges.set(t,e),this},t.prototype.getNeighbors=function(t){return this.edges.get(t)},t}(),Vector2=function(){function t(t,e){this.x=0,this.y=0,this.x=t||0,this.y=e||this.x}return Object.defineProperty(t,"zero",{get:function(){return t.zeroVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"one",{get:function(){return t.unitVector2},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitX",{get:function(){return t.unitXVector},enumerable:!0,configurable:!0}),Object.defineProperty(t,"unitY",{get:function(){return t.unitYVector},enumerable:!0,configurable:!0}),t.add=function(e,n){var i=new t(0,0);return i.x=e.x+n.x,i.y=e.y+n.y,i},t.divide=function(e,n){var i=new t(0,0);return i.x=e.x/n.x,i.y=e.y/n.y,i},t.multiply=function(e,n){var i=new t(0,0);return i.x=e.x*n.x,i.y=e.y*n.y,i},t.subtract=function(e,n){var i=new t(0,0);return i.x=e.x-n.x,i.y=e.y-n.y,i},t.prototype.normalize=function(){var t=1/Math.sqrt(this.x*this.x+this.y*this.y);this.x*=t,this.y*=t},t.prototype.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},t.prototype.round=function(){return new t(Math.round(this.x),Math.round(this.y))},t.normalize=function(t){var e=1/Math.sqrt(t.x*t.x+t.y*t.y);return t.x*=e,t.y*=e,t},t.dot=function(t,e){return t.x*e.x+t.y*e.y},t.distanceSquared=function(t,e){var n=t.x-e.x,i=t.y-e.y;return n*n+i*i},t.clamp=function(e,n,i){return new t(MathHelper.clamp(e.x,n.x,i.x),MathHelper.clamp(e.y,n.y,i.y))},t.lerp=function(e,n,i){return new t(MathHelper.lerp(e.x,n.x,i),MathHelper.lerp(e.y,n.y,i))},t.transform=function(e,n){return new t(e.x*n.m11+e.y*n.m21,e.x*n.m12+e.y*n.m22)},t.distance=function(t,e){var n=t.x-e.x,i=t.y-e.y;return Math.sqrt(n*n+i*i)},t.negate=function(e){var n=new t;return n.x=-e.x,n.y=-e.y,n},t.unitYVector=new t(0,1),t.unitXVector=new t(1,0),t.unitVector2=new t(1,1),t.zeroVector2=new t(0,0),t}(),UnweightedGridGraph=function(){function t(e,n,i){void 0===i&&(i=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=n,this._dirs=i?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===c())break}return o?this.recontructPath(r,e,n):null},t.hasKey=function(t,e){for(var n,i=t.keys();!(n=i.next()).done;)if(JSON.stringify(n.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var n,i,o=t.keys(),r=t.values();n=o.next(),i=r.next(),!n.done;)if(JSON.stringify(n.value)==JSON.stringify(e))return i.value;return null},t.recontructPath=function(t,e,n){var i=[],o=n;for(i.push(n);o!=e;)o=this.getKey(t,o),i.push(o);return i.reverse(),i},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._enabled=!0,e.updateInterval=1,e}return __extends(e,t),Object.defineProperty(e.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},e.prototype.initialize=function(){},e.prototype.onAddedToEntity=function(){},e.prototype.onRemovedFromEntity=function(){},e.prototype.onEnabled=function(){},e.prototype.onDisabled=function(){},e.prototype.update=function(){},e.prototype.debugRender=function(){},e.prototype.onEntityTransformChanged=function(t){},e.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},e.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},e}(egret.DisplayObjectContainer),Entity=function(t){function e(n){var i=t.call(this)||this;return i._updateOrder=0,i._enabled=!0,i._tag=0,i.name=n,i.components=new ComponentList(i),i.id=e._idGenerator++,i.componentBits=new BitSet,i}return __extends(e,t),Object.defineProperty(e.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"position",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.$setX(t.x),this.$setY(t.y),this.onEntityTransformChanged(TransformComponent.position)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scale",{get:function(){return new Vector2(this.scaleX,this.scaleY)},set:function(t){this.$setScaleX(t.x),this.$setScaleY(t.y),this.onEntityTransformChanged(TransformComponent.scale)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rotation",{set:function(t){this.$setRotation(t),this.onEntityTransformChanged(TransformComponent.rotation)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),e.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(e.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),e.prototype.roundPosition=function(){this.position=Vector2Ext.round(this.position)},e.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},e.prototype.setTag=function(t){return this._tag!=t&&(this.scene&&this.scene.entities.removeFromTagList(this),this._tag=t,this.scene&&this.scene.entities.addToTagList(this)),this},e.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.getChildAt(t).entity.destroy()}},e}(egret.DisplayObjectContainer);!function(t){t[t.rotation=0]="rotation",t[t.scale=1]="scale",t[t.position=2]="position"}(TransformComponent||(TransformComponent={}));var CameraStyle,Scene=function(t){function e(){var e=t.call(this)||this;return e.enablePostProcessing=!0,e._renderers=[],e._postProcessors=[],e.entityProcessors=new EntityProcessorList,e.renderableComponents=new RenderableComponentList,e.entities=new EntityList(e),e.content=new ContentManager,e.width=SceneManager.stage.stageWidth,e.height=SceneManager.stage.stageHeight,e.addEventListener(egret.Event.ACTIVATE,e.onActive,e),e.addEventListener(egret.Event.DEACTIVATE,e.onDeactive,e),e}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this,this.addChild(t);for(var e=0;e=0;e--)GlobalManager.globalManagers[e].enabled&&GlobalManager.globalManagers[e].update();if(t.sceneTransition&&(!t.sceneTransition||t.sceneTransition.loadsNewScene&&!t.sceneTransition.isNewSceneLoaded)||t._scene.update(),t._nextScene){t._scene.end();for(e=0;et&&(this._zoom=t),this._maximumZoom=t,this},e.prototype.setZoom=function(t){var e=MathHelper.clamp(t,-1,1);return this._zoom=0==e?1:e<0?MathHelper.map(e,-1,0,this._minimumZoom,1):MathHelper.map(e,0,1,1,this._maximumZoom),SceneManager.scene.scaleX=this._zoom,SceneManager.scene.scaleY=this._zoom,this},e.prototype.setRotation=function(t){return SceneManager.scene.rotation=t,this},e.prototype.setPosition=function(t){return this.entity.position=t,this},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this.targetEntity=t,this.cameraStyle=e;var n=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight);switch(this.cameraStyle){case CameraStyle.cameraWindow:var i=n.width/6,o=n.height/3;this.deadzone=new Rectangle((n.width-i)/2,(n.height-o)/2,i,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(n.width/2,n.height/2,10,10)}},e.prototype.update=function(){var t=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),e=Vector2.multiply(new Vector2(t.width,t.height),new Vector2(.5));this._worldSpaceDeadZone.x=this.position.x-e.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.position.y-e.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this.targetEntity&&this.updateFollow(),this.position=Vector2.lerp(this.position,Vector2.add(this.position,this._desiredPositionDelta),this.followLerp),this.entity.roundPosition(),this.mapLockEnabled&&(this.position=this.clampToMapSize(this.position),this.entity.roundPosition())},e.prototype.clampToMapSize=function(t){var e=new Rectangle(0,0,SceneManager.stage.stageWidth,SceneManager.stage.stageHeight),n=Vector2.multiply(new Vector2(e.width,e.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-n.x,this.mapSize.y-n.y);return Vector2.clamp(t,n,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this.cameraStyle==CameraStyle.lockOn){var t=this.targetEntity.position.x,e=this.targetEntity.position.y;this._worldSpaceDeadZone.x>t?this._desiredPositionDelta.x=t-this._worldSpaceDeadZone.x:this._worldSpaceDeadZone.xe&&(this._desiredPositionDelta.y=e-this._worldSpaceDeadZone.y)}else{if(!this._targetCollider&&(this._targetCollider=this.targetEntity.getComponent(Collider),!this._targetCollider))return;var n=this.targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(n)||(this._worldSpaceDeadZone.left>n.left?this._desiredPositionDelta.x=n.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.rightn.top&&(this._desiredPositionDelta.y=n.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var LoopMode,State,ComponentPool=function(){function t(t){this._type=t,this._cache=[]}return t.prototype.obtain=function(){try{return this._cache.length>0?this._cache.shift():new this._type}catch(t){throw new Error(this._type+t)}},t.prototype.free=function(t){t.reset(),this._cache.push(t)},t}(),PooledComponent=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e}(Component),RenderableComponent=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e._areBoundsDirty=!0,e._bounds=new Rectangle,e._localOffset=Vector2.zero,e.color=0,e}return __extends(e,t),Object.defineProperty(e.prototype,"width",{get:function(){return this.getWidth()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"height",{get:function(){return this.getHeight()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isVisible",{get:function(){return this._isVisible},set:function(t){this._isVisible=t,this._isVisible?this.onBecameVisible():this.onBecameInvisible()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bounds",{get:function(){return new Rectangle(this.getBounds().x,this.getBounds().y,this.getBounds().width,this.getBounds().height)},enumerable:!0,configurable:!0}),e.prototype.getWidth=function(){return this.bounds.width},e.prototype.getHeight=function(){return this.bounds.height},e.prototype.onBecameVisible=function(){},e.prototype.onBecameInvisible=function(){},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=t.getBounds().intersects(this.getBounds()),this.isVisible},e}(PooledComponent),Mesh=function(t){function e(){var e=t.call(this)||this;return e._mesh=new egret.Mesh,e}return __extends(e,t),e.prototype.setTexture=function(t){return this._mesh.texture=t,this},e.prototype.onAddedToEntity=function(){this.addChild(this._mesh)},e.prototype.onRemovedFromEntity=function(){this.removeChild(this._mesh)},e.prototype.render=function(t){this.x=this.entity.position.x-t.position.x+t.origin.x,this.y=this.entity.position.y-t.position.y+t.origin.y},e.prototype.reset=function(){},e}(RenderableComponent),Sprite=function(){return function(t,e,n){void 0===e&&(e=new Rectangle(0,0,t.textureWidth,t.textureHeight)),void 0===n&&(n=e.getHalfSize()),this.uvs=new Rectangle,this.texture2D=t,this.sourceRect=e,this.center=new Vector2(.5*e.width,.5*e.height),this.origin=n;var i=1/t.textureWidth,o=1/t.textureHeight;this.uvs.x=e.x*i,this.uvs.y=e.y*o,this.uvs.width=e.width*i,this.uvs.height=e.height*o}}(),SpriteAnimation=function(){return function(t,e){this.sprites=t,this.frameRate=e}}(),SpriteRenderer=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"sprite",{get:function(){return this._sprite},set:function(t){this.setSprite(t)},enumerable:!0,configurable:!0}),e.prototype.setSprite=function(t){return this.removeChildren(),this._sprite=t,this._sprite&&(this.anchorOffsetX=this._sprite.origin.x/this._sprite.sourceRect.width,this.anchorOffsetY=this._sprite.origin.y/this._sprite.sourceRect.height),this.bitmap=new egret.Bitmap(t.texture2D),this.addChild(this.bitmap),this},e.prototype.setColor=function(t){var e=[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0];e[0]=Math.floor(t/256/256)/255,e[6]=Math.floor(t/256%256)/255,e[12]=t%256/255;var n=new egret.ColorMatrixFilter(e);return this.filters=[n],this},e.prototype.isVisibleFromCamera=function(t){return this.isVisible=new Rectangle(0,0,this.stage.stageWidth,this.stage.stageHeight).intersects(this.bounds),this.visible=this.isVisible,this.isVisible},e.prototype.render=function(t){this.x=-t.position.x+t.origin.x,this.y=-t.position.y+t.origin.y},e.prototype.onRemovedFromEntity=function(){this.parent&&this.parent.removeChild(this)},e.prototype.reset=function(){},e}(RenderableComponent),SpriteAnimator=function(t){function e(e){var n=t.call(this)||this;return n.speed=1,n.animationState=State.none,n._animations=new Map,n._elapsedTime=0,e&&n.setSprite(e),n}return __extends(e,t),Object.defineProperty(e.prototype,"isRunning",{get:function(){return this.animationState==State.running},enumerable:!0,configurable:!0}),e.prototype.addAnimation=function(t,e){return!this.sprite&&e.sprites.length>0&&this.setSprite(e.sprites[0]),this._animations[t]=e,this},e.prototype.play=function(t,e){void 0===e&&(e=null),this.currentAnimation=this._animations[t],this.currentAnimationName=t,this.currentFrame=0,this.animationState=State.running,this.sprite=this.currentAnimation.sprites[0],this._elapsedTime=0,this._loopMode=e||LoopMode.loop},e.prototype.isAnimationActive=function(t){return this.currentAnimation&&this.currentAnimationName==t},e.prototype.pause=function(){this.animationState=State.paused},e.prototype.unPause=function(){this.animationState=State.running},e.prototype.stop=function(){this.currentAnimation=null,this.currentAnimationName=null,this.currentFrame=0,this.animationState=State.none},e.prototype.update=function(){if(this.animationState==State.running&&this.currentAnimation){var t=this.currentAnimation,e=1/(t.frameRate*this.speed),n=e*t.sprites.length;this._elapsedTime+=Time.deltaTime;var i=Math.abs(this._elapsedTime);if(this._loopMode==LoopMode.once&&i>n||this._loopMode==LoopMode.pingPongOnce&&i>2*n)return this.animationState=State.completed,this._elapsedTime=0,this.currentFrame=0,void(this.sprite=t.sprites[this.currentFrame]);var o=Math.floor(i/e),r=t.sprites.length;if(r>2&&(this._loopMode==LoopMode.pingPong||this._loopMode==LoopMode.pingPongOnce)){var s=r-1;this.currentFrame=s-Math.abs(s-o%(2*s))}else this.currentFrame=o%r;this.sprite=t.sprites[this.currentFrame]}},e}(SpriteRenderer);!function(t){t[t.loop=0]="loop",t[t.once=1]="once",t[t.clampForever=2]="clampForever",t[t.pingPong=3]="pingPong",t[t.pingPongOnce=4]="pingPongOnce"}(LoopMode||(LoopMode={})),function(t){t[t.none=0]="none",t[t.running=1]="running",t[t.paused=2]="paused",t[t.completed=3]="completed"}(State||(State={}));var PointSectors,TiledSpriteRenderer=function(t){function e(e){var n=t.call(this)||this;return n.setSprite(e),n.sourceRect=e.sourceRect,n}return __extends(e,t),Object.defineProperty(e.prototype,"scrollX",{get:function(){return this.sourceRect.x},set:function(t){this.sourceRect.x=t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"scrollY",{get:function(){return this.sourceRect.y},set:function(t){this.sourceRect.y=t},enumerable:!0,configurable:!0}),e.prototype.render=function(e){if(this.sprite){t.prototype.render.call(this,e);var n=new egret.RenderTexture,i=new egret.Bitmap(this.sprite.texture2D),o=new egret.Rectangle(this.sourceRect.x,this.sourceRect.y,this.sourceRect.width,this.sourceRect.height);n.drawToTexture(i,o),this.bitmap.texture=n}},e}(SpriteRenderer),Mover=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.onAddedToEntity=function(){this._triggerHelper=new ColliderTriggerHelper(this.entity)},e.prototype.calculateMovement=function(t){var e=new CollisionResult;if(!this.entity.getComponent(Collider)||!this._triggerHelper)return null;for(var n=this.entity.getComponents(Collider),i=0;i>6;0!=(e&t.LONG_MASK)&&n++,this._bits=new Array(n)}return t.prototype.and=function(t){for(var e,n=Math.min(this._bits.length,t._bits.length),i=0;i=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var n=this._bits[e];if(0!=n)if(-1!=n){var i=((n=((n=(n>>1&0x5555555555555400)+(0x5555555555555400&n))>>2&0x3333333333333400)+(0x3333333333333400&n))>>32)+n;t+=((i=((i=(i>>4&252645135)+(252645135&i))>>8&16711935)+(16711935&i))>>16&65535)+(65535&i)}else t+=64}return t},t.prototype.clear=function(t){if(null!=t){var e=t>>6;this.ensure(e),this._bits[e]&=~(1<=this._bits.length){var e=new Number[t+1];e=this._bits.copyWithin(0,0,this._bits.length),this._bits=e}},t.prototype.get=function(t){var e=t>>6;return!(e>=this._bits.length)&&0!=(this._bits[e]&1<=0;)if(0!=(this._bits[e]&t._bits[e]))return!0;return!1},t.prototype.isEmpty=function(){for(var t=this._bits.length-1;t>=0;t--)if(this._bits[t])return!1;return!0},t.prototype.nextSetBit=function(t){for(var e=t>>6,n=1<>6;this.ensure(n),this._bits[n]|=1<0){for(var t=0;t0){t=0;for(var e=this._componentsToAdd.length;t0){var e=this._entitiesToRemove;this._entitiesToRemove=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.remove(e),e.scene=null,t.scene.entityProcessors.onEntityRemoved(e)}),this._tempEntityList.length=0}if(this._entitiesToAdded.length>0){e=this._entitiesToAdded;this._entitiesToAdded=this._tempEntityList,this._tempEntityList=e,this._tempEntityList.forEach(function(e){t._entities.contains(e)||(t._entities.push(e),e.scene=t.scene,t.scene.entityProcessors.onEntityAdded(e))}),this._tempEntityList.forEach(function(t){return t.onAddedToScene()}),this._tempEntityList.length=0}this._unsortedTags.length>0&&(this._unsortedTags.forEach(function(e){t._entityDict.get(e).sort()}),this._unsortedTags.length=0)},t}(),EntityProcessorList=function(){function t(){this._processors=[]}return t.prototype.add=function(t){this._processors.push(t)},t.prototype.remove=function(t){this._processors.remove(t)},t.prototype.onComponentAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onComponentRemoved=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityAdded=function(t){this.notifyEntityChanged(t)},t.prototype.onEntityRemoved=function(t){this.removeFromProcessors(t)},t.prototype.notifyEntityChanged=function(t){for(var e=0;e=0;e=this.allSet.nextSetBit(e+1))if(!t.componentBits.get(e))return!1;return!(!this.exclusionSet.isEmpty()&&this.exclusionSet.intersects(t.componentBits))&&!(!this.oneSet.isEmpty()&&!this.oneSet.intersects(t.componentBits))},t.prototype.all=function(){for(var t=this,e=[],n=0;nn?n:t},t.pointOnCirlce=function(e,n,i){var o=t.toRadians(i);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.isEven=function(t){return t%2==0},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,n,i,o,r){this.m11=0,this.m12=0,this.m21=0,this.m22=0,this.m31=0,this.m32=0,this.m11=t||1,this.m12=e||0,this.m21=n||0,this.m22=i||1,this.m31=o||0,this.m32=r||0}return Object.defineProperty(t,"identity",{get:function(){return t._identity},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"translation",{get:function(){return new Vector2(this.m31,this.m32)},set:function(t){this.m31=t.x,this.m32=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return Math.atan2(this.m21,this.m11)},set:function(t){var e=Math.cos(t),n=Math.sin(t);this.m11=e,this.m12=n,this.m21=-n,this.m22=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return MathHelper.toDegrees(this.rotation)},set:function(t){this.rotation=MathHelper.toRadians(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return new Vector2(this.m11,this.m22)},set:function(t){this.m11=t.x,this.m12=t.y},enumerable:!0,configurable:!0}),t.add=function(t,e){return t.m11+=e.m11,t.m12+=e.m12,t.m21+=e.m21,t.m22+=e.m22,t.m31+=e.m31,t.m32+=e.m32,t},t.divide=function(t,e){return t.m11/=e.m11,t.m12/=e.m12,t.m21/=e.m21,t.m22/=e.m22,t.m31/=e.m31,t.m32/=e.m32,t},t.multiply=function(e,n){var i=new t,o=e.m11*n.m11+e.m12*n.m21,r=e.m11*n.m12+e.m12*n.m22,s=e.m21*n.m11+e.m22*n.m21,a=e.m21*n.m12+e.m22*n.m22,c=e.m31*n.m11+e.m32*n.m21+n.m31,h=e.m31*n.m12+e.m32*n.m22+n.m32;return i.m11=o,i.m12=r,i.m21=s,i.m22=a,i.m31=c,i.m32=h,i},t.multiplyTranslation=function(e,n,i){var o=t.createTranslation(n,i);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,n){void 0===n&&(n=new t);var i=1/e.determinant();return n.m11=e.m22*i,n.m12=-e.m12*i,n.m21=-e.m21*i,n.m22=e.m11*i,n.m31=(e.m32*e.m21-e.m31*e.m22)*i,n.m32=-(e.m32*e.m11-e.m31*e.m12)*i,n},t.createTranslation=function(e,n){var i=new t;return i.m11=1,i.m12=0,i.m21=0,i.m22=1,i.m31=e,i.m32=n,i},t.createTranslationVector=function(t){return this.createTranslation(t.x,t.y)},t.createRotation=function(e,n){n=new t;var i=Math.cos(e),o=Math.sin(e);return n.m11=i,n.m12=o,n.m21=-o,n.m22=i,n},t.createScale=function(e,n,i){return void 0===i&&(i=new t),i.m11=e,i.m12=0,i.m21=0,i.m22=n,i.m31=0,i.m32=0,i},t.prototype.toEgretMatrix=function(){return new egret.Matrix(this.m11,this.m12,this.m21,this.m22,this.m31,this.m32)},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),Object.defineProperty(e.prototype,"max",{get:function(){return new Vector2(this.right,this.bottom)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"center",{get:function(){return new Vector2(this.x+this.width/2,this.y+this.height/2)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"location",{get:function(){return new Vector2(this.x,this.y)},set:function(t){this.x=t.x,this.y=t.y},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return new Vector2(this.width,this.height)},set:function(t){this.width=t.x,this.height=t.y},enumerable:!0,configurable:!0}),e.prototype.intersects=function(t){return t.lefti&&(i=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,n,i,o)},e}(egret.Rectangle),Vector3=function(){return function(t,e,n){this.x=t,this.y=e,this.z=n}}(),ColliderTriggerHelper=function(){function t(t){this._activeTriggerIntersections=[],this._previousTriggerIntersections=[],this._tempTriggerList=[],this._entity=t}return t.prototype.update=function(){for(var t=this._entity.getComponents(Collider),e=0;e1)return!1;var h=(a.x*o.y-a.y*o.x)/s;return!(h<0||h>1)},t.lineToLineIntersection=function(t,e,n,i){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(i,n),a=r.x*s.y-r.y*s.x;if(0==a)return o;var c=Vector2.subtract(n,t),h=(c.x*s.y-c.y*s.x)/a;if(h<0||h>1)return o;var u=(c.x*r.y-c.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(h*r.x,h*r.y))},t.closestPointOnLine=function(t,e,n){var i=Vector2.subtract(e,t),o=Vector2.subtract(n,t),r=Vector2.dot(o,i)/Vector2.dot(i,i);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(i.x*r,i.y*r))},t.isCircleToCircle=function(t,e,n,i){return Vector2.distanceSquared(t,n)<(e+i)*(e+i)},t.isCircleToLine=function(t,e,n,i){return Vector2.distanceSquared(t,this.closestPointOnLine(n,i,t))=t&&o.y>=e&&o.x=t+n&&(r|=PointSectors.right),o.y=e+i&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.clear=function(){this._spatialHash.clear()},t.overlapCircleAll=function(t,e,n,i){return void 0===i&&(i=-1),this._spatialHash.overlapCircle(t,e,n,i)},t.boxcastBroadphase=function(t,e){void 0===e&&(e=this.allLayers);var n=this._spatialHash.aabbBroadphase(t,null,e);return{colliders:n.tempHashSet,rect:n.bounds}},t.boxcastBroadphaseExcludingSelf=function(t,e,n){return void 0===n&&(n=this.allLayers),this._spatialHash.aabbBroadphase(e,t,n)},t.addCollider=function(e){t._spatialHash.register(e)},t.removeCollider=function(e){t._spatialHash.remove(e)},t.updateCollider=function(t){this._spatialHash.remove(t),this._spatialHash.register(t)},t.spatialHashCellSize=100,t.allLayers=-1,t}(),Shape=function(){return function(){}}(),Polygon=function(t){function e(e,n){var i=t.call(this)||this;return i.isUnrotated=!0,i._areEdgeNormalsDirty=!0,i.setPoints(e),i.isBox=n,i}return __extends(e,t),Object.defineProperty(e.prototype,"edgeNormals",{get:function(){return this._areEdgeNormalsDirty&&this.buildEdgeNormals(),this._edgeNormals},enumerable:!0,configurable:!0}),e.prototype.buildEdgeNormals=function(){var t,e=this.isBox?2:this.points.length;null!=this._edgeNormals&&this._edgeNormals.length==e||(this._edgeNormals=new Array(e));for(var n=0;n=this.points.length?this.points[0]:this.points[n+1];var o=Vector2Ext.perpendicular(i,t);o=Vector2.normalize(o),this._edgeNormals[n]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[i].y>t.y&&t.x<(this.points[i].x-this.points[n].x)*(t.y-this.points[n].y)/(this.points[i].y-this.points[n].y)+this.points[n].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var n=new Array(t),i=0;i0&&(o=!1),!o)return null;(g=Math.abs(g))i&&(i=o);return{min:n,max:i}},t.circleToPolygon=function(t,e){var n=new CollisionResult,i=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,i),r=o.closestPoint,s=o.distanceSquared;n.normal=o.edgeNormal;var a,c=e.containsPoint(t.position);if(s>t.radius*t.radius&&!c)return null;if(c)a=Vector2.multiply(n.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(n.normal,new Vector2(t.radius));else{var h=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/h))}return n.minimumTranslationVector=a,n.point=Vector2.add(r,e.position),n},t.circleToBox=function(t,e){var n=new CollisionResult,i=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){n.point=i;var o=Vector2.add(i,Vector2.subtract(n.normal,new Vector2(t.radius)));return n.minimumTranslationVector=Vector2.subtract(t.position,o),n}var r=Vector2.distanceSquared(i,t.position);if(0==r)n.minimumTranslationVector=Vector2.multiply(n.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){n.normal=Vector2.subtract(t.position,i);var s=n.normal.length()-t.radius;return n.normal=Vector2Ext.normalize(n.normal),n.minimumTranslationVector=Vector2.multiply(new Vector2(s),n.normal),n}return null},t.pointToCircle=function(t,e){var n=new CollisionResult,i=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(i=0?t:4294967296+t},t.prototype.add=function(t,e,n){this._store.set(this.getKey(t,e),n)},t.prototype.remove=function(t){this._store.forEach(function(e){e.contains(t)&&e.remove(t)})},t.prototype.tryGetValue=function(t,e){return this._store.get(this.getKey(t,e))},t.prototype.clear=function(){this._store.clear()},t}(),ContentManager=function(){function t(){this.loadedAssets=new Map}return t.prototype.loadRes=function(t,e){var n=this;return void 0===e&&(e=!0),new Promise(function(i,o){var r=n.loadedAssets.get(t);r?i(r):e?RES.getResAsync(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)}):RES.getResByUrl(t).then(function(e){n.loadedAssets.set(t,e),i(e)}).catch(function(e){console.error("资源加载错误:",t,e),o(e)})})},t.prototype.dispose=function(){this.loadedAssets.forEach(function(t){t.dispose()}),this.loadedAssets.clear()},t}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var n=this._messageTable.get(t);n||(n=[],this._messageTable.set(t,n)),n.contains(e)&&console.warn("您试图添加相同的观察者两次"),n.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var n=this._messageTable.get(t);if(n)for(var i=n.length-1;i>=0;i--)n[i](e)},t}(),GlobalManager=function(){function t(){}return Object.defineProperty(t.prototype,"enabled",{get:function(){return this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled())},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.update=function(){},t.registerGlobalManager=function(t){this.globalManagers.push(t),t.enabled=!0},t.unregisterGlobalManager=function(t){this.globalManagers.remove(t),t.enabled=!1},t.getGlobalManager=function(t){for(var e=0;e0&&this.setpreviousTouchState(this._gameTouchs[0]),t},enumerable:!0,configurable:!0}),t.initialize=function(t){this._init||(this._init=!0,this._stage=t,this._stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.touchBegin,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_MOVE,this.touchMove,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_END,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_CANCEL,this.touchEnd,this),this._stage.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE,this.touchEnd,this),this.initTouchCache())},t.initTouchCache=function(){this._totalTouchCount=0,this._touchIndex=0,this._gameTouchs.length=0;for(var t=0;t0)for(var e=0;ethis._objectQueue.length;)this._objectQueue.shift()},t.clearCache=function(){this._objectQueue.length=0},t.obtain=function(){return this._objectQueue.length>0?this._objectQueue.shift():[]},t.free=function(t){this._objectQueue.unshift(t),t.length=0},t._objectQueue=[],t}(),Pair=function(){function t(t,e){this.first=t,this.second=e}return t.prototype.clear=function(){this.first=this.second=null},t.prototype.equals=function(t){return this.first==t.first&&this.second==t.second},t}(),RectangleExt=function(){function t(){}return t.union=function(t,e){var n=new Rectangle(e.x,e.y,0,0);return this.unionR(t,n)},t.unionR=function(t,e){var n=new Rectangle;return n.x=Math.min(t.x,e.x),n.y=Math.min(t.y,e.y),n.width=Math.max(t.right,e.right)-n.x,n.height=Math.max(t.bottom,e.bottom)-n.y,n},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,n){void 0===n&&(n=!0);var i=e.length;this.initialize(i);for(var o=0,r=0;i>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],c=e[r],h=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,c,h)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,c,h)){s=!1;break}u=this._triNext[u]}while(u!=this._triPrev[r])}else s=!1;s?(this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),this._triNext[this._triPrev[r]]=this._triNext[r],this._triPrev[this._triNext[r]]=this._triPrev[r],i--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),n||this.triangleIndices.reverse()},t.prototype.initialize=function(t){this.triangleIndices.length=0,this._triNext.lengthMathHelper.Epsilon?t=Vector2.divide(t,new Vector2(e)):t.x=t.y=0,t},t.transformA=function(t,e,n,i,o,r){for(var s=0;s {
- public dirs: Point[] = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, 1)
+class AstarGridGraph implements IAstarGraph {
+ public dirs: Vector2[] = [
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, 1)
];
- public walls: Point[] = [];
- public weightedNodes: Point[] = [];
+ public walls: Vector2[] = [];
+ public weightedNodes: Vector2[] = [];
public defaultWeight: number = 1;
public weightedNodeWeight = 5;
private _width;
private _height;
- private _neighbors: Point[] = new Array(4);
+ private _neighbors: Vector2[] = new Array(4);
constructor(width: number, height: number){
this._width = width;
@@ -28,7 +28,7 @@ class AstarGridGraph implements IAstarGraph {
* 确保节点在网格图的边界内
* @param node
*/
- public isNodeInBounds(node: Point): boolean {
+ public isNodeInBounds(node: Vector2): boolean {
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
}
@@ -36,19 +36,19 @@ class AstarGridGraph implements IAstarGraph {
* 检查节点是否可以通过。墙壁是不可逾越的。
* @param node
*/
- public isNodePassable(node: Point): boolean {
+ public isNodePassable(node: Vector2): boolean {
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
}
- public search(start: Point, goal: Point){
+ public search(start: Vector2, goal: Vector2){
return AStarPathfinder.search(this, start, goal);
}
- public getNeighbors(node: Point): Point[] {
+ public getNeighbors(node: Vector2): Vector2[] {
this._neighbors.length = 0;
this.dirs.forEach(dir => {
- let next = new Point(node.x + dir.x, node.y + dir.y);
+ let next = new Vector2(node.x + dir.x, node.y + dir.y);
if (this.isNodeInBounds(next) && this.isNodePassable(next))
this._neighbors.push(next);
});
@@ -56,11 +56,11 @@ class AstarGridGraph implements IAstarGraph {
return this._neighbors;
}
- public cost(from: Point, to: Point): number {
+ public cost(from: Vector2, to: Vector2): number {
return this.weightedNodes.find((p)=> JSON.stringify(p) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
}
- public heuristic(node: Point, goal: Point) {
+ public heuristic(node: Vector2, goal: Vector2) {
return Math.abs(node.x - goal.x) + Math.abs(node.y - goal.y);
}
diff --git a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts
index 9715df36..f769f398 100644
--- a/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts
+++ b/source/src/AI/Pathfinding/BreadthFirst/UnweightedGridGraph.ts
@@ -1,33 +1,33 @@
-///
+///
/**
* 基本的未加权网格图形用于BreadthFirstPathfinder
*/
-class UnweightedGridGraph implements IUnweightedGraph {
- private static readonly CARDINAL_DIRS: Point[] = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, -1)
+class UnweightedGridGraph implements IUnweightedGraph {
+ private static readonly CARDINAL_DIRS: Vector2[] = [
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, -1)
];
private static readonly COMPASS_DIRS = [
- new Point(1, 0),
- new Point(1, -1),
- new Point(0, -1),
- new Point(-1, -1),
- new Point(-1, 0),
- new Point(-1, 1),
- new Point(0, 1),
- new Point(1, 1),
+ new Vector2(1, 0),
+ new Vector2(1, -1),
+ new Vector2(0, -1),
+ new Vector2(-1, -1),
+ new Vector2(-1, 0),
+ new Vector2(-1, 1),
+ new Vector2(0, 1),
+ new Vector2(1, 1),
];
- public walls: Point[] = [];
+ public walls: Vector2[] = [];
private _width: number;
private _hegiht: number;
- private _dirs: Point[];
- private _neighbors: Point[] = new Array(4);
+ private _dirs: Vector2[];
+ private _neighbors: Vector2[] = new Array(4);
constructor(width: number, height: number, allowDiagonalSearch: boolean = false) {
this._width = width;
@@ -35,19 +35,19 @@ class UnweightedGridGraph implements IUnweightedGraph {
this._dirs = allowDiagonalSearch ? UnweightedGridGraph.COMPASS_DIRS : UnweightedGridGraph.CARDINAL_DIRS;
}
- public isNodeInBounds(node: Point): boolean {
+ public isNodeInBounds(node: Vector2): boolean {
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._hegiht;
}
- public isNodePassable(node: Point): boolean {
+ public isNodePassable(node: Vector2): boolean {
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
}
- public getNeighbors(node: Point) {
+ public getNeighbors(node: Vector2) {
this._neighbors.length = 0;
this._dirs.forEach(dir => {
- let next = new Point(node.x + dir.x, node.y + dir.y);
+ let next = new Vector2(node.x + dir.x, node.y + dir.y);
if (this.isNodeInBounds(next) && this.isNodePassable(next))
this._neighbors.push(next);
});
@@ -55,7 +55,7 @@ class UnweightedGridGraph implements IUnweightedGraph {
return this._neighbors;
}
- public search(start: Point, goal: Point): Point[] {
+ public search(start: Vector2, goal: Vector2): Vector2[] {
return BreadthFirstPathfinder.search(this, start, goal);
}
}
\ No newline at end of file
diff --git a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts
index 7b289deb..474535c1 100644
--- a/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts
+++ b/source/src/AI/Pathfinding/Dijkstra/WeightedGridGraph.ts
@@ -1,35 +1,35 @@
-///
+///
/**
* 支持一种加权节点的基本网格图
*/
-class WeightedGridGraph implements IWeightedGraph {
+class WeightedGridGraph implements IWeightedGraph {
public static readonly CARDINAL_DIRS = [
- new Point(1, 0),
- new Point(0, -1),
- new Point(-1, 0),
- new Point(0, 1)
+ new Vector2(1, 0),
+ new Vector2(0, -1),
+ new Vector2(-1, 0),
+ new Vector2(0, 1)
];
private static readonly COMPASS_DIRS = [
- new Point(1, 0),
- new Point(1, -1),
- new Point(0, -1),
- new Point(-1, -1),
- new Point(-1, 0),
- new Point(-1, 1),
- new Point(0, 1),
- new Point(1, 1),
+ new Vector2(1, 0),
+ new Vector2(1, -1),
+ new Vector2(0, -1),
+ new Vector2(-1, -1),
+ new Vector2(-1, 0),
+ new Vector2(-1, 1),
+ new Vector2(0, 1),
+ new Vector2(1, 1),
];
- public walls: Point[] = [];
- public weightedNodes: Point[] = [];
+ public walls: Vector2[] = [];
+ public weightedNodes: Vector2[] = [];
public defaultWeight = 1;
public weightedNodeWeight = 5;
private _width: number;
private _height: number;
- private _dirs: Point[];
- private _neighbors: Point[] = new Array(4);
+ private _dirs: Vector2[];
+ private _neighbors: Vector2[] = new Array(4);
constructor(width: number, height: number, allowDiagonalSearch: boolean = false){
this._width = width;
@@ -37,23 +37,23 @@ class WeightedGridGraph implements IWeightedGraph {
this._dirs = allowDiagonalSearch ? WeightedGridGraph.COMPASS_DIRS : WeightedGridGraph.CARDINAL_DIRS;
}
- public isNodeInBounds(node: Point){
+ public isNodeInBounds(node: Vector2){
return 0 <= node.x && node.x < this._width && 0 <= node.y && node.y < this._height;
}
- public isNodePassable(node: Point): boolean {
+ public isNodePassable(node: Vector2): boolean {
return !this.walls.firstOrDefault(wall => JSON.stringify(wall) == JSON.stringify(node));
}
- public search(start: Point, goal: Point){
+ public search(start: Vector2, goal: Vector2){
return WeightedPathfinder.search(this, start, goal);
}
- public getNeighbors(node: Point): Point[]{
+ public getNeighbors(node: Vector2): Vector2[]{
this._neighbors.length = 0;
this._dirs.forEach(dir => {
- let next = new Point(node.x + dir.x, node.y + dir.y);
+ let next = new Vector2(node.x + dir.x, node.y + dir.y);
if (this.isNodeInBounds(next) && this.isNodePassable(next))
this._neighbors.push(next);
});
@@ -61,7 +61,7 @@ class WeightedGridGraph implements IWeightedGraph {
return this._neighbors;
}
- public cost(from: Point, to: Point): number{
+ public cost(from: Vector2, to: Vector2): number{
return this.weightedNodes.find(t => JSON.stringify(t) == JSON.stringify(to)) ? this.weightedNodeWeight : this.defaultWeight;
}
}
\ No newline at end of file
diff --git a/source/src/ECS/Component.ts b/source/src/ECS/Component.ts
index a231b29d..a365bab7 100644
--- a/source/src/ECS/Component.ts
+++ b/source/src/ECS/Component.ts
@@ -28,7 +28,6 @@ abstract class Component extends egret.DisplayObjectContainer {
}
public initialize(){
-
}
public onAddedToEntity(){
@@ -55,6 +54,14 @@ abstract class Component extends egret.DisplayObjectContainer {
}
+ /**
+ * 当实体的位置改变时调用。这允许组件知道它们由于父实体的移动而移动了。
+ * @param comp
+ */
+ public onEntityTransformChanged(comp: TransformComponent){
+
+ }
+
/** 内部使用 运行时不应该调用 */
public registerComponent(){
this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this), false);
diff --git a/source/src/ECS/Components/Camera.ts b/source/src/ECS/Components/Camera.ts
index 1f1708ba..9a1f7e68 100644
--- a/source/src/ECS/Components/Camera.ts
+++ b/source/src/ECS/Components/Camera.ts
@@ -6,6 +6,7 @@ class Camera extends Component {
private _minimumZoom = 0.3;
private _maximumZoom = 3;
+ private _position: Vector2 = Vector2.zero;
/**
* 如果相机模式为cameraWindow 则会进行缓动移动
* 该值为移动速度
@@ -67,11 +68,24 @@ class Camera extends Component {
}
public get position(){
- return this.entity.position;
+ return this._position;
}
public set position(value: Vector2){
- this.entity.position = value;
+ this._position = value;
+ }
+
+ public get x(){
+ return this._position.x;
+ }
+ public set x(value: number){
+ this._position.x = value;
+ }
+ public get y(){
+ return this._position.y;
+ }
+ public set y(value: number){
+ this._position.y = value;
}
constructor() {
diff --git a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts
index 98b8470c..14e56800 100644
--- a/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts
+++ b/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts
@@ -8,12 +8,16 @@ class BoxCollider extends Collider {
this.setWidth(value);
}
+ /**
+ * 设置BoxCollider的宽度
+ * @param width
+ */
public setWidth(width: number): BoxCollider{
this._colliderRequiresAutoSizing = false;
let box = this.shape as Box;
if (width != box.width){
+ // 更新框,改变边界,如果我们需要更新物理系统中的边界
box.updateBox(width, box.height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
@@ -29,17 +33,24 @@ class BoxCollider extends Collider {
this.setHeight(value);
}
+ /**
+ * 设置BoxCollider的高度
+ * @param height
+ */
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);
}
}
+ /**
+ * 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
+ */
constructor(){
super();
@@ -52,8 +63,8 @@ class BoxCollider extends Collider {
this._colliderRequiresAutoSizing = false;
let box = this.shape as Box;
if (width != box.width || height != box.height){
+ // 更新框,改变边界,如果我们需要更新物理系统中的边界
box.updateBox(width, height);
- this._isPositionDirty = true;
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
diff --git a/source/src/ECS/Components/Physics/Colliders/Collider.ts b/source/src/ECS/Components/Physics/Colliders/Collider.ts
index a5766250..40493224 100644
--- a/source/src/ECS/Components/Physics/Colliders/Collider.ts
+++ b/source/src/ECS/Components/Physics/Colliders/Collider.ts
@@ -1,32 +1,41 @@
abstract class Collider extends Component{
+ /** 对撞机的基本形状 */
public shape: Shape;
+ /** 在处理冲突时,physicsLayer可以用作过滤器。Flags类有帮助位掩码的方法。 */
public physicsLayer = 1 << 0;
+ /** 如果这个碰撞器是一个触发器,它将不会引起碰撞,但它仍然会触发事件 */
public isTrigger: boolean;
- public registeredPhysicsBounds: Rectangle;
- public shouldColliderScaleAndRotationWithTransform = true;
+ /**
+ * 这个对撞机在物理系统注册时的边界。
+ * 存储这个允许我们始终能够安全地从物理系统中移除对撞机,即使它在试图移除它之前已经被移动了。
+ */
+ public registeredPhysicsBounds: Rectangle = new Rectangle();
+ /** 如果为true,碰撞器将根据附加的变换缩放和旋转 */
+ public shouldColliderScaleAndRotateWithTransform = true;
+ /** 默认为所有层。 */
public collidesWithLayers = Physics.allLayers;
public _localOffsetLength: number;
- public _isPositionDirty = true;
- public _isRotationDirty = true;
+ /** 标记来跟踪我们的实体是否被添加到场景中 */
protected _isParentEntityAddedToScene;
protected _colliderRequiresAutoSizing;
protected _localOffset: Vector2 = new Vector2(0, 0);
+ /** 标记来记录我们是否注册了物理系统 */
protected _isColliderRegistered;
public get bounds(): Rectangle {
- if (this._isPositionDirty || this._isRotationDirty){
- this.shape.recalculateBounds(this);
- this._isPositionDirty = this._isRotationDirty = false;
- }
-
- return this.shape.bounds;
+ // this.shape.recalculateBounds(this);
+ let bds = this.entity.getBounds();
+ return new Rectangle(bds.x, bds.y, bds.width, bds.height);
}
public get localOffset(){
- return this._localOffset;
+ return new Vector2(this.x, this.y);
}
+ /**
+ * 将localOffset添加到实体。获取碰撞器的最终位置。这允许您向一个实体添加多个碰撞器并分别定位它们。
+ */
public set localOffset(value: Vector2){
this.setLocalOffset(value);
}
@@ -34,20 +43,27 @@ abstract class Collider extends Component{
public setLocalOffset(offset: Vector2){
if (this._localOffset != offset){
this.unregisterColliderWithPhysicsSystem();
- this._localOffset = offset;
+ this.$setX(offset.x);
+ this.$setY(offset.y);
this._localOffsetLength = this._localOffset.length();
- this._isPositionDirty = true;
this.registerColliderWithPhysicsSystem();
}
}
+ /**
+ * 父实体会在不同的时间调用它(当添加到场景,启用,等等)
+ */
public registerColliderWithPhysicsSystem(){
+ // 如果在将我们添加到实体之前更改了origin等属性,则实体可以为null
if (this._isParentEntityAddedToScene && !this._isColliderRegistered){
Physics.addCollider(this);
this._isColliderRegistered = true;
}
}
+ /**
+ * 父实体会在不同的时候调用它(从场景中移除,禁用,等等)
+ */
public unregisterColliderWithPhysicsSystem(){
if (this._isParentEntityAddedToScene && this._isColliderRegistered){
Physics.removeCollider(this);
@@ -55,11 +71,21 @@ abstract class Collider extends Component{
this._isColliderRegistered = false;
}
+ /**
+ * 检查这个形状是否与物理系统中的其他对撞机重叠
+ * @param other
+ */
public overlaps(other: Collider){
return this.shape.overlaps(other.shape);
}
+ /**
+ * 检查这个与运动应用的碰撞器(移动向量)是否与碰撞器碰撞。如果是这样,将返回true,并且结果将填充碰撞数据。
+ * @param collider
+ * @param motion
+ */
public collidesWith(collider: Collider, motion: Vector2){
+ // 改变形状的位置,使它在移动后的位置,这样我们可以检查重叠
let oldPosition = this.shape.position;
this.shape.position = Vector2.add(this.shape.position, motion);
@@ -67,6 +93,7 @@ abstract class Collider extends Component{
if (result)
result.collider = collider;
+ // 将图形位置返回到检查前的位置
this.shape.position = oldPosition;
return result;
@@ -78,20 +105,20 @@ abstract class Collider extends Component{
console.error("Only box and circle colliders can be created automatically");
}
- let renderable = this.entity.getComponent(RenderableComponent);
- if (renderable){
- let renderbaleBounds = renderable.bounds;
+ let bounds = this.entity.getBounds();
+ let renderbaleBounds = new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
- let width = renderbaleBounds.width / this.entity.scale.x;
- let height = renderbaleBounds.height / this.entity.scale.y;
+ // 这里我们需要大小*反尺度,因为当我们自动调整碰撞器的大小时,它需要没有缩放的渲染
+ let width = renderbaleBounds.width / this.entity.scale.x;
+ let height = renderbaleBounds.height / this.entity.scale.y;
- if (this instanceof BoxCollider){
- let boxCollider = this as BoxCollider;
- boxCollider.width = width;
- boxCollider.height = height;
+ if (this instanceof BoxCollider){
+ let boxCollider = this as BoxCollider;
+ boxCollider.width = width;
+ boxCollider.height = height;
- this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
- }
+ // 获取渲染的中心,将其转移到本地坐标,并使用它作为碰撞器的localOffset
+ this.localOffset = Vector2.subtract(renderbaleBounds.center, this.entity.position);
}
}
@@ -106,10 +133,14 @@ abstract class Collider extends Component{
public onEnabled(){
this.registerColliderWithPhysicsSystem();
- this._isPositionDirty = this._isRotationDirty = true;
}
public onDisabled(){
this.unregisterColliderWithPhysicsSystem();
}
+
+ public onEntityTransformChanged(comp: TransformComponent){
+ if (this._isColliderRegistered)
+ Physics.updateCollider(this);
+ }
}
\ No newline at end of file
diff --git a/source/src/ECS/Components/Physics/Mover.ts b/source/src/ECS/Components/Physics/Mover.ts
index 6e7c4ce9..1c730d62 100644
--- a/source/src/ECS/Components/Physics/Mover.ts
+++ b/source/src/ECS/Components/Physics/Mover.ts
@@ -1,3 +1,10 @@
+/**
+ * 辅助类说明了一种处理移动的方法,它考虑了包括触发器在内的所有冲突。
+ * ITriggerListener接口用于管理对移动过程中违反的任何触发器的回调。
+ * 一个物体只能通过移动器移动。要正确报告触发器的move方法。
+ *
+ * 请注意,多个移动者相互交互将多次调用ITriggerListener。
+ */
class Mover extends Component {
private _triggerHelper: ColliderTriggerHelper;
@@ -5,6 +12,10 @@ class Mover extends Component {
this._triggerHelper = new ColliderTriggerHelper(this.entity);
}
+ /**
+ * 计算修改运动矢量的运动,以考虑移动时可能发生的碰撞
+ * @param motion
+ */
public calculateMovement(motion: Vector2){
let collisionResult = new CollisionResult();
@@ -16,9 +27,11 @@ class Mover extends Component {
for (let i = 0; i < colliders.length; i ++){
let collider = colliders[i];
+ // 不检测触发器
if (collider.isTrigger)
continue;
+ // 获取我们在新位置可能发生碰撞的任何东西
let bounds = collider.bounds;
bounds.x += motion.x;
bounds.y += motion.y;
@@ -28,13 +41,16 @@ class Mover extends Component {
for (let j = 0; j < neighbors.length; j ++){
let neighbor = neighbors[j];
+ // 不检测触发器
if (neighbor.isTrigger)
continue;
let _internalcollisionResult = collider.collidesWith(neighbor, motion);
if (_internalcollisionResult){
+ // 如果碰撞 则退回之前的移动量
motion = Vector2.subtract(motion, _internalcollisionResult.minimumTranslationVector);
+ // 如果我们碰到多个对象,为了简单起见,只取第一个。
if (_internalcollisionResult.collider){
collisionResult = _internalcollisionResult;
}
diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts
index 32170e9c..09238e97 100644
--- a/source/src/ECS/Components/SpriteRenderer.ts
+++ b/source/src/ECS/Components/SpriteRenderer.ts
@@ -1,25 +1,12 @@
class SpriteRenderer extends RenderableComponent {
- private _origin: Vector2;
private _sprite: Sprite;
protected bitmap: egret.Bitmap;
- public get origin(){
- return this._origin;
- }
- public set origin(value: Vector2){
- this.setOrigin(value);
- }
- public setOrigin(origin: Vector2){
- if (this._origin != origin){
- this._origin = origin;
- }
- return this;
- }
- /** 应该由这个精灵显示的精灵。当设置时,精灵的原点也被设置为匹配精灵.origin。 */
+ /** 应该由这个精灵显示的精灵 */
public get sprite(): Sprite{
return this._sprite;
}
- /** 应该由这个精灵显示的精灵。当设置时,精灵的原点也被设置为匹配精灵.origin。 */
+ /** 应该由这个精灵显示的精灵 */
public set sprite(value: Sprite){
this.setSprite(value);
}
@@ -27,7 +14,10 @@ class SpriteRenderer extends RenderableComponent {
public setSprite(sprite: Sprite): SpriteRenderer{
this.removeChildren();
this._sprite = sprite;
- if (this._sprite) this._origin = this._sprite.origin;
+ if (this._sprite) {
+ this.anchorOffsetX = this._sprite.origin.x / this._sprite.sourceRect.width;
+ this.anchorOffsetY = this._sprite.origin.y / this._sprite.sourceRect.height;
+ }
this.bitmap = new egret.Bitmap(sprite.texture2D);
this.addChild(this.bitmap);
@@ -58,8 +48,8 @@ class SpriteRenderer extends RenderableComponent {
/** 渲染处理 在每个模块中处理各自的渲染逻辑 */
public render(camera: Camera){
- this.x = this.entity.position.x - this.origin.x - camera.position.x + camera.origin.x;
- this.y = this.entity.position.y - this.origin.y - camera.position.y + camera.origin.y;
+ this.x = -camera.position.x + camera.origin.x;
+ this.y = -camera.position.y + camera.origin.y;
}
public onRemovedFromEntity(){
diff --git a/source/src/ECS/Entity.ts b/source/src/ECS/Entity.ts
index eb5ae729..ed56b187 100644
--- a/source/src/ECS/Entity.ts
+++ b/source/src/ECS/Entity.ts
@@ -1,7 +1,6 @@
class Entity extends egret.DisplayObjectContainer {
private static _idGenerator: number;
- private _position: Vector2 = Vector2.zero;
public name: string;
public readonly id: number;
/** 当前实体所属的场景 */
@@ -20,11 +19,13 @@ class Entity extends egret.DisplayObjectContainer {
}
public get position(){
- return this._position;
+ return new Vector2(this.x, this.y);
}
public set position(value: Vector2){
- this._position = value;
+ this.$setX(value.x);
+ this.$setY(value.y);
+ this.onEntityTransformChanged(TransformComponent.position);
}
public get scale(){
@@ -32,8 +33,14 @@ class Entity extends egret.DisplayObjectContainer {
}
public set scale(value: Vector2){
- this.scaleX = value.x;
- this.scaleY = value.y;
+ this.$setScaleX(value.x);
+ this.$setScaleY(value.y);
+ this.onEntityTransformChanged(TransformComponent.scale);
+ }
+
+ public set rotation(value: number){
+ this.$setRotation(value);
+ this.onEntityTransformChanged(TransformComponent.rotation);
}
public get enabled(){
@@ -160,6 +167,10 @@ class Entity extends egret.DisplayObjectContainer {
return this.components.getComponents(typeName, componentList);
}
+ private onEntityTransformChanged(comp: TransformComponent){
+ this.components.onEntityTransformChanged(comp);
+ }
+
public removeComponentForType(type){
let comp = this.getComponent(type);
if (comp){
@@ -203,4 +214,10 @@ class Entity extends egret.DisplayObjectContainer {
(child as Component).entity.destroy();
}
}
+}
+
+enum TransformComponent {
+ rotation,
+ scale,
+ position
}
\ No newline at end of file
diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts
index 7e4b2870..9bf9100e 100644
--- a/source/src/ECS/Scene.ts
+++ b/source/src/ECS/Scene.ts
@@ -144,6 +144,9 @@ class Scene extends egret.DisplayObjectContainer {
this.entityProcessors.end();
this.unload();
+
+ if (this.parent)
+ this.parent.removeChild(this);
}
protected async onStart() {
diff --git a/source/src/ECS/Utils/ComponentList.ts b/source/src/ECS/Utils/ComponentList.ts
index 07849ed6..bdb60bdf 100644
--- a/source/src/ECS/Utils/ComponentList.ts
+++ b/source/src/ECS/Utils/ComponentList.ts
@@ -101,6 +101,18 @@ class ComponentList {
}
}
+ public onEntityTransformChanged(comp: TransformComponent){
+ for (let i = 0; i < this._components.length; i ++){
+ if (this._components[i].enabled)
+ this._components[i].onEntityTransformChanged(comp);
+ }
+
+ for (let i = 0; i < this._componentsToAdd.length; i ++){
+ if (this._componentsToAdd[i].enabled)
+ this._componentsToAdd[i].onEntityTransformChanged(comp);
+ }
+ }
+
private handleRemove(component: Component){
if (component instanceof RenderableComponent)
this._entity.scene.renderableComponents.remove(component);
diff --git a/source/src/Math/Matrix2D.ts b/source/src/Math/Matrix2D.ts
index b2cc0cab..41794194 100644
--- a/source/src/Math/Matrix2D.ts
+++ b/source/src/Math/Matrix2D.ts
@@ -155,8 +155,13 @@ class Matrix2D {
return result;
}
- public static createTranslation(xPosition: number, yPosition: number, result?: Matrix2D){
- result = result ? result : new Matrix2D();
+ /**
+ * 创建一个新的tranlation
+ * @param xPosition
+ * @param yPosition
+ */
+ public static createTranslation(xPosition: number, yPosition: number){
+ let result = new Matrix2D();
result.m11 = 1;
result.m12 = 0;
@@ -170,6 +175,14 @@ class Matrix2D {
return result;
}
+ /**
+ * 根据position 创建一个translation
+ * @param position
+ */
+ public static createTranslationVector(position: Vector2){
+ return this.createTranslation(position.x, position.y);
+ }
+
public static createRotation(radians: number, result?: Matrix2D){
result = new Matrix2D();
diff --git a/source/src/Math/Point.ts b/source/src/Math/Point.ts
deleted file mode 100644
index 4da78bc7..00000000
--- a/source/src/Math/Point.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-class Point {
- public x: number;
- public y: number;
-
- constructor(x?: number, y?: number){
- this.x = x ? x : 0;
- this.y = y ? y : this.x;
- }
-}
\ No newline at end of file
diff --git a/source/src/Math/Rectangle.ts b/source/src/Math/Rectangle.ts
index 69e0b30a..e83be97e 100644
--- a/source/src/Math/Rectangle.ts
+++ b/source/src/Math/Rectangle.ts
@@ -1,43 +1,21 @@
-class Rectangle {
- public x: number;
- public y: number;
- public width: number;
- public height: number;
-
- private _tempMat: Matrix2D;
- private _transformMat: Matrix2D;
-
+class Rectangle extends egret.Rectangle {
/**
* 获取矩形的最大点,即右下角
*/
- public get max(){
+ public get max() {
return new Vector2(this.right, this.bottom);
}
- public get left() {
- return this.x;
- }
-
- public get right() {
- return this.x + this.width;
- }
-
- public get top() {
- return this.y;
- }
-
- public get bottom() {
- return this.y + this.height;
- }
-
+ /** 中心点坐标 */
public get center() {
return new Vector2(this.x + (this.width / 2), this.y + (this.height / 2));
}
+ /** 左上角的坐标 */
public get location() {
return new Vector2(this.x, this.y);
}
-
+ /** 左上角的坐标 */
public set location(value: Vector2) {
this.x = value.x;
this.y = value.y;
@@ -52,48 +30,66 @@ class Rectangle {
this.height = value.y;
}
- constructor(x?: number, y?: number, width?: number, height?: number) {
- this.x = x ? x : 0;
- this.y = y ? y : 0;
- this.width = width ? width : 0;
- this.height = height ? height : 0;
- }
-
- public intersects(value: Rectangle) {
+ /**
+ * 是否与另一个矩形相交
+ * @param value
+ */
+ public intersects(value: egret.Rectangle) {
return value.left < this.right &&
this.left < value.right &&
value.top < this.bottom &&
this.top < value.bottom;
}
- public contains(value: Vector2) {
+ /**
+ * 判断点是否在矩形内
+ * @param value
+ */
+ public containsInVec(value: Vector2) {
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
(this.y <= value.y)) &&
(value.y < (this.y + this.height)));
}
+ /**
+ * 获取所提供的矩形是否在此矩形的边界内
+ * @param value
+ */
public containsRect(value: Rectangle) {
return ((((this.x <= value.x) && (value.x < (this.x + this.width))) &&
(this.y <= value.y)) &&
(value.y < (this.y + this.height)));
}
- public getHalfSize(){
+ public getHalfSize() {
return new Vector2(this.width * 0.5, this.height * 0.5);
}
+ /**
+ * 创建一个矩形的最小/最大点(左上角,右下角的点)
+ * @param minX
+ * @param minY
+ * @param maxX
+ * @param maxY
+ */
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
return new Rectangle(minX, minY, maxX - minX, maxY - minY);
}
- public getClosestPointOnRectangleBorderToPoint(point: Point): { res: Vector2, edgeNormal: Vector2 } {
- let edgeNormal = new Vector2(0, 0);
+ /**
+ * 获取矩形边界上与给定点最近的点
+ * @param point
+ */
+ public getClosestPointOnRectangleBorderToPoint(point: Vector2): { res: Vector2, edgeNormal: Vector2 } {
+ let edgeNormal = Vector2.zero;
- let res = new Vector2(0, 0);
+ // 对于每个轴,如果点在盒子外面
+ let res = new Vector2();
res.x = MathHelper.clamp(point.x, this.left, this.right);
res.y = MathHelper.clamp(point.y, this.top, this.bottom);
- if (this.contains(res)) {
+ // 如果点在矩形内,我们需要推res到边界,因为它将在矩形内
+ if (this.containsInVec(res)) {
let dl = res.x - this.left;
let dr = this.right - res.x;
let dt = res.y - this.top;
@@ -114,41 +110,36 @@ class Rectangle {
edgeNormal.x = 1;
}
} else {
- if (res.x == this.left) {
- edgeNormal.x = -1;
- }
- if (res.x == this.right) {
- edgeNormal.x = 1;
- }
- if (res.y == this.top) {
- edgeNormal.y = -1;
- }
- if (res.y == this.bottom) {
- edgeNormal.y = 1;
- }
+ if (res.x == this.left) edgeNormal.x = -1;
+ if (res.x == this.right) edgeNormal.x = 1;
+ if (res.y == this.top) edgeNormal.y = -1;
+ if (res.y == this.bottom) edgeNormal.y = 1;
}
return { res: res, edgeNormal: edgeNormal };
}
- public getClosestPointOnBoundsToOrigin(){
+ /**
+ *
+ */
+ public getClosestPointOnBoundsToOrigin() {
let max = this.max;
let minDist = Math.abs(this.location.x);
let boundsPoint = new Vector2(this.location.x, 0);
- if (Math.abs(max.x) < minDist){
+ if (Math.abs(max.x) < minDist) {
minDist = Math.abs(max.x);
boundsPoint.x = max.x;
boundsPoint.y = 0;
}
-
- if (Math.abs(max.y) < minDist){
+
+ if (Math.abs(max.y) < minDist) {
minDist = Math.abs(max.y);
boundsPoint.x = 0;
boundsPoint.y = max.y;
}
- if (Math.abs(this.location.y) < minDist){
+ if (Math.abs(this.location.y) < minDist) {
minDist = Math.abs(this.location.y);
boundsPoint.x = 0;
boundsPoint.y = this.location.y;
@@ -156,52 +147,13 @@ class Rectangle {
return boundsPoint;
}
-
- public calculateBounds(parentPosition: Vector2, position: Vector2, origin: Vector2, scale: Vector2,
- rotation: number, width: number, height: number) {
- if (rotation == 0) {
- this.x = parentPosition.x + position.x - origin.x * scale.x;
- this.y = parentPosition.y + position.y - origin.y * scale.y;
- this.width = width * scale.x;
- this.height = height * scale.y;
- } else {
- let worldPosX = parentPosition.x + position.x;
- let worldPosY = parentPosition.y + position.y;
-
- this._transformMat = Matrix2D.createTranslation(-worldPosX - origin.x, -worldPosY - origin.y);
- this._tempMat = Matrix2D.createScale(scale.x, scale.y);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- this._tempMat = Matrix2D.createRotation(rotation);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
- this._tempMat = Matrix2D.createTranslation(worldPosX, worldPosY);
- this._transformMat = Matrix2D.multiply(this._transformMat, this._tempMat);
-
- let topLeft = new Vector2(worldPosX, worldPosY);
- let topRight = new Vector2(worldPosX + width, worldPosY);
- let bottomLeft = new Vector2(worldPosX, worldPosY + height);
- let bottomRight = new Vector2(worldPosX + width, worldPosY + height);
-
- topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
- topRight = Vector2Ext.transformR(topRight, this._transformMat);
- bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
- bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
-
- let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
- let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
- let minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
- let maxY = Math.max(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);
-
- this.location = new Vector2(minX, minY);
- this.width = maxX - minX;
- this.height = maxY - minY;
- }
- }
-
+
/**
* 给定多边形的点,计算边界
* @param points
*/
public static rectEncompassingPoints(points: Vector2[]) {
+ // 我们需要求出x/y的最小值/最大值
let minX = Number.POSITIVE_INFINITY;
let minY = Number.POSITIVE_INFINITY;
let maxX = Number.NEGATIVE_INFINITY;
@@ -210,19 +162,11 @@ class Rectangle {
for (let i = 0; i < points.length; i++) {
let pt = points[i];
- if (pt.x < minX) {
- minX = pt.x;
- }
- if (pt.x > maxX) {
- maxX = pt.x;
- }
+ if (pt.x < minX) minX = pt.x;
+ if (pt.x > maxX) maxX = pt.x;
- if (pt.y < minY) {
- minY = pt.y;
- }
- if (pt.y > maxY) {
- maxY = pt.y;
- }
+ if (pt.y < minY) minY = pt.y;
+ if (pt.y > maxY) maxY = pt.y;
}
return this.fromMinMax(minX, minY, maxX, maxY);
diff --git a/source/src/Physics/Physics.ts b/source/src/Physics/Physics.ts
index f3c39b79..f27a7d58 100644
--- a/source/src/Physics/Physics.ts
+++ b/source/src/Physics/Physics.ts
@@ -2,13 +2,16 @@ class Physics {
private static _spatialHash: SpatialHash;
/** 调用reset并创建一个新的SpatialHash时使用的单元格大小 */
public static spatialHashCellSize = 100;
-
+ /** 接受layerMask的所有方法的默认值 */
public static readonly allLayers: number = -1;
public static reset(){
this._spatialHash = new SpatialHash(this.spatialHashCellSize);
}
+ /**
+ * 从SpatialHash中移除所有碰撞器
+ */
public static clear(){
this._spatialHash.clear();
}
@@ -26,14 +29,26 @@ class Physics {
return this._spatialHash.aabbBroadphase(rect, collider, layerMask);
}
+ /**
+ * 将对撞机添加到物理系统中
+ * @param collider
+ */
public static addCollider(collider: Collider){
Physics._spatialHash.register(collider);
}
+ /**
+ * 从物理系统中移除对撞机
+ * @param collider
+ */
public static removeCollider(collider: Collider){
Physics._spatialHash.remove(collider);
}
+ /**
+ * 更新物理系统中对撞机的位置。这实际上只是移除然后重新添加带有新边界的碰撞器
+ * @param collider
+ */
public static updateCollider(collider: Collider){
this._spatialHash.remove(collider);
this._spatialHash.register(collider);
diff --git a/source/src/Physics/Shapes/Box.ts b/source/src/Physics/Shapes/Box.ts
index 85cbbd86..a78a96bd 100644
--- a/source/src/Physics/Shapes/Box.ts
+++ b/source/src/Physics/Shapes/Box.ts
@@ -1,4 +1,7 @@
///
+/**
+ * 多边形的特殊情况。在进行SAT碰撞检查时,我们只需要检查2个轴而不是8个轴
+ */
class Box extends Polygon {
public width: number;
public height: number;
@@ -9,7 +12,13 @@ class Box extends Polygon {
this.height = height;
}
+ /**
+ * 在一个盒子的形状中建立多边形需要的点的帮助方法
+ * @param width
+ * @param height
+ */
private static buildBox(width: number, height: number): Vector2[]{
+ // 我们在(0,0)的中心周围创建点
let halfWidth = width / 2;
let halfHeight = height / 2;
let verts = new Array(4);
@@ -21,11 +30,8 @@ class Box extends Polygon {
return verts;
}
- /**
- *
- * @param other
- */
public overlaps(other: Shape){
+ // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测
if (this.isUnrotated){
if (other instanceof Box && other.isUnrotated)
return this.bounds.intersects(other.bounds);
@@ -37,11 +43,8 @@ class Box extends Polygon {
return super.overlaps(other);
}
- /**
- *
- * @param other
- */
public collidesWithShape(other: Shape){
+ // 特殊情况,这一个高性能方式实现,其他情况则使用polygon方法检测
if (this.isUnrotated && other instanceof Box && other.isUnrotated){
return ShapeCollisions.boxToBox(this, other);
}
@@ -51,10 +54,16 @@ class Box extends Polygon {
return super.collidesWithShape(other);
}
+ /**
+ * 更新框点,重新计算中心,设置宽度/高度
+ * @param width
+ * @param height
+ */
public updateBox(width: number, height: number){
this.width = width;
this.height = height;
+ // 我们在(0,0)的中心周围创建点
let halfWidth = width / 2;
let halfHeight = height / 2;
@@ -69,7 +78,7 @@ class Box extends Polygon {
public containsPoint(point: Vector2){
if (this.isUnrotated)
- return this.bounds.contains(point);
+ return this.bounds.containsInVec(point);
return super.containsPoint(point);
}
diff --git a/source/src/Physics/Shapes/Circle.ts b/source/src/Physics/Shapes/Circle.ts
index 81593ea7..b89ba6ff 100644
--- a/source/src/Physics/Shapes/Circle.ts
+++ b/source/src/Physics/Shapes/Circle.ts
@@ -32,7 +32,7 @@ class Circle extends Shape {
public recalculateBounds(collider: Collider) {
this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotationWithTransform) {
+ if (collider.shouldColliderScaleAndRotateWithTransform) {
let scale = collider.entity.scale;
let hasUnitScale = scale.x == 1 && scale.y == 1;
let maxScale = Math.max(scale.x, scale.y);
diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts
index bd13d41f..86342362 100644
--- a/source/src/Physics/Shapes/Polygon.ts
+++ b/source/src/Physics/Shapes/Polygon.ts
@@ -103,6 +103,13 @@ class Polygon extends Shape {
return new Vector2(x / points.length, y / points.length);
}
+ /**
+ * 迭代多边形的所有边,并得到任意边上离点最近的点。
+ * 通过最近点的平方距离和它所在的边的法线返回。
+ * 点应该在多边形的空间中(点-多边形.位置)
+ * @param points
+ * @param point
+ */
public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2): { closestPoint, distanceSquared, edgeNormal } {
let distanceSquared = Number.MAX_VALUE;
let edgeNormal = new Vector2(0, 0);
@@ -121,6 +128,7 @@ class Polygon extends Shape {
distanceSquared = tempDistanceSquared;
closestPoint = closest;
+ // 求直线的法线
let line = Vector2.subtract(points[j], points[i]);
edgeNormal.x = -line.y;
edgeNormal.y = line.x;
@@ -136,7 +144,13 @@ class Polygon extends Shape {
return ShapeCollisions.pointToPoly(point, this);
}
+ /**
+ * 本质上,这个算法所做的就是从一个点发射一条射线。
+ * 如果它与奇数条多边形边相交,我们就知道它在多边形内部。
+ * @param point
+ */
public containsPoint(point: Vector2) {
+ // 将点归一化到多边形坐标空间中
point = Vector2.subtract(point, this.position);
let isInside = false;
@@ -168,9 +182,10 @@ class Polygon extends Shape {
}
public recalculateBounds(collider: Collider) {
+ // 如果我们没有旋转或不关心TRS我们使用localOffset作为中心,我们会从那开始
this.center = collider.localOffset;
- if (collider.shouldColliderScaleAndRotationWithTransform){
+ if (collider.shouldColliderScaleAndRotateWithTransform){
let hasUnitScale = true;
let tempMat: Matrix2D;
let combinedMatrix = Matrix2D.createTranslation(-this._polygonCenter.x, -this._polygonCenter.y);
@@ -180,14 +195,18 @@ class Polygon extends Shape {
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
hasUnitScale = false;
+
+ // 缩放偏移量并将其设置为中心。如果我们有旋转,它会在下面重置
let scaledOffset = Vector2.multiply(collider.localOffset, collider.entity.scale);
this.center = scaledOffset;
}
if (collider.entity.rotation != 0){
- tempMat = Matrix2D.createRotation(collider.entity.rotation);
+ tempMat = Matrix2D.createRotation(collider.entity.rotation, tempMat);
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
+ // 为了处理偏移原点的旋转我们只需要将圆心在(0,0)附近移动我们的偏移使角度为0
+ // 我们还需要处理这里的比例所以我们先对偏移进行缩放以得到合适的长度。
let offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * MathHelper.Rad2Deg;
let offsetLength = hasUnitScale ? collider._localOffsetLength : (Vector2.multiply(collider.localOffset, collider.entity.scale)).length();
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength, MathHelper.toDegrees(collider.entity.rotation) + offsetAngle);
@@ -196,11 +215,9 @@ class Polygon extends Shape {
tempMat = Matrix2D.createTranslation(this._polygonCenter.x, this._polygonCenter.y);
combinedMatrix = Matrix2D.multiply(combinedMatrix, tempMat);
+ // 最后变换原始点
Vector2Ext.transform(this._originalPoints, combinedMatrix, this.points);
this.isUnrotated = collider.entity.rotation == 0;
-
- if (collider._isRotationDirty)
- this._areEdgeNormalsDirty = true;
}
this.position = Vector2.add(collider.entity.position, this.center);
diff --git a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts
index a17e9619..a45c32e8 100644
--- a/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts
+++ b/source/src/Physics/Shapes/ShapeCollisions/ShapeCollisions.ts
@@ -15,13 +15,17 @@ class ShapeCollisions {
let polygonOffset = Vector2.subtract(first.position, second.position);
let axis: Vector2;
+ // 循环穿过两个多边形的所有边
for (let edgeIndex = 0; edgeIndex < firstEdges.length + secondEdges.length; edgeIndex++) {
+ // 1. 找出当前多边形是否相交
+ // 多边形的归一化轴垂直于缓存给我们的当前边
if (edgeIndex < firstEdges.length) {
axis = firstEdges[edgeIndex];
} else {
axis = secondEdges[edgeIndex - firstEdges.length];
}
+ // 求多边形在当前轴上的投影
let minA = 0;
let minB = 0;
let maxA = 0;
@@ -34,17 +38,24 @@ class ShapeCollisions {
minB = tb.min;
maxB = tb.max;
+ // 将区间设为第二个多边形的空间。由轴上投影的位置差偏移。
let relativeIntervalOffset = Vector2.dot(polygonOffset, axis);
minA += relativeIntervalOffset;
maxA += relativeIntervalOffset;
+ // 检查多边形投影是否正在相交
intervalDist = this.intervalDistance(minA, maxA, minB, maxB);
if (intervalDist > 0)
isIntersecting = false;
+ // 对于多对多数据类型转换,添加一个Vector2?参数称为deltaMovement。为了提高速度,我们这里不使用它
+ // TODO: 现在找出多边形是否会相交。只要检查速度就行了
+
+ // 如果多边形不相交,也不会相交,退出循环
if (!isIntersecting)
return null;
+ // 检查当前间隔距离是否为最小值。如果是,则存储间隔距离和当前距离。这将用于计算最小平移向量
intervalDist = Math.abs(intervalDist);
if (intervalDist < minIntervalDistance) {
minIntervalDistance = intervalDist;
@@ -55,8 +66,9 @@ class ShapeCollisions {
}
}
+ // 利用最小平移向量对多边形进行推入。
result.normal = translationAxis;
- result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis), new Vector2(minIntervalDistance));
+ result.minimumTranslationVector = Vector2.multiply(new Vector2(-translationAxis.x, -translationAxis.y), new Vector2(minIntervalDistance));
return result;
}
@@ -262,11 +274,12 @@ class ShapeCollisions {
let result = new CollisionResult();
let minkowskiDiff = this.minkowskiDifference(first, second);
- if (minkowskiDiff.contains(new Vector2(0, 0))){
+ if (minkowskiDiff.containsInVec(new Vector2(0, 0))){
+ // 计算MTV。如果它是零,我们就可以称它为非碰撞
result.minimumTranslationVector = minkowskiDiff.getClosestPointOnBoundsToOrigin();
- if (result.minimumTranslationVector == Vector2.zero)
- return false;
+ if (result.minimumTranslationVector.x == 0 && result.minimumTranslationVector.y == 0)
+ return null;
result.normal = new Vector2(-result.minimumTranslationVector.x, -result.minimumTranslationVector.y);
result.normal.normalize();
@@ -278,6 +291,8 @@ class ShapeCollisions {
}
private static minkowskiDifference(first: Box, second: Box){
+ // 我们需要第一个框的左上角
+ // 碰撞器只会修改运动的位置所以我们需要用位置来计算出运动是什么。
let positionOffset = Vector2.subtract(first.position, Vector2.add(first.bounds.location, Vector2.divide(first.bounds.size, new Vector2(2))));
let topLeft = Vector2.subtract(Vector2.add(first.bounds.location, positionOffset), second.bounds.max);
let fullSize = Vector2.add(first.bounds.size, second.bounds.size);
diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts
index 42663304..205da0ed 100644
--- a/source/src/Physics/Verlet/SpatialHash.ts
+++ b/source/src/Physics/Verlet/SpatialHash.ts
@@ -2,10 +2,15 @@ class SpatialHash {
public gridBounds: Rectangle = new Rectangle();
private _raycastParser: RaycastResultParser;
+ /** 散列中每个单元格的大小 */
private _cellSize: number;
+ /** 1除以单元格大小。缓存结果,因为它被大量使用。 */
private _inverseCellSize: number;
- private _overlapTestCircle: Circle;
+ /** 缓存的循环用于重叠检查 */
+ private _overlapTestCircle: Circle = new Circle(0);
+ /** 用于返回冲突信息的共享HashSet */
private _tempHashSet: Collider[] = [];
+ /** 保存所有数据的字典 */
private _cellDict: NumberDictionary = new NumberDictionary();
constructor(cellSize: number = 100) {
@@ -14,6 +19,10 @@ class SpatialHash {
this._raycastParser = new RaycastResultParser();
}
+ /**
+ * 从SpatialHash中删除对象
+ * @param collider
+ */
public remove(collider: Collider) {
let bounds = collider.registeredPhysicsBounds;
let p1 = this.cellCoords(bounds.x, bounds.y);
@@ -21,6 +30,7 @@ class SpatialHash {
for (let x = p1.x; x <= p2.x; x++) {
for (let y = p1.y; y <= p2.y; y++) {
+ // 单元格应该始终存在,因为这个碰撞器应该在所有查询的单元格中
let cell = this.cellAtPosition(x, y);
if (!cell)
console.error(`removing Collider [${collider}] from a cell that it is not present in`);
@@ -30,22 +40,28 @@ class SpatialHash {
}
}
+ /**
+ * 将对象添加到SpatialHash
+ * @param collider
+ */
public register(collider: Collider) {
let bounds = collider.bounds;
collider.registeredPhysicsBounds = bounds;
let p1 = this.cellCoords(bounds.x, bounds.y);
let p2 = this.cellCoords(bounds.right, bounds.bottom);
- if (!this.gridBounds.contains(new Vector2(p1.x, p1.y))) {
+ // 更新边界以跟踪网格大小
+ if (!this.gridBounds.containsInVec(new Vector2(p1.x, p1.y))) {
this.gridBounds = RectangleExt.union(this.gridBounds, p1);
}
- if (!this.gridBounds.contains(new Vector2(p2.x, p2.y))) {
+ if (!this.gridBounds.containsInVec(new Vector2(p2.x, p2.y))) {
this.gridBounds = RectangleExt.union(this.gridBounds, p2);
}
for (let x = p1.x; x <= p2.x; x++) {
for (let y = p1.y; y <= p2.y; y++) {
+ // 如果没有单元格,我们需要创建它
let c = this.cellAtPosition(x, y, true);
c.push(collider);
}
@@ -56,6 +72,13 @@ class SpatialHash {
this._cellDict.clear();
}
+ /**
+ * 获取位于指定圆内的所有碰撞器
+ * @param circleCenter
+ * @param radius
+ * @param results
+ * @param layerMask
+ */
public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) {
let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2);
@@ -82,6 +105,12 @@ class SpatialHash {
return resultCounter;
}
+ /**
+ * 返回边框与单元格相交的所有对象
+ * @param bounds
+ * @param excludeCollider
+ * @param layerMask
+ */
public aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number) {
this._tempHashSet.length = 0;
@@ -94,9 +123,11 @@ class SpatialHash {
if (!cell)
continue;
+ // 当cell不为空。循环并取回所有碰撞器
for (let i = 0; i < cell.length; i++) {
let collider = cell[i];
+ // 如果它是自身或者如果它不匹配我们的层掩码 跳过这个碰撞器
if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer))
continue;
@@ -111,6 +142,13 @@ class SpatialHash {
return {tempHashSet: this._tempHashSet, bounds: bounds};
}
+ /**
+ * 获取世界空间x,y值的单元格。
+ * 如果单元格为空且createCellIfEmpty为true,则会创建一个新的单元格
+ * @param x
+ * @param y
+ * @param createCellIfEmpty
+ */
private cellAtPosition(x: number, y: number, createCellIfEmpty: boolean = false) {
let cell: Collider[] = this._cellDict.tryGetValue(x, y);
if (!cell) {
@@ -122,8 +160,13 @@ class SpatialHash {
return cell;
}
- private cellCoords(x: number, y: number): Point {
- return new Point(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
+ /**
+ * 获取单元格的x,y值作为世界空间的x,y值
+ * @param x
+ * @param y
+ */
+ private cellCoords(x: number, y: number): Vector2 {
+ return new Vector2(Math.floor(x * this._inverseCellSize), Math.floor(y * this._inverseCellSize));
}
}
@@ -131,6 +174,10 @@ class RaycastResultParser {
}
+/**
+ * 包装一个Unit32,列表碰撞器字典
+ * 它的主要目的是将int、int x、y坐标散列到单个Uint32键中,使用O(1)查找。
+ */
class NumberDictionary {
private _store: Map = new Map();
@@ -154,6 +201,10 @@ class NumberDictionary {
this._store.set(this.getKey(x, y), list);
}
+ /**
+ * 使用蛮力方法从字典存储列表中移除碰撞器
+ * @param obj
+ */
public remove(obj: Collider) {
this._store.forEach(list => {
if (list.contains(obj))
@@ -165,6 +216,9 @@ class NumberDictionary {
return this._store.get(this.getKey(x, y));
}
+ /**
+ * 清除字典数据
+ */
public clear() {
this._store.clear();
}
diff --git a/source/src/Utils/RectangleExt.ts b/source/src/Utils/RectangleExt.ts
index 5c05afd9..9f681679 100644
--- a/source/src/Utils/RectangleExt.ts
+++ b/source/src/Utils/RectangleExt.ts
@@ -1,5 +1,5 @@
class RectangleExt {
- public static union(first: Rectangle, point: Point){
+ public static union(first: Rectangle, point: Vector2){
let rect = new Rectangle(point.x, point.y, 0, 0);
return this.unionR(first, rect);
}
diff --git a/source/src/Utils/Vector2Ext.ts b/source/src/Utils/Vector2Ext.ts
index 0068be0a..17789716 100644
--- a/source/src/Utils/Vector2Ext.ts
+++ b/source/src/Utils/Vector2Ext.ts
@@ -43,6 +43,15 @@ class Vector2Ext {
return vec;
}
+ /**
+ * 通过指定的矩阵对Vector2的数组中的向量应用变换,并将结果放置在另一个数组中。
+ * @param sourceArray
+ * @param sourceIndex
+ * @param matrix
+ * @param destinationArray
+ * @param destinationIndex
+ * @param length
+ */
public static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D,
destinationArray: Vector2[], destinationIndex: number, length: number) {
for (let i = 0; i < length; i ++){
@@ -60,6 +69,12 @@ class Vector2Ext {
return new Vector2(x, y);
}
+ /**
+ * 通过指定的矩阵对Vector2的数组中的所有向量应用变换,并将结果放到另一个数组中。
+ * @param sourceArray
+ * @param matrix
+ * @param destinationArray
+ */
public static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]) {
this.transformA(sourceArray, 0, matrix, destinationArray, 0, sourceArray.length);
}