diff --git a/demo/libs/framework/framework.d.ts b/demo/libs/framework/framework.d.ts index ca5a358b..5675336d 100644 --- a/demo/libs/framework/framework.d.ts +++ b/demo/libs/framework/framework.d.ts @@ -211,10 +211,12 @@ declare class Scene extends egret.DisplayObjectContainer { camera: Camera; readonly entities: EntityList; readonly renderableComponents: RenderableComponentList; + readonly content: ContentManager; private _projectionMatrix; private _transformMatrix; private _matrixTransformMatrix; private _renderers; + private _didSceneBegin; readonly entityProcessors: EntityProcessorList; constructor(displayObject: egret.DisplayObject); createEntity(name: string): Entity; @@ -224,25 +226,27 @@ declare class Scene extends egret.DisplayObjectContainer { addEntityProcessor(processor: EntitySystem): EntitySystem; removeEntityProcessor(processor: EntitySystem): void; getEntityProcessor(): T; - setActive(): Scene; addRenderer(renderer: T): T; getRenderer(type: any): T; removeRenderer(renderer: Renderer): void; - initialize(): void; - onActive(): void; - onDeactive(): void; + begin(): void; + end(): void; + protected onStart(): void; + protected onActive(): void; + protected onDeactive(): void; update(): void; render(): void; - prepRenderState(): void; - destory(): void; } declare class SceneManager { - private static _loadedScenes; - private static _lastScene; - private static _activeScene; - static createScene(name: string, scene: Scene): Scene; - static setActiveScene(scene: Scene): Scene; - static getActiveScene(): Scene; + private static _scene; + private static _nextScene; + static sceneTransition: SceneTransition; + constructor(stage: egret.Stage); + static scene: Scene; + static initialize(stage: egret.Stage): void; + static update(): void; + static render(): void; + static startSceneTransition(sceneTransition: T): T; } declare enum DirtyType { clean = 0, @@ -623,6 +627,33 @@ interface IRenderable { declare class ScreenSpaceRenderer extends Renderer { render(scene: Scene): void; } +declare abstract class SceneTransition { + loadsNewScene: boolean; + isNewSceneLoaded: boolean; + wantsPreviousSceneRender: boolean; + protected sceneLoadAction: Function; + previousSceneRender: egret.RenderTexture; + onScreenObscured: Function; + onTransitionCompleted: Function; + progress: number; + constructor(sceneLoadAction: Function, wantsPreviousSceneRender?: boolean); + private _hasPreviousSceneRender; + readonly hasPreviousSceneRender: boolean; + preRender(): void; + render(): void; + onBeginTransition(): Promise; + protected transitionComplete(): void; + protected loadScene(): Promise; +} +declare class FadeTransition extends SceneTransition { + fadeToColor: number; + fadeOutDuration: number; + private _color; + private _toColor; + private _destinationRect; + private _overlayTexture; + constructor(sceneLoadAction: Function); +} declare class Flags { static isFlagSet(self: number, flag: number): boolean; static isUnshiftedFlagSet(self: number, flag: number): boolean; @@ -759,6 +790,7 @@ declare class Physics { static spatialHashCellSize: number; static readonly allLayers: number; static reset(): void; + static clear(): void; static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[]; static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[]; @@ -787,7 +819,7 @@ declare class Polygon extends Shape { constructor(points: Vector2[], isBox?: boolean); private buildEdgeNormals; setPoints(points: Vector2[]): void; - collidesWithShape(other: Shape): CollisionResult; + collidesWithShape(other: Shape): any; recalculateCenterAndEdgeNormals(): void; overlaps(other: Shape): any; static findPolygonCenter(points: Vector2[]): Vector2; @@ -850,6 +882,7 @@ declare class SpatialHash { constructor(cellSize?: number); remove(collider: Collider): void; register(collider: Collider): void; + clear(): void; overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[]; private cellAtPosition; @@ -866,6 +899,11 @@ declare class NumberDictionary { tryGetValue(x: number, y: number): Collider[]; clear(): void; } +declare class ContentManager { + protected loadedAssets: Map; + load(name: string, local?: boolean): Promise; + dispose(): void; +} declare class Emitter { private _messageTable; constructor(); @@ -908,7 +946,7 @@ declare class Input { static readonly totalTouchCount: number; static readonly gameTouchs: TouchState[]; static readonly touchPositionDelta: Vector2; - static initialize(): void; + static initialize(stage: egret.Stage): void; private static initTouchCache; private static touchBegin; private static touchMove; diff --git a/demo/libs/framework/framework.js b/demo/libs/framework/framework.js index 6f94394f..b373e1eb 100644 --- a/demo/libs/framework/framework.js +++ b/demo/libs/framework/framework.js @@ -8,6 +8,41 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; Array.prototype.findIndex = function (predicate) { function findIndex(array, predicate) { for (var i = 0, len = array.length; i < len; i++) { @@ -1085,9 +1120,9 @@ var Scene = (function (_super) { _this.entityProcessors = new EntityProcessorList(); _this.renderableComponents = new RenderableComponentList(); _this.entities = new EntityList(_this); + _this.content = new ContentManager(); _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); - _this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this); return _this; } Scene.prototype.createEntity = function (name) { @@ -1121,10 +1156,6 @@ var Scene = (function (_super) { Scene.prototype.getEntityProcessor = function () { return this.entityProcessors.getProcessor(); }; - Scene.prototype.setActive = function () { - SceneManager.setActiveScene(this); - return this; - }; Scene.prototype.addRenderer = function (renderer) { this._renderers.push(renderer); this._renderers.sort(); @@ -1141,28 +1172,38 @@ var Scene = (function (_super) { Scene.prototype.removeRenderer = function (renderer) { this._renderers.remove(renderer); }; - Scene.prototype.initialize = function () { + Scene.prototype.begin = function () { if (this._renderers.length == 0) { this.addRenderer(new DefaultRenderer()); console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); } this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); Physics.reset(); - Input.initialize(); if (this.entityProcessors) this.entityProcessors.begin(); this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + this._didSceneBegin = true; + this.onStart(); + }; + Scene.prototype.end = function () { + this._didSceneBegin = false; + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + this.entities.removeAllEntities(); + Physics.clear(); + this.camera.destory(); + this.camera = null; + this.content.dispose(); + if (this.entityProcessors) + this.entityProcessors.end(); + }; + Scene.prototype.onStart = function () { }; Scene.prototype.onActive = function () { }; Scene.prototype.onDeactive = function () { }; Scene.prototype.update = function () { - Time.update(egret.getTimer()); - for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } this.entities.updateLists(); if (this.entityProcessors) this.entityProcessors.update(); @@ -1170,7 +1211,6 @@ var Scene = (function (_super) { if (this.entityProcessors) this.entityProcessors.lateUpdate(); this.renderableComponents.updateList(); - this.render(); }; Scene.prototype.render = function () { for (var i = 0; i < this._renderers.length; i++) { @@ -1180,44 +1220,82 @@ var Scene = (function (_super) { this._renderers[i].render(this); } }; - Scene.prototype.prepRenderState = function () { - this._projectionMatrix.m11 = 2 / this.stage.stageWidth; - this._projectionMatrix.m22 = -2 / this.stage.stageHeight; - this._transformMatrix = this.camera.transformMatrix; - this._matrixTransformMatrix = Matrix2D.multiply(this._transformMatrix, this._projectionMatrix); - }; - Scene.prototype.destory = function () { - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - this.camera.destory(); - this.camera = null; - this.entities.removeAllEntities(); - }; return Scene; }(egret.DisplayObjectContainer)); var SceneManager = (function () { - function SceneManager() { + function SceneManager(stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + SceneManager.initialize(stage); } - SceneManager.createScene = function (name, scene) { - scene.name = name; - this._loadedScenes.set(name, scene); - return scene; + Object.defineProperty(SceneManager, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + if (!value) + throw new Error("场景不能为空"); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + } + else { + this._nextScene = value; + } + }, + enumerable: true, + configurable: true + }); + SceneManager.initialize = function (stage) { + Input.initialize(stage); }; - SceneManager.setActiveScene = function (scene) { - if (this._activeScene) { - if (this._activeScene == scene) - return; - this._lastScene = this._activeScene; - this._activeScene.destory(); + SceneManager.update = function () { + Time.update(egret.getTimer()); + if (SceneManager._scene) { + for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (GlobalManager.globalManagers[i].enabled) + GlobalManager.globalManagers[i].update(); + } + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + if (SceneManager._nextScene) { + SceneManager._scene.end(); + for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { + var entity = SceneManager._scene.entities.buffer[i]; + entity.destory(); + } + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._scene.begin(); + } } - this._activeScene = scene; - this._activeScene.initialize(); - return scene; + SceneManager.render(); }; - SceneManager.getActiveScene = function () { - return this._activeScene; + SceneManager.render = function () { + if (this.sceneTransition) + this.sceneTransition.preRender(); + if (this.sceneTransition) { + if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this.sceneTransition.onBeginTransition(); + } + else if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + } + this.sceneTransition.render(); + } + else if (this.scene) { + this.scene.render(); + } + }; + SceneManager.startSceneTransition = function (sceneTransition) { + if (!this.sceneTransition) { + throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。"); + } + this.sceneTransition = sceneTransition; + return sceneTransition; }; - SceneManager._loadedScenes = new Map(); return SceneManager; }()); var DirtyType; @@ -2051,11 +2129,11 @@ var SpriteRenderer = (function (_super) { return; this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x; this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y; - this._bitmap.rotation = this.entity.transform.rotation; + this._bitmap.rotation = this.entity.transform.rotation + camera.transform.rotation; this._bitmap.anchorOffsetX = this._origin.x; this._bitmap.anchorOffsetY = this._origin.y; - this._bitmap.scaleX = this.entity.transform.scale.x; - this._bitmap.scaleY = this.entity.transform.scale.y; + this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x; + this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y; }; return SpriteRenderer; }(RenderableComponent)); @@ -2899,7 +2977,7 @@ var Renderer = (function () { Renderer.prototype.onAddedToScene = function (scene) { }; Renderer.prototype.beginRender = function (cam) { cam.transform.updateTransform(); - var entities = SceneManager.getActiveScene().entities; + var entities = SceneManager.scene.entities; for (var i = 0; i < entities.buffer.length; i++) { entities.buffer[i].transform.updateTransform(); } @@ -2934,6 +3012,85 @@ var ScreenSpaceRenderer = (function (_super) { }; return ScreenSpaceRenderer; }(Renderer)); +var SceneTransition = (function () { + function SceneTransition(sceneLoadAction, wantsPreviousSceneRender) { + if (wantsPreviousSceneRender === void 0) { wantsPreviousSceneRender = true; } + this.progress = 0; + this.sceneLoadAction = sceneLoadAction; + this.wantsPreviousSceneRender = wantsPreviousSceneRender; + this.loadsNewScene = sceneLoadAction != null; + if (wantsPreviousSceneRender) + this.previousSceneRender = new egret.RenderTexture(); + } + Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { + get: function () { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; + } + return true; + }, + enumerable: true, + configurable: true + }); + SceneTransition.prototype.preRender = function () { }; + SceneTransition.prototype.render = function () { + }; + SceneTransition.prototype.onBeginTransition = function () { + var _this = this; + return new Promise(function (resolve) { + resolve(_this.loadScene()); + _this.transitionComplete(); + }); + }; + SceneTransition.prototype.transitionComplete = function () { + SceneManager.sceneTransition = null; + if (this.previousSceneRender) { + this.previousSceneRender.dispose(); + this.previousSceneRender = null; + } + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + }; + SceneTransition.prototype.loadScene = function () { + var _this = this; + return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (this.onScreenObscured) + this.onScreenObscured(); + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + resolve(); + } + _a = SceneManager; + return [4, this.sceneLoadAction()]; + case 1: + _a.scene = _b.sent(); + this.isNewSceneLoaded = true; + return [2]; + } + }); + }); }); + }; + return SceneTransition; +}()); +var FadeTransition = (function (_super) { + __extends(FadeTransition, _super); + function FadeTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction, true) || this; + _this.fadeToColor = 0x000000; + _this.fadeOutDuration = 0.4; + _this._color = 0xFFFFFF; + _this._toColor = 0xFFFFFF; + _this._destinationRect = new Rectangle(0, 0, _this.previousSceneRender.textureWidth, _this.previousSceneRender.textureHeight); + return _this; + } + return FadeTransition; +}(SceneTransition)); var Flags = (function () { function Flags() { } @@ -3662,6 +3819,9 @@ var Physics = (function () { Physics.reset = function () { this._spatialHash = new SpatialHash(this.spatialHashCellSize); }; + Physics.clear = function () { + this._spatialHash.clear(); + }; Physics.overlapCircleAll = function (center, randius, results, layerMask) { if (layerMask === void 0) { layerMask = -1; } return this._spatialHash.overlapCircle(center, randius, results, layerMask); @@ -3739,8 +3899,7 @@ var Polygon = (function (_super) { Polygon.prototype.collidesWithShape = function (other) { var result = new CollisionResult(); if (other instanceof Polygon) { - result = ShapeCollisions.polygonToPolygon(this, other); - return result; + return ShapeCollisions.polygonToPolygon(this, other); } if (other instanceof Circle) { result = ShapeCollisions.circleToPolygon(other, this); @@ -4163,6 +4322,9 @@ var SpatialHash = (function () { } } }; + SpatialHash.prototype.clear = function () { + this._cellDict.clear(); + }; SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; @@ -4256,6 +4418,48 @@ var NumberDictionary = (function () { }; return NumberDictionary; }()); +var ContentManager = (function () { + function ContentManager() { + this.loadedAssets = new Map(); + } + ContentManager.prototype.load = function (name, local) { + var _this = this; + if (local === void 0) { local = true; } + return new Promise(function (resolve, reject) { + var res = _this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + if (local) { + RES.getResAsync(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + else { + RES.getResByUrl(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + }; + ContentManager.prototype.dispose = function () { + this.loadedAssets.forEach(function (value) { + var assetsToRemove = value; + assetsToRemove.dispose(); + }); + this.loadedAssets.clear(); + }; + return ContentManager; +}()); var Emitter = (function () { function Emitter() { this._messageTable = new Map(); @@ -4354,6 +4558,8 @@ var Input = (function () { } Object.defineProperty(Input, "touchPosition", { get: function () { + if (!this._gameTouchs[0]) + return Vector2.zero; return this._gameTouchs[0].position; }, enumerable: true, @@ -4402,11 +4608,11 @@ var Input = (function () { enumerable: true, configurable: true }); - Input.initialize = function () { + Input.initialize = function (stage) { if (this._init) return; this._init = true; - this._stage = SceneManager.getActiveScene().stage; + this._stage = stage; 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); diff --git a/demo/libs/framework/framework.min.js b/demo/libs/framework/framework.min.js index 61aa958d..1e7ef145 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 i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var i=0,n=t.length;i-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(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(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,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,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}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,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.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,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(t.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),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){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.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},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return i._renderers=[],e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.renderableComponents=new RenderableComponentList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;e=0;t--)GlobalManager.globalManagers[t].enabled&&GlobalManager.globalManagers[t].update();this.entities.updateLists(),this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList(),this.render()},e.prototype.render=function(){for(var t=0;tt&&(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),this._areMatrixesDirty=!0,this},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),0!=this.entity.transform.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,i){void 0===i&&(i=CameraStyle.lockOn);var n=t.call(this)||this;return n.followLerp=.1,n.deadzone=new Rectangle,n.focusOffset=new Vector2,n.mapSize=new Vector2,n._worldSpaceDeadZone=new Rectangle,n._desiredPositionDelta=new Vector2,n._targetEntity=e,n._cameraStyle=i,n.camera=null,n}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var i=this.camera.bounds;switch(this._cameraStyle){case CameraStyle.cameraWindow:var n=i.width/6,o=i.height/3;this.deadzone=new Rectangle((i.width-n)/2,(i.height-o)/2,n,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(i.width/2,i.height/2,10,10)}},e.prototype.update=function(){var t=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.transform.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.transform.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.transform.position.x,e=this._targetEntity.transform.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 i=this._targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(i)||(this._worldSpaceDeadZone.left>i.left?this._desiredPositionDelta.x=i.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.righti.top&&(this._desiredPositionDelta.y=i.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}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,i=1<>6;this.ensure(i),this._bits[i]|=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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){t.transform.updateTransform();for(var e=SceneManager.getActiveScene().entities,i=0;ii?i:t},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,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=i||0,this.m22=n||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),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,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,i){var n=new t,o=e.m11*i.m11+e.m12*i.m21,r=e.m11*i.m12+e.m12*i.m22,s=e.m21*i.m11+e.m22*i.m21,a=e.m21*i.m12+e.m22*i.m22,h=e.m31*i.m11+e.m32*i.m21+i.m31,c=e.m31*i.m12+e.m32*i.m22+i.m32;return n.m11=o,n.m12=r,n.m21=s,n.m22=a,n.m31=h,n.m32=c,n},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=new t);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return(n=n||new t).m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=new t;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=new t),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return 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.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,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,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,n},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,n},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 i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.clamp=function(e,i,n){return new t(MathHelper.clamp(e.x,i.x,n.x),MathHelper.clamp(e.y,i.y,n.y))},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},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}(),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 c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},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,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}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 i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},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}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](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(){this._init||(this._init=!0,this._stage=SceneManager.getActiveScene().stage,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 i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){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],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||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,i,n,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"===h())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"===h())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(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(t.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),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){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.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},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return n._renderers=[],e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.renderableComponents=new RenderableComponentList,n.entities=new EntityList(n),n.content=new ContentManager,n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;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),this._areMatrixesDirty=!0,this},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),0!=this.entity.transform.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,n){void 0===n&&(n=CameraStyle.lockOn);var i=t.call(this)||this;return i.followLerp=.1,i.deadzone=new Rectangle,i.focusOffset=new Vector2,i.mapSize=new Vector2,i._worldSpaceDeadZone=new Rectangle,i._desiredPositionDelta=new Vector2,i._targetEntity=e,i._cameraStyle=n,i.camera=null,i}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var n=this.camera.bounds;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=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.transform.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.transform.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),n=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,n)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.transform.position.x,e=this._targetEntity.transform.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 PointSectors,Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){t.transform.updateTransform();for(var e=SceneManager.scene.entities,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.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,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=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=h,i.m32=c,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._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,"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}(),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 c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>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 h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*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){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},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;(y=Math.abs(y))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,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)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 c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/c))}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.load=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]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){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 static manager: SceneManager; protected createChildren(): void { super.createChildren(); @@ -52,6 +53,7 @@ class Main extends eui.UILayer { egret.registerImplementation("eui.IAssetAdapter", assetAdapter); egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter()); + Main.manager = new SceneManager(this.stage); Main.emitter = new Emitter(); this.addEventListener(egret.Event.ENTER_FRAME, this.updateFrame, this); this.runGame(); @@ -97,23 +99,7 @@ class Main extends eui.UILayer { * Create scene interface */ protected createGameScene(): void { - let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); - let scene = SceneManager.createScene("main", new MainScene(this)).setActive(); - let player = scene.createEntity("player"); - player.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xFF0000); - player.addComponent(new SpawnComponent(EnemyType.worm)); - player.addComponent(new Mover()); - player.addComponent(new PlayerController()); - player.addComponent(new FollowCamera(player)); - player.addComponent(new BoxCollider()); - - for (let i = 0; i < 20; i ++){ - let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); - let player2 = scene.createEntity("player2"); - player2.addComponent(new SpriteRenderer()).setSprite(sprite); - player2.transform.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i); - player2.addComponent(new BoxCollider()); - } + SceneManager.scene = new MainScene(this); // Main.emitter.addObserver(CoreEmitterType.Update, ()=>{ // console.log("update emitter"); diff --git a/demo/src/game/MainScene.ts b/demo/src/game/MainScene.ts index 285e2157..0d17273f 100644 --- a/demo/src/game/MainScene.ts +++ b/demo/src/game/MainScene.ts @@ -8,6 +8,33 @@ class MainScene extends Scene { this.breadthfirstTest(); } + public onStart(){ + this.content.load("http://www.hyuan.org/123.jpeg", false).then((data)=>{ + console.log(data); + }); + + this.camera.setZoom(0.5); + + let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); + let player = this.createEntity("player"); + player.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xFF0000); + player.addComponent(new SpawnComponent(EnemyType.worm)); + player.addComponent(new Mover()); + player.addComponent(new PlayerController()); + player.addComponent(new FollowCamera(player)); + player.addComponent(new BoxCollider()); + + + + for (let i = 0; i < 20; i ++){ + let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png")); + let player2 = this.createEntity("player2"); + player2.addComponent(new SpriteRenderer()).setSprite(sprite); + player2.transform.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i); + player2.addComponent(new BoxCollider()); + } + } + public breadthfirstTest(){ let graph = new UnweightedGraph(); diff --git a/demo/src/game/PlayerController.ts b/demo/src/game/PlayerController.ts index ac27c9eb..237cef14 100644 --- a/demo/src/game/PlayerController.ts +++ b/demo/src/game/PlayerController.ts @@ -27,7 +27,7 @@ class PlayerController extends Component { return; if (this.down){ - let camera = SceneManager.getActiveScene().camera; + let camera = SceneManager.scene.camera; let worldVec = camera.screenToWorldPoint(this.touchPoint); this.mover.move(Input.touchPositionDelta); console.log(Input.touchPositionDelta); diff --git a/source/bin/framework.d.ts b/source/bin/framework.d.ts index ca5a358b..5675336d 100644 --- a/source/bin/framework.d.ts +++ b/source/bin/framework.d.ts @@ -211,10 +211,12 @@ declare class Scene extends egret.DisplayObjectContainer { camera: Camera; readonly entities: EntityList; readonly renderableComponents: RenderableComponentList; + readonly content: ContentManager; private _projectionMatrix; private _transformMatrix; private _matrixTransformMatrix; private _renderers; + private _didSceneBegin; readonly entityProcessors: EntityProcessorList; constructor(displayObject: egret.DisplayObject); createEntity(name: string): Entity; @@ -224,25 +226,27 @@ declare class Scene extends egret.DisplayObjectContainer { addEntityProcessor(processor: EntitySystem): EntitySystem; removeEntityProcessor(processor: EntitySystem): void; getEntityProcessor(): T; - setActive(): Scene; addRenderer(renderer: T): T; getRenderer(type: any): T; removeRenderer(renderer: Renderer): void; - initialize(): void; - onActive(): void; - onDeactive(): void; + begin(): void; + end(): void; + protected onStart(): void; + protected onActive(): void; + protected onDeactive(): void; update(): void; render(): void; - prepRenderState(): void; - destory(): void; } declare class SceneManager { - private static _loadedScenes; - private static _lastScene; - private static _activeScene; - static createScene(name: string, scene: Scene): Scene; - static setActiveScene(scene: Scene): Scene; - static getActiveScene(): Scene; + private static _scene; + private static _nextScene; + static sceneTransition: SceneTransition; + constructor(stage: egret.Stage); + static scene: Scene; + static initialize(stage: egret.Stage): void; + static update(): void; + static render(): void; + static startSceneTransition(sceneTransition: T): T; } declare enum DirtyType { clean = 0, @@ -623,6 +627,33 @@ interface IRenderable { declare class ScreenSpaceRenderer extends Renderer { render(scene: Scene): void; } +declare abstract class SceneTransition { + loadsNewScene: boolean; + isNewSceneLoaded: boolean; + wantsPreviousSceneRender: boolean; + protected sceneLoadAction: Function; + previousSceneRender: egret.RenderTexture; + onScreenObscured: Function; + onTransitionCompleted: Function; + progress: number; + constructor(sceneLoadAction: Function, wantsPreviousSceneRender?: boolean); + private _hasPreviousSceneRender; + readonly hasPreviousSceneRender: boolean; + preRender(): void; + render(): void; + onBeginTransition(): Promise; + protected transitionComplete(): void; + protected loadScene(): Promise; +} +declare class FadeTransition extends SceneTransition { + fadeToColor: number; + fadeOutDuration: number; + private _color; + private _toColor; + private _destinationRect; + private _overlayTexture; + constructor(sceneLoadAction: Function); +} declare class Flags { static isFlagSet(self: number, flag: number): boolean; static isUnshiftedFlagSet(self: number, flag: number): boolean; @@ -759,6 +790,7 @@ declare class Physics { static spatialHashCellSize: number; static readonly allLayers: number; static reset(): void; + static clear(): void; static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask?: number): number; static boxcastBroadphase(rect: Rectangle, layerMask?: number): Collider[]; static boxcastBroadphaseExcludingSelf(collider: Collider, rect: Rectangle, layerMask?: number): Collider[]; @@ -787,7 +819,7 @@ declare class Polygon extends Shape { constructor(points: Vector2[], isBox?: boolean); private buildEdgeNormals; setPoints(points: Vector2[]): void; - collidesWithShape(other: Shape): CollisionResult; + collidesWithShape(other: Shape): any; recalculateCenterAndEdgeNormals(): void; overlaps(other: Shape): any; static findPolygonCenter(points: Vector2[]): Vector2; @@ -850,6 +882,7 @@ declare class SpatialHash { constructor(cellSize?: number); remove(collider: Collider): void; register(collider: Collider): void; + clear(): void; overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask: any): number; aabbBroadphase(bounds: Rectangle, excludeCollider: Collider, layerMask: number): Collider[]; private cellAtPosition; @@ -866,6 +899,11 @@ declare class NumberDictionary { tryGetValue(x: number, y: number): Collider[]; clear(): void; } +declare class ContentManager { + protected loadedAssets: Map; + load(name: string, local?: boolean): Promise; + dispose(): void; +} declare class Emitter { private _messageTable; constructor(); @@ -908,7 +946,7 @@ declare class Input { static readonly totalTouchCount: number; static readonly gameTouchs: TouchState[]; static readonly touchPositionDelta: Vector2; - static initialize(): void; + static initialize(stage: egret.Stage): void; private static initTouchCache; private static touchBegin; private static touchMove; diff --git a/source/bin/framework.js b/source/bin/framework.js index 6f94394f..b373e1eb 100644 --- a/source/bin/framework.js +++ b/source/bin/framework.js @@ -8,6 +8,41 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; Array.prototype.findIndex = function (predicate) { function findIndex(array, predicate) { for (var i = 0, len = array.length; i < len; i++) { @@ -1085,9 +1120,9 @@ var Scene = (function (_super) { _this.entityProcessors = new EntityProcessorList(); _this.renderableComponents = new RenderableComponentList(); _this.entities = new EntityList(_this); + _this.content = new ContentManager(); _this.addEventListener(egret.Event.ACTIVATE, _this.onActive, _this); _this.addEventListener(egret.Event.DEACTIVATE, _this.onDeactive, _this); - _this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this); return _this; } Scene.prototype.createEntity = function (name) { @@ -1121,10 +1156,6 @@ var Scene = (function (_super) { Scene.prototype.getEntityProcessor = function () { return this.entityProcessors.getProcessor(); }; - Scene.prototype.setActive = function () { - SceneManager.setActiveScene(this); - return this; - }; Scene.prototype.addRenderer = function (renderer) { this._renderers.push(renderer); this._renderers.sort(); @@ -1141,28 +1172,38 @@ var Scene = (function (_super) { Scene.prototype.removeRenderer = function (renderer) { this._renderers.remove(renderer); }; - Scene.prototype.initialize = function () { + Scene.prototype.begin = function () { if (this._renderers.length == 0) { this.addRenderer(new DefaultRenderer()); console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); } this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); Physics.reset(); - Input.initialize(); if (this.entityProcessors) this.entityProcessors.begin(); this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + this._didSceneBegin = true; + this.onStart(); + }; + Scene.prototype.end = function () { + this._didSceneBegin = false; + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + this.entities.removeAllEntities(); + Physics.clear(); + this.camera.destory(); + this.camera = null; + this.content.dispose(); + if (this.entityProcessors) + this.entityProcessors.end(); + }; + Scene.prototype.onStart = function () { }; Scene.prototype.onActive = function () { }; Scene.prototype.onDeactive = function () { }; Scene.prototype.update = function () { - Time.update(egret.getTimer()); - for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } this.entities.updateLists(); if (this.entityProcessors) this.entityProcessors.update(); @@ -1170,7 +1211,6 @@ var Scene = (function (_super) { if (this.entityProcessors) this.entityProcessors.lateUpdate(); this.renderableComponents.updateList(); - this.render(); }; Scene.prototype.render = function () { for (var i = 0; i < this._renderers.length; i++) { @@ -1180,44 +1220,82 @@ var Scene = (function (_super) { this._renderers[i].render(this); } }; - Scene.prototype.prepRenderState = function () { - this._projectionMatrix.m11 = 2 / this.stage.stageWidth; - this._projectionMatrix.m22 = -2 / this.stage.stageHeight; - this._transformMatrix = this.camera.transformMatrix; - this._matrixTransformMatrix = Matrix2D.multiply(this._transformMatrix, this._projectionMatrix); - }; - Scene.prototype.destory = function () { - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - this.camera.destory(); - this.camera = null; - this.entities.removeAllEntities(); - }; return Scene; }(egret.DisplayObjectContainer)); var SceneManager = (function () { - function SceneManager() { + function SceneManager(stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + SceneManager.initialize(stage); } - SceneManager.createScene = function (name, scene) { - scene.name = name; - this._loadedScenes.set(name, scene); - return scene; + Object.defineProperty(SceneManager, "scene", { + get: function () { + return this._scene; + }, + set: function (value) { + if (!value) + throw new Error("场景不能为空"); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + } + else { + this._nextScene = value; + } + }, + enumerable: true, + configurable: true + }); + SceneManager.initialize = function (stage) { + Input.initialize(stage); }; - SceneManager.setActiveScene = function (scene) { - if (this._activeScene) { - if (this._activeScene == scene) - return; - this._lastScene = this._activeScene; - this._activeScene.destory(); + SceneManager.update = function () { + Time.update(egret.getTimer()); + if (SceneManager._scene) { + for (var i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (GlobalManager.globalManagers[i].enabled) + GlobalManager.globalManagers[i].update(); + } + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + if (SceneManager._nextScene) { + SceneManager._scene.end(); + for (var i = 0; i < SceneManager._scene.entities.buffer.length; i++) { + var entity = SceneManager._scene.entities.buffer[i]; + entity.destory(); + } + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + SceneManager._scene.begin(); + } } - this._activeScene = scene; - this._activeScene.initialize(); - return scene; + SceneManager.render(); }; - SceneManager.getActiveScene = function () { - return this._activeScene; + SceneManager.render = function () { + if (this.sceneTransition) + this.sceneTransition.preRender(); + if (this.sceneTransition) { + if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this.sceneTransition.onBeginTransition(); + } + else if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + } + this.sceneTransition.render(); + } + else if (this.scene) { + this.scene.render(); + } + }; + SceneManager.startSceneTransition = function (sceneTransition) { + if (!this.sceneTransition) { + throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。"); + } + this.sceneTransition = sceneTransition; + return sceneTransition; }; - SceneManager._loadedScenes = new Map(); return SceneManager; }()); var DirtyType; @@ -2051,11 +2129,11 @@ var SpriteRenderer = (function (_super) { return; this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x; this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y; - this._bitmap.rotation = this.entity.transform.rotation; + this._bitmap.rotation = this.entity.transform.rotation + camera.transform.rotation; this._bitmap.anchorOffsetX = this._origin.x; this._bitmap.anchorOffsetY = this._origin.y; - this._bitmap.scaleX = this.entity.transform.scale.x; - this._bitmap.scaleY = this.entity.transform.scale.y; + this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x; + this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y; }; return SpriteRenderer; }(RenderableComponent)); @@ -2899,7 +2977,7 @@ var Renderer = (function () { Renderer.prototype.onAddedToScene = function (scene) { }; Renderer.prototype.beginRender = function (cam) { cam.transform.updateTransform(); - var entities = SceneManager.getActiveScene().entities; + var entities = SceneManager.scene.entities; for (var i = 0; i < entities.buffer.length; i++) { entities.buffer[i].transform.updateTransform(); } @@ -2934,6 +3012,85 @@ var ScreenSpaceRenderer = (function (_super) { }; return ScreenSpaceRenderer; }(Renderer)); +var SceneTransition = (function () { + function SceneTransition(sceneLoadAction, wantsPreviousSceneRender) { + if (wantsPreviousSceneRender === void 0) { wantsPreviousSceneRender = true; } + this.progress = 0; + this.sceneLoadAction = sceneLoadAction; + this.wantsPreviousSceneRender = wantsPreviousSceneRender; + this.loadsNewScene = sceneLoadAction != null; + if (wantsPreviousSceneRender) + this.previousSceneRender = new egret.RenderTexture(); + } + Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", { + get: function () { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; + } + return true; + }, + enumerable: true, + configurable: true + }); + SceneTransition.prototype.preRender = function () { }; + SceneTransition.prototype.render = function () { + }; + SceneTransition.prototype.onBeginTransition = function () { + var _this = this; + return new Promise(function (resolve) { + resolve(_this.loadScene()); + _this.transitionComplete(); + }); + }; + SceneTransition.prototype.transitionComplete = function () { + SceneManager.sceneTransition = null; + if (this.previousSceneRender) { + this.previousSceneRender.dispose(); + this.previousSceneRender = null; + } + if (this.onTransitionCompleted) { + this.onTransitionCompleted(); + } + }; + SceneTransition.prototype.loadScene = function () { + var _this = this; + return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + if (this.onScreenObscured) + this.onScreenObscured(); + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + resolve(); + } + _a = SceneManager; + return [4, this.sceneLoadAction()]; + case 1: + _a.scene = _b.sent(); + this.isNewSceneLoaded = true; + return [2]; + } + }); + }); }); + }; + return SceneTransition; +}()); +var FadeTransition = (function (_super) { + __extends(FadeTransition, _super); + function FadeTransition(sceneLoadAction) { + var _this = _super.call(this, sceneLoadAction, true) || this; + _this.fadeToColor = 0x000000; + _this.fadeOutDuration = 0.4; + _this._color = 0xFFFFFF; + _this._toColor = 0xFFFFFF; + _this._destinationRect = new Rectangle(0, 0, _this.previousSceneRender.textureWidth, _this.previousSceneRender.textureHeight); + return _this; + } + return FadeTransition; +}(SceneTransition)); var Flags = (function () { function Flags() { } @@ -3662,6 +3819,9 @@ var Physics = (function () { Physics.reset = function () { this._spatialHash = new SpatialHash(this.spatialHashCellSize); }; + Physics.clear = function () { + this._spatialHash.clear(); + }; Physics.overlapCircleAll = function (center, randius, results, layerMask) { if (layerMask === void 0) { layerMask = -1; } return this._spatialHash.overlapCircle(center, randius, results, layerMask); @@ -3739,8 +3899,7 @@ var Polygon = (function (_super) { Polygon.prototype.collidesWithShape = function (other) { var result = new CollisionResult(); if (other instanceof Polygon) { - result = ShapeCollisions.polygonToPolygon(this, other); - return result; + return ShapeCollisions.polygonToPolygon(this, other); } if (other instanceof Circle) { result = ShapeCollisions.circleToPolygon(other, this); @@ -4163,6 +4322,9 @@ var SpatialHash = (function () { } } }; + SpatialHash.prototype.clear = function () { + this._cellDict.clear(); + }; SpatialHash.prototype.overlapCircle = function (circleCenter, radius, results, layerMask) { var bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); this._overlapTestCircle.radius = radius; @@ -4256,6 +4418,48 @@ var NumberDictionary = (function () { }; return NumberDictionary; }()); +var ContentManager = (function () { + function ContentManager() { + this.loadedAssets = new Map(); + } + ContentManager.prototype.load = function (name, local) { + var _this = this; + if (local === void 0) { local = true; } + return new Promise(function (resolve, reject) { + var res = _this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + if (local) { + RES.getResAsync(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + else { + RES.getResByUrl(name).then(function (data) { + _this.loadedAssets.set(name, data); + resolve(data); + }).catch(function (err) { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }); + }; + ContentManager.prototype.dispose = function () { + this.loadedAssets.forEach(function (value) { + var assetsToRemove = value; + assetsToRemove.dispose(); + }); + this.loadedAssets.clear(); + }; + return ContentManager; +}()); var Emitter = (function () { function Emitter() { this._messageTable = new Map(); @@ -4354,6 +4558,8 @@ var Input = (function () { } Object.defineProperty(Input, "touchPosition", { get: function () { + if (!this._gameTouchs[0]) + return Vector2.zero; return this._gameTouchs[0].position; }, enumerable: true, @@ -4402,11 +4608,11 @@ var Input = (function () { enumerable: true, configurable: true }); - Input.initialize = function () { + Input.initialize = function (stage) { if (this._init) return; this._init = true; - this._stage = SceneManager.getActiveScene().stage; + this._stage = stage; 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); diff --git a/source/bin/framework.min.js b/source/bin/framework.min.js index 61aa958d..1e7ef145 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 i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}}(),Array.prototype.findIndex=function(t){return function(t,e){for(var i=0,n=t.length;i-1}(this,t)},Array.prototype.firstOrDefault=function(t){return function(t,e){var i=t.findIndex(e);return-1==i?null:t[i]}(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(i,n,o){return e.call(arguments[2],n,o,t)&&i.push(n),i},[]);for(var i=[],n=0,o=t.length;n=0&&t.splice(i,1)}while(i>=0)}(this,t)},Array.prototype.remove=function(t){return function(t,e){var i=t.findIndex(function(t){return t===e});return i>=0&&(t.splice(i,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,i){t.splice(e,i)}(this,t,e)},Array.prototype.select=function(t){return function(t,e){if("function"==typeof t.reduce)return t.reduce(function(i,n,o){return i.push(e.call(arguments[2],n,o,t)),i},[]);for(var i=[],n=0,o=t.length;nr?1:-1}),t}(this,t,e)},Array.prototype.orderByDescending=function(t,e){return function(t,e,i){return t.sort(function(t,n){var o=e(t),r=e(n);return i?-i(o,r):o0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),AStarNode=function(t){function e(e){var i=t.call(this)||this;return i.data=e,i}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,i)?this.cascadeUp(t):this.cascadeDown(t)},t.prototype.cascadeDown=function(t){for(var e,i=t.queueIndex;;){e=t;var n=2*i;if(n>this._numNodes){t.queueIndex=i,this._nodes[i]=t;break}var o=this._nodes[n];this.hasHigherPriority(o,e)&&(e=o);var r=n+1;if(r<=this._numNodes){var s=this._nodes[r];this.hasHigherPriority(s,e)&&(e=s)}if(e==t){t.queueIndex=i,this._nodes[i]=t;break}this._nodes[i]=e;var a=e.queueIndex;e.queueIndex=i,i=a}},t.prototype.cascadeUp=function(t){for(var e=Math.floor(t.queueIndex/2);e>=1;){var i=this._nodes[e];if(this.hasHigherPriority(i,t))break;this.swap(t,i),e=Math.floor(t.queueIndex/2)}},t.prototype.swap=function(t,e){this._nodes[t.queueIndex]=e,this._nodes[e.queueIndex]=t;var i=t.queueIndex;t.queueIndex=e.queueIndex,e.queueIndex=i},t.prototype.hasHigherPriority=function(t,e){return t.priority0;){if("break"===a())break}return o?AStarPathfinder.recontructPath(s,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.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,i,n){void 0===n&&(n=!1),this.walls=[],this._neighbors=new Array(4),this._width=e,this._hegiht=i,this._dirs=n?t.COMPASS_DIRS:t.CARDINAL_DIRS}return t.prototype.isNodeInBounds=function(t){return 0<=t.x&&t.x0;){if("break"===h())break}return o?this.recontructPath(r,e,i):null},t.hasKey=function(t,e){for(var i,n=t.keys();!(i=n.next()).done;)if(JSON.stringify(i.value)==JSON.stringify(e))return!0;return!1},t.getKey=function(t,e){for(var i,n,o=t.keys(),r=t.values();i=o.next(),n=r.next(),!i.done;)if(JSON.stringify(i.value)==JSON.stringify(e))return n.value;return null},t.recontructPath=function(t,e,i){var n=[],o=i;for(n.push(i);o!=e;)o=this.getKey(t,o),n.push(o);return n.reverse(),n},t}(),DebugDefaults=function(){function t(){}return t.verletParticle=14431326,t.verletConstraintEdge=4406838,t}(),Component=function(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(t.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),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){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.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},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var i=t.call(this)||this;return i._renderers=[],e.stage.addChild(i),i._projectionMatrix=new Matrix2D(0,0,0,0,0,0),i.entityProcessors=new EntityProcessorList,i.renderableComponents=new RenderableComponentList,i.entities=new EntityList(i),i.addEventListener(egret.Event.ACTIVATE,i.onActive,i),i.addEventListener(egret.Event.DEACTIVATE,i.onDeactive,i),i.addEventListener(egret.Event.ENTER_FRAME,i.update,i),i}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;for(var e=0;e=0;t--)GlobalManager.globalManagers[t].enabled&&GlobalManager.globalManagers[t].update();this.entities.updateLists(),this.entityProcessors&&this.entityProcessors.update(),this.entities.update(),this.entityProcessors&&this.entityProcessors.lateUpdate(),this.renderableComponents.updateList(),this.render()},e.prototype.render=function(){for(var t=0;tt&&(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),this._areMatrixesDirty=!0,this},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),0!=this.entity.transform.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,i){void 0===i&&(i=CameraStyle.lockOn);var n=t.call(this)||this;return n.followLerp=.1,n.deadzone=new Rectangle,n.focusOffset=new Vector2,n.mapSize=new Vector2,n._worldSpaceDeadZone=new Rectangle,n._desiredPositionDelta=new Vector2,n._targetEntity=e,n._cameraStyle=i,n.camera=null,n}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var i=this.camera.bounds;switch(this._cameraStyle){case CameraStyle.cameraWindow:var n=i.width/6,o=i.height/3;this.deadzone=new Rectangle((i.width-n)/2,(i.height-o)/2,n,o);break;case CameraStyle.lockOn:this.deadzone=new Rectangle(i.width/2,i.height/2,10,10)}},e.prototype.update=function(){var t=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.transform.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.transform.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),i=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,i)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.transform.position.x,e=this._targetEntity.transform.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 i=this._targetEntity.getComponent(Collider).bounds;this._worldSpaceDeadZone.containsRect(i)||(this._worldSpaceDeadZone.left>i.left?this._desiredPositionDelta.x=i.left-this._worldSpaceDeadZone.left:this._worldSpaceDeadZone.righti.top&&(this._desiredPositionDelta.y=i.top-this._worldSpaceDeadZone.top))}},e}(Component);!function(t){t[t.lockOn=0]="lockOn",t[t.cameraWindow=1]="cameraWindow"}(CameraStyle||(CameraStyle={}));var PointSectors,Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>6;0!=(e&t.LONG_MASK)&&i++,this._bits=new Array(i)}return t.prototype.and=function(t){for(var e,i=Math.min(this._bits.length,t._bits.length),n=0;n=0;)this._bits[e]&=~t._bits[e]},t.prototype.cardinality=function(){for(var t=0,e=this._bits.length-1;e>=0;e--){var i=this._bits[e];if(0!=i)if(-1!=i){var n=((i=((i=(i>>1&0x5555555555555400)+(0x5555555555555400&i))>>2&0x3333333333333400)+(0x3333333333333400&i))>>32)+i;t+=((n=((n=(n>>4&252645135)+(252645135&n))>>8&16711935)+(16711935&n))>>16&65535)+(65535&n)}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,i=1<>6;this.ensure(i),this._bits[i]|=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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){t.transform.updateTransform();for(var e=SceneManager.getActiveScene().entities,i=0;ii?i:t},t.pointOnCirlce=function(e,i,n){var o=t.toRadians(n);return new Vector2(Math.cos(o)*o+e.x,Math.sin(o)*o+e.y)},t.Epsilon=1e-5,t.Rad2Deg=57.29578,t.Deg2Rad=.0174532924,t}(),Matrix2D=function(){function t(t,e,i,n,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=i||0,this.m22=n||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),i=Math.sin(t);this.m11=e,this.m12=i,this.m21=-i,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,i){var n=new t,o=e.m11*i.m11+e.m12*i.m21,r=e.m11*i.m12+e.m12*i.m22,s=e.m21*i.m11+e.m22*i.m21,a=e.m21*i.m12+e.m22*i.m22,h=e.m31*i.m11+e.m32*i.m21+i.m31,c=e.m31*i.m12+e.m32*i.m22+i.m32;return n.m11=o,n.m12=r,n.m21=s,n.m22=a,n.m31=h,n.m32=c,n},t.multiplyTranslation=function(e,i,n){var o=t.createTranslation(i,n);return t.multiply(e,o)},t.prototype.determinant=function(){return this.m11*this.m22-this.m12*this.m21},t.invert=function(e,i){void 0===i&&(i=new t);var n=1/e.determinant();return i.m11=e.m22*n,i.m12=-e.m12*n,i.m21=-e.m21*n,i.m22=e.m11*n,i.m31=(e.m32*e.m21-e.m31*e.m22)*n,i.m32=-(e.m32*e.m11-e.m31*e.m12)*n,i},t.createTranslation=function(e,i,n){return(n=n||new t).m11=1,n.m12=0,n.m21=0,n.m22=1,n.m31=e,n.m32=i,n},t.createRotation=function(e,i){i=new t;var n=Math.cos(e),o=Math.sin(e);return i.m11=n,i.m12=o,i.m21=-o,i.m22=n,i},t.createScale=function(e,i,n){return void 0===n&&(n=new t),n.m11=e,n.m12=0,n.m21=0,n.m22=i,n.m31=0,n.m32=0,n},t._identity=new t(1,0,0,1,0,0),t}(),Rectangle=function(){function t(t,e,i,n){this.x=t||0,this.y=e||0,this.width=i||0,this.height=n||0}return 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.leftn&&(n=s.x),s.yo&&(o=s.y)}return this.fromMinMax(e,i,n,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,i){var n=new t(0,0);return n.x=e.x+i.x,n.y=e.y+i.y,n},t.divide=function(e,i){var n=new t(0,0);return n.x=e.x/i.x,n.y=e.y/i.y,n},t.multiply=function(e,i){var n=new t(0,0);return n.x=e.x*i.x,n.y=e.y*i.y,n},t.subtract=function(e,i){var n=new t(0,0);return n.x=e.x-i.x,n.y=e.y-i.y,n},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 i=t.x-e.x,n=t.y-e.y;return i*i+n*n},t.clamp=function(e,i,n){return new t(MathHelper.clamp(e.x,i.x,n.x),MathHelper.clamp(e.y,i.y,n.y))},t.lerp=function(e,i,n){return new t(MathHelper.lerp(e.x,i.x,n),MathHelper.lerp(e.y,i.y,n))},t.transform=function(e,i){return new t(e.x*i.m11+e.y*i.m21,e.x*i.m12+e.y*i.m22)},t.distance=function(t,e){var i=t.x-e.x,n=t.y-e.y;return Math.sqrt(i*i+n*n)},t.negate=function(e){var i=new t;return i.x=-e.x,i.y=-e.y,i},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}(),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 c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>1)},t.lineToLineIntersection=function(t,e,i,n){var o=new Vector2(0,0),r=Vector2.subtract(e,t),s=Vector2.subtract(n,i),a=r.x*s.y-r.y*s.x;if(0==a)return o;var h=Vector2.subtract(i,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*r.y))},t.closestPointOnLine=function(t,e,i){var n=Vector2.subtract(e,t),o=Vector2.subtract(i,t),r=Vector2.dot(o,n)/Vector2.dot(n,n);return r=MathHelper.clamp(r,0,1),Vector2.add(t,new Vector2(n.x*r,n.y*r))},t.isCircleToCircle=function(t,e,i,n){return Vector2.distanceSquared(t,i)<(e+n)*(e+n)},t.isCircleToLine=function(t,e,i,n){return Vector2.distanceSquared(t,this.closestPointOnLine(i,n,t))=t&&o.y>=e&&o.x=t+i&&(r|=PointSectors.right),o.y=e+n&&(r|=PointSectors.bottom),r},t}(),Physics=function(){function t(){}return t.reset=function(){this._spatialHash=new SpatialHash(this.spatialHashCellSize)},t.overlapCircleAll=function(t,e,i,n){return void 0===n&&(n=-1),this._spatialHash.overlapCircle(t,e,i,n)},t.boxcastBroadphase=function(t,e){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},t.boxcastBroadphaseExcludingSelf=function(t,e,i){return void 0===i&&(i=this.allLayers),this._spatialHash.aabbBroadphase(e,t,i)},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,i){var n=t.call(this)||this;return n.isUnrotated=!0,n._areEdgeNormalsDirty=!0,n.setPoints(e),n.isBox=i,n}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 i=0;i=this.points.length?this.points[0]:this.points[i+1];var o=Vector2Ext.perpendicular(n,t);o=Vector2.normalize(o),this._edgeNormals[i]=o}},e.prototype.setPoints=function(t){this.points=t,this.recalculateCenterAndEdgeNormals(),this._originalPoints=[];for(var e=0;et.y!=this.points[n].y>t.y&&t.x<(this.points[n].x-this.points[i].x)*(t.y-this.points[i].y)/(this.points[n].y-this.points[i].y)+this.points[i].x&&(e=!e);return e},e.buildSymmertricalPolygon=function(t,e){for(var i=new Array(t),n=0;n0&&(o=!1),!o)return null;(y=Math.abs(y))n&&(n=o);return{min:i,max:n}},t.circleToPolygon=function(t,e){var i=new CollisionResult,n=Vector2.subtract(t.position,e.position),o=Polygon.getClosestPointOnPolygonToPoint(e.points,n),r=o.closestPoint,s=o.distanceSquared;i.normal=o.edgeNormal;var a,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)a=Vector2.multiply(i.normal,new Vector2(Math.sqrt(s)-t.radius));else if(0==s)a=Vector2.multiply(i.normal,new Vector2(t.radius));else{var c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(n,r)),new Vector2((t.radius-s)/c))}return i.minimumTranslationVector=a,i.point=Vector2.add(r,e.position),i},t.circleToBox=function(t,e){var i=new CollisionResult,n=e.bounds.getClosestPointOnRectangleBorderToPoint(t.position).res;if(e.containsPoint(t.position)){i.point=n;var o=Vector2.add(n,Vector2.subtract(i.normal,new Vector2(t.radius)));return i.minimumTranslationVector=Vector2.subtract(t.position,o),i}var r=Vector2.distanceSquared(n,t.position);if(0==r)i.minimumTranslationVector=Vector2.multiply(i.normal,new Vector2(t.radius));else if(r<=t.radius*t.radius){i.normal=Vector2.subtract(t.position,n);var s=i.normal.length()-t.radius;return i.normal=Vector2Ext.normalize(i.normal),i.minimumTranslationVector=Vector2.multiply(new Vector2(s),i.normal),i}return null},t.pointToCircle=function(t,e){var i=new CollisionResult,n=Vector2.distanceSquared(t,e.position),o=1+e.radius;if(n=0?t:4294967296+t},t.prototype.add=function(t,e,i){this._store.set(this.getKey(t,e),i)},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}(),Emitter=function(){function t(){this._messageTable=new Map}return t.prototype.addObserver=function(t,e){var i=this._messageTable.get(t);i||(i=[],this._messageTable.set(t,i)),i.contains(e)&&console.warn("您试图添加相同的观察者两次"),i.push(e)},t.prototype.removeObserver=function(t,e){this._messageTable.get(t).remove(e)},t.prototype.emit=function(t,e){var i=this._messageTable.get(t);if(i)for(var n=i.length-1;n>=0;n--)i[n](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(){this._init||(this._init=!0,this._stage=SceneManager.getActiveScene().stage,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 i=new Rectangle(e.x,e.y,0,0);return this.unionR(t,i)},t.unionR=function(t,e){var i=new Rectangle;return i.x=Math.min(t.x,e.x),i.y=Math.min(t.y,e.y),i.width=Math.max(t.right,e.right)-i.x,i.height=Math.max(t.bottom,e.bottom)-i.y,i},t}(),Triangulator=function(){function t(){this.triangleIndices=[],this._triPrev=new Array(12),this._triNext=new Array(12)}return t.prototype.triangulate=function(e,i){void 0===i&&(i=!0);var n=e.length;this.initialize(n);for(var o=0,r=0;n>3&&o<500;){o++;var s=!0,a=e[this._triPrev[r]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){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],n--,r=this._triPrev[r]):r=this._triNext[r]}this.triangleIndices.push(this._triPrev[r]),this.triangleIndices.push(r),this.triangleIndices.push(this._triNext[r]),i||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,i,n,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"===h())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"===h())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(){function t(){this._enabled=!0,this.updateInterval=1}return Object.defineProperty(t.prototype,"transform",{get:function(){return this.entity.transform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"enabled",{get:function(){return this.entity?this.entity.enabled&&this._enabled:this._enabled},set:function(t){this.setEnabled(t)},enumerable:!0,configurable:!0}),t.prototype.setEnabled=function(t){return this._enabled!=t&&(this._enabled=t,this._enabled?this.onEnabled():this.onDisabled()),this},Object.defineProperty(t.prototype,"stage",{get:function(){return this.entity?this.entity.stage:null},enumerable:!0,configurable:!0}),t.prototype.initialize=function(){},t.prototype.onAddedToEntity=function(){},t.prototype.onRemovedFromEntity=function(){},t.prototype.onEnabled=function(){},t.prototype.onDisabled=function(){},t.prototype.onEntityTransformChanged=function(t){},t.prototype.update=function(){},t.prototype.debugRender=function(){},t.prototype.registerComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this),!1),this.entity.scene.entityProcessors.onComponentAdded(this.entity)},t.prototype.deregisterComponent=function(){this.entity.componentBits.set(ComponentTypeManager.getIndexFor(this)),this.entity.scene.entityProcessors.onComponentRemoved(this.entity)},t}(),Entity=function(){function t(e){this._updateOrder=0,this._enabled=!0,this._tag=0,this.name=e,this.transform=new Transform(this),this.components=new ComponentList(this),this.id=t._idGenerator++,this.componentBits=new BitSet}return Object.defineProperty(t.prototype,"parent",{get:function(){return this.transform.parent},set:function(t){this.transform.setParent(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"position",{get:function(){return this.transform.position},set:function(t){this.transform.setPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localPosition",{get:function(){return this.transform.localPosition},set:function(t){this.transform.setLocalPosition(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotation",{get:function(){return this.transform.rotation},set:function(t){this.transform.setRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rotationDegrees",{get:function(){return this.transform.rotationDegrees},set:function(t){this.transform.setRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotation",{get:function(){return this.transform.localRotation},set:function(t){this.transform.setLocalRotation(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localRotationDegrees",{get:function(){return this.transform.localRotationDegrees},set:function(t){this.transform.setLocalRotationDegrees(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"scale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localScale",{get:function(){return this.transform.scale},set:function(t){this.transform.setScale(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldInverseTransform",{get:function(){return this.transform.worldInverseTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"localToWorldTransform",{get:function(){return this.transform.localToWorldTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"worldToLocalTransform",{get:function(){return this.transform.worldToLocalTransform},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isDestoryed",{get:function(){return this._isDestoryed},enumerable:!0,configurable:!0}),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){return this._enabled!=t&&(this._enabled=t),this},Object.defineProperty(t.prototype,"tag",{get:function(){return this._tag},set:function(t){this.setTag(t)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"stage",{get:function(){return this.scene?this.scene.stage:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"updateOrder",{get:function(){return this._updateOrder},set:function(t){this.setUpdateOrder(t)},enumerable:!0,configurable:!0}),t.prototype.setUpdateOrder=function(t){if(this._updateOrder!=t)return this._updateOrder=t,this.scene,this},t.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},t.prototype.attachToScene=function(t){this.scene=t,t.entities.add(this),this.components.registerAllComponents();for(var e=0;e=0;t--){this.transform.getChild(t).entity.destory()}},t}(),Scene=function(t){function e(e){var n=t.call(this)||this;return n._renderers=[],e.stage.addChild(n),n._projectionMatrix=new Matrix2D(0,0,0,0,0,0),n.entityProcessors=new EntityProcessorList,n.renderableComponents=new RenderableComponentList,n.entities=new EntityList(n),n.content=new ContentManager,n.addEventListener(egret.Event.ACTIVATE,n.onActive,n),n.addEventListener(egret.Event.DEACTIVATE,n.onDeactive,n),n}return __extends(e,t),e.prototype.createEntity=function(t){var e=new Entity(t);return e.transform.position=new Vector2(0,0),this.addEntity(e)},e.prototype.addEntity=function(t){this.entities.add(t),t.scene=this;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),this._areMatrixesDirty=!0,this},e.prototype.setPosition=function(t){return this.entity.transform.setPosition(t),this},e.prototype.forceMatrixUpdate=function(){this._areMatrixesDirty=!0},e.prototype.updateMatrixes=function(){var t;this._areMatrixesDirty&&(this._transformMatrix=Matrix2D.createTranslation(-this.entity.transform.position.x,-this.entity.transform.position.y),1!=this._zoom&&(t=Matrix2D.createScale(this._zoom,this._zoom),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),0!=this.entity.transform.rotation&&(t=Matrix2D.createRotation(this.entity.rotation),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t)),t=Matrix2D.createTranslation(this._origin.x,this._origin.y,t),this._transformMatrix=Matrix2D.multiply(this._transformMatrix,t),this._inverseTransformMatrix=Matrix2D.invert(this._transformMatrix),this._areBoundsDirty=!0,this._areMatrixesDirty=!1)},e.prototype.screenToWorldPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._inverseTransformMatrix)},e.prototype.worldToScreenPoint=function(t){return this.updateMatrixes(),Vector2Ext.transformR(t,this._transformMatrix)},e.prototype.onEntityTransformChanged=function(t){this._areMatrixesDirty=!0},e.prototype.destory=function(){},e}(Component),CameraInset=function(){return function(){this.left=0,this.right=0,this.top=0,this.bottom=0}}(),FollowCamera=function(t){function e(e,n){void 0===n&&(n=CameraStyle.lockOn);var i=t.call(this)||this;return i.followLerp=.1,i.deadzone=new Rectangle,i.focusOffset=new Vector2,i.mapSize=new Vector2,i._worldSpaceDeadZone=new Rectangle,i._desiredPositionDelta=new Vector2,i._targetEntity=e,i._cameraStyle=n,i.camera=null,i}return __extends(e,t),e.prototype.onAddedToEntity=function(){this.camera||(this.camera=this.entity.scene.camera),this.follow(this._targetEntity,this._cameraStyle)},e.prototype.follow=function(t,e){void 0===e&&(e=CameraStyle.cameraWindow),this._targetEntity=t,this._cameraStyle=e;var n=this.camera.bounds;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=Vector2.multiply(this.camera.bounds.size,new Vector2(.5));this._worldSpaceDeadZone.x=this.camera.position.x-t.x+this.deadzone.x+this.focusOffset.x,this._worldSpaceDeadZone.y=this.camera.position.y-t.y+this.deadzone.y+this.focusOffset.y,this._worldSpaceDeadZone.width=this.deadzone.width,this._worldSpaceDeadZone.height=this.deadzone.height,this._targetEntity&&this.updateFollow(),this.camera.position=Vector2.lerp(this.camera.position,Vector2.add(this.camera.position,this._desiredPositionDelta),this.followLerp),this.camera.entity.transform.roundPosition(),this.mapLockEnabled&&(this.camera.position=this.clampToMapSize(this.camera.position),this.camera.entity.transform.roundPosition())},e.prototype.clampToMapSize=function(t){var e=Vector2.multiply(new Vector2(this.camera.bounds.width,this.camera.bounds.height),new Vector2(.5)),n=new Vector2(this.mapSize.x-e.x,this.mapSize.y-e.y);return Vector2.clamp(t,e,n)},e.prototype.updateFollow=function(){if(this._desiredPositionDelta.x=this._desiredPositionDelta.y=0,this._cameraStyle==CameraStyle.lockOn){var t=this._targetEntity.transform.position.x,e=this._targetEntity.transform.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 PointSectors,Mesh=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return __extends(e,t),e.prototype.initialize=function(){},e.prototype.setVertPosition=function(t){(!this._verts||this._verts.length!=t.length)&&(this._verts=new Array(t.length));for(var e=0;e>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}(),RenderableComponentList=function(){function t(){this._components=[]}return Object.defineProperty(t.prototype,"count",{get:function(){return this._components.length},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"buffer",{get:function(){return this._components},enumerable:!0,configurable:!0}),t.prototype.add=function(t){this._components.push(t)},t.prototype.remove=function(t){this._components.remove(t)},t.prototype.updateList=function(){},t}(),Time=function(){function t(){}return t.update=function(t){var e=(t-this._lastTime)/1e3;this.deltaTime=e*this.timeScale,this.unscaledDeltaTime=e,this.frameCount++,this._lastTime=t},t.deltaTime=0,t.timeScale=1,t.frameCount=0,t._lastTime=0,t}(),Renderer=function(){function t(){}return t.prototype.onAddedToScene=function(t){},t.prototype.beginRender=function(t){t.transform.updateTransform();for(var e=SceneManager.scene.entities,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.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,h=e.m31*n.m11+e.m32*n.m21+n.m31,c=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=h,i.m32=c,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._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,"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}(),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 c=(a.x*o.y-a.y*o.x)/s;return!(c<0||c>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 h=Vector2.subtract(n,t),c=(h.x*s.y-h.y*s.x)/a;if(c<0||c>1)return o;var u=(h.x*r.y-h.y*r.x)/a;return u<0||u>1?o:o=Vector2.add(t,new Vector2(c*r.x,c*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){return void 0===e&&(e=this.allLayers),this._spatialHash.aabbBroadphase(t,null,e)},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;(y=Math.abs(y))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,h=e.containsPoint(t.position);if(s>t.radius*t.radius&&!h)return null;if(h)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 c=Math.sqrt(s);a=Vector2.multiply(new Vector2(-Vector2.subtract(i,r)),new Vector2((t.radius-s)/c))}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.load=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]],h=e[r],c=e[this._triNext[r]];if(Vector2Ext.isTriangleCCW(a,h,c)){var u=this._triNext[this._triNext[r]];do{if(t.testPointTriangle(e[u],a,h,c)){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 number; + /** + * get pow in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get pow in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getPowIn(pow: number): (t: number) => number; + /** + * get pow out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get pow out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getPowOut(pow: number): (t: number) => number; + /** + * get pow in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get pow in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getPowInOut(pow: number): (t: number) => number; + /** + * quad in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quad in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quadIn: (t: number) => number; + /** + * quad out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quad out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quadOut: (t: number) => number; + /** + * quad in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quad in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quadInOut: (t: number) => number; + /** + * cubic in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * cubic in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static cubicIn: (t: number) => number; + /** + * cubic out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * cubic out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static cubicOut: (t: number) => number; + /** + * cubic in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * cubic in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static cubicInOut: (t: number) => number; + /** + * quart in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quart in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quartIn: (t: number) => number; + /** + * quart out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quart out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quartOut: (t: number) => number; + /** + * quart in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quart in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quartInOut: (t: number) => number; + /** + * quint in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quint in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quintIn: (t: number) => number; + /** + * quint out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quint out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quintOut: (t: number) => number; + /** + * quint in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * quint in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static quintInOut: (t: number) => number; + /** + * sine in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * sine in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static sineIn(t: number): number; + /** + * sine out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * sine out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static sineOut(t: number): number; + /** + * sine in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * sine in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static sineInOut(t: number): number; + /** + * get back in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get back in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getBackIn(amount: number): (t: number) => number; + /** + * back in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * back in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static backIn: (t: number) => number; + /** + * get back out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get back out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getBackOut(amount: number): (t: any) => number; + /** + * back out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * back out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static backOut: (t: any) => number; + /** + * get back in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get back in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getBackInOut(amount: number): (t: number) => number; + /** + * back in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * back in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static backInOut: (t: number) => number; + /** + * circ in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * circ in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static circIn(t: number): number; + /** + * circ out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * circ out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static circOut(t: number): number; + /** + * circ in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * circ in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static circInOut(t: number): number; + /** + * bounce in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * bounce in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static bounceIn(t: number): number; + /** + * bounce out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * bounce out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static bounceOut(t: number): number; + /** + * bounce in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * bounce in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static bounceInOut(t: number): number; + /** + * get elastic in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get elastic in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getElasticIn(amplitude: number, period: number): (t: number) => number; + /** + * elastic in.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * elastic in。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static elasticIn: (t: number) => number; + /** + * get elastic out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get elastic out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getElasticOut(amplitude: number, period: number): (t: number) => number; + /** + * elastic out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * elastic out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static elasticOut: (t: number) => number; + /** + * get elastic in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * get elastic in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static getElasticInOut(amplitude: number, period: number): (t: number) => number; + /** + * elastic in out.See example. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * elastic in out。请查看示例 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static elasticInOut: (t: number) => number; + } +} +declare namespace egret { + /** + * Tween is the animation easing class of Egret + * @see http://edn.egret.com/cn/docs/page/576 Tween ease animation + * @version Egret 2.4 + * @platform Web,Native + * @includeExample extension/tween/Tween.ts + * @language en_US + */ + /** + * Tween是Egret的动画缓动类 + * @see http://edn.egret.com/cn/docs/page/576 Tween缓动动画 + * @version Egret 2.4 + * @platform Web,Native + * @includeExample extension/tween/Tween.ts + * @language zh_CN + */ + class Tween extends EventDispatcher { + /** + * 不做特殊处理 + * @constant {number} egret.Tween.NONE + * @private + */ + private static NONE; + /** + * 循环 + * @constant {number} egret.Tween.LOOP + * @private + */ + private static LOOP; + /** + * 倒序 + * @constant {number} egret.Tween.REVERSE + * @private + */ + private static REVERSE; + /** + * @private + */ + private static _tweens; + /** + * @private + */ + private static IGNORE; + /** + * @private + */ + private static _plugins; + /** + * @private + */ + private static _inited; + /** + * @private + */ + private _target; + /** + * @private + */ + private _useTicks; + /** + * @private + */ + private ignoreGlobalPause; + /** + * @private + */ + private loop; + /** + * @private + */ + private pluginData; + /** + * @private + */ + private _curQueueProps; + /** + * @private + */ + private _initQueueProps; + /** + * @private + */ + private _steps; + /** + * @private + */ + private paused; + /** + * @private + */ + private duration; + /** + * @private + */ + private _prevPos; + /** + * @private + */ + private position; + /** + * @private + */ + private _prevPosition; + /** + * @private + */ + private _stepPosition; + /** + * @private + */ + private passive; + /** + * Activate an object and add a Tween animation to the object + * @param target {any} The object to be activated + * @param props {any} Parameters, support loop onChange onChangeObj + * @param pluginData {any} Write realized + * @param override {boolean} Whether to remove the object before adding a tween, the default value false + * Not recommended, you can use Tween.removeTweens(target) instead. + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 激活一个对象,对其添加 Tween 动画 + * @param target {any} 要激活 Tween 的对象 + * @param props {any} 参数,支持loop(循环播放) onChange(变化函数) onChangeObj(变化函数作用域) + * @param pluginData {any} 暂未实现 + * @param override {boolean} 是否移除对象之前添加的tween,默认值false。 + * 不建议使用,可使用 Tween.removeTweens(target) 代替。 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static get(target: any, props?: { + loop?: boolean; + onChange?: Function; + onChangeObj?: any; + }, pluginData?: any, override?: boolean): Tween; + /** + * Delete all Tween animations from an object + * @param target The object whose Tween to be deleted + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 删除一个对象上的全部 Tween 动画 + * @param target 需要移除 Tween 的对象 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static removeTweens(target: any): void; + /** + * Pause all Tween animations of a certain object + * @param target The object whose Tween to be paused + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 暂停某个对象的所有 Tween + * @param target 要暂停 Tween 的对象 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static pauseTweens(target: any): void; + /** + * Resume playing all easing of a certain object + * @param target The object whose Tween to be resumed + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 继续播放某个对象的所有缓动 + * @param target 要继续播放 Tween 的对象 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static resumeTweens(target: any): void; + /** + * @private + * + * @param delta + * @param paused + */ + private static tick(timeStamp, paused?); + private static _lastTime; + /** + * @private + * + * @param tween + * @param value + */ + private static _register(tween, value); + /** + * Delete all Tween + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 删除所有 Tween + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + static removeAllTweens(): void; + /** + * 创建一个 egret.Tween 对象 + * @private + * @version Egret 2.4 + * @platform Web,Native + */ + constructor(target: any, props: any, pluginData: any); + /** + * @private + * + * @param target + * @param props + * @param pluginData + */ + private initialize(target, props, pluginData); + /** + * @private + * + * @param value + * @param actionsMode + * @returns + */ + setPosition(value: number, actionsMode?: number): boolean; + /** + * @private + * + * @param startPos + * @param endPos + * @param includeStart + */ + private _runAction(action, startPos, endPos, includeStart?); + /** + * @private + * + * @param step + * @param ratio + */ + private _updateTargetProps(step, ratio); + /** + * Whether setting is paused + * @param value {boolean} Whether to pause + * @returns Tween object itself + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 设置是否暂停 + * @param value {boolean} 是否暂停 + * @returns Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + setPaused(value: boolean): Tween; + /** + * @private + * + * @param props + * @returns + */ + private _cloneProps(props); + /** + * @private + * + * @param o + * @returns + */ + private _addStep(o); + /** + * @private + * + * @param o + * @returns + */ + private _appendQueueProps(o); + /** + * @private + * + * @param o + * @returns + */ + private _addAction(o); + /** + * @private + * + * @param props + * @param o + */ + private _set(props, o); + /** + * Wait the specified milliseconds before the execution of the next animation + * @param duration {number} Waiting time, in milliseconds + * @param passive {boolean} Whether properties are updated during the waiting time + * @returns Tween object itself + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 等待指定毫秒后执行下一个动画 + * @param duration {number} 要等待的时间,以毫秒为单位 + * @param passive {boolean} 等待期间属性是否会更新 + * @returns Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + wait(duration: number, passive?: boolean): Tween; + /** + * Modify the property of the specified object to a specified value + * @param props {Object} Property set of an object + * @param duration {number} Duration + * @param ease {egret.Ease} Easing algorithm + * @returns {egret.Tween} Tween object itself + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 将指定对象的属性修改为指定值 + * @param props {Object} 对象的属性集合 + * @param duration {number} 持续时间 + * @param ease {egret.Ease} 缓动算法 + * @returns {egret.Tween} Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + to(props: any, duration?: number, ease?: Function): Tween; + /** + * Execute callback function + * @param callback {Function} Callback method + * @param thisObj {any} this action scope of the callback method + * @param params {any[]} Parameter of the callback method + * @returns {egret.Tween} Tween object itself + * @version Egret 2.4 + * @platform Web,Native + * @example + *
+         *  egret.Tween.get(display).call(function (a:number, b:string) {
+         *      console.log("a: " + a); // the first parameter passed 233
+         *      console.log("b: " + b); // the second parameter passed “hello”
+         *  }, this, [233, "hello"]);
+         * 
+ * @language en_US + */ + /** + * 执行回调函数 + * @param callback {Function} 回调方法 + * @param thisObj {any} 回调方法this作用域 + * @param params {any[]} 回调方法参数 + * @returns {egret.Tween} Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + * @example + *
+         *  egret.Tween.get(display).call(function (a:number, b:string) {
+         *      console.log("a: " + a); //对应传入的第一个参数 233
+         *      console.log("b: " + b); //对应传入的第二个参数 “hello”
+         *  }, this, [233, "hello"]);
+         * 
+ * @language zh_CN + */ + call(callback: Function, thisObj?: any, params?: any[]): Tween; + /** + * Now modify the properties of the specified object to the specified value + * @param props {Object} Property set of an object + * @param target The object whose Tween to be resumed + * @returns {egret.Tween} Tween object itself + * @version Egret 2.4 + * @platform Web,Native + */ + /** + * 立即将指定对象的属性修改为指定值 + * @param props {Object} 对象的属性集合 + * @param target 要继续播放 Tween 的对象 + * @returns {egret.Tween} Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + */ + set(props: any, target?: any): Tween; + /** + * Execute + * @param tween {egret.Tween} The Tween object to be operated. Default: this + * @returns {egret.Tween} Tween object itself + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 执行 + * @param tween {egret.Tween} 需要操作的 Tween 对象,默认this + * @returns {egret.Tween} Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + play(tween?: Tween): Tween; + /** + * Pause + * @param tween {egret.Tween} The Tween object to be operated. Default: this + * @returns {egret.Tween} Tween object itself + * @version Egret 2.4 + * @platform Web,Native + * @language en_US + */ + /** + * 暂停 + * @param tween {egret.Tween} 需要操作的 Tween 对象,默认this + * @returns {egret.Tween} Tween对象本身 + * @version Egret 2.4 + * @platform Web,Native + * @language zh_CN + */ + pause(tween?: Tween): Tween; + /** + * @method egret.Tween#tick + * @param delta {number} + * @private + * @version Egret 2.4 + * @platform Web,Native + */ + $tick(delta: number): void; + } +} +declare namespace egret.tween { + type EaseType = 'quadIn' | 'quadOut' | 'quadOut' | 'quadInOut' | 'cubicIn' | 'cubicOut' | 'cubicInOut' | 'quartIn' | 'quartOut' | 'quartInOut' | 'quintIn' | 'quintOut' | 'quintInOut' | 'sineIn' | 'sineOut' | 'sineInOut' | 'backIn' | 'backOut' | 'backInOut' | 'circIn' | 'circOut' | 'circInOut' | 'bounceIn' | 'bounceOut' | 'bounceInOut' | 'elasticIn' | 'elasticOut' | 'elasticInOut'; + /** + * Abstract class, Indicate the base action. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 抽象类,表示一个基本动作 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + abstract class BasePath extends EventDispatcher { + /** + * the name of this action. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 动作的名称 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + name: string; + } + /** + * Indicate the to action. See Tween.to + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 表示一个to动作,参见Tween.to + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + class To extends BasePath { + /** + * Property set of an object + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 对象的属性集合 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + props: Object; + /** + * Duration + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 持续时间 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + duration: number; + /** + * Easing algorithm + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 缓动算法 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + ease: EaseType | Function; + } + /** + * Indicate the wait action. See Tween.wait + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 表示一个wait动作,参见Tween.wait + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + class Wait extends BasePath { + /** + * Duration + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 持续时间 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + duration: number; + /** + * Whether properties are updated during the waiting time + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 等待期间属性是否会更新 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + passive: boolean; + } + /** + * Indicate the set action. See Tween.set + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 表示一个set动作,参见Tween.set + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + class Set extends BasePath { + /** + * Property set of an object + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 对象的属性集合 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + props: Object; + } + /** + * Indicate the tick action. See Tween.tick + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 表示一个tick动作,参见Tween.tick + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + class Tick extends BasePath { + /** + * Delta time + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 增加的时间 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + delta: number; + } + /** + * TweenItem is a wrapper for Tween, which can set the behavior of Tween by setting attributes and adding Path. + * + * @event pathComplete Dispatched when some Path has complete. + * @event complete Dispatched when all Paths has complete. + * + * @defaultProperty props + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * TweenItem是对Tween的包装器,能通过设置属性和添加Path的方式设置Tween的行为。 + * 通常用于使用在EXML中定义组件的动画。 + * + * @event pathComplete 当某个Path执行完毕时会派发此事件。 + * @event complete 当所有Path执行完毕时会派发此事件。 + * + * @defaultProperty props + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + /** + * Use in exml: + * ``` + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * ``` + */ + class TweenItem extends EventDispatcher { + private tween; + constructor(); + /** + * @private + */ + private _props; + /** + * The Tween's props. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * Tween的props参数。 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + props: any; + /** + * @private + */ + private _target; + /** + * The Tween's target. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * Tween的target参数。 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + target: any; + /** + * @private + */ + private _paths; + /** + * The Actions in Tween. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * TweenItem中添加的行为。 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + paths: BasePath[]; + /** + * Play the Tween + * @position The starting position, the default is from the last position to play + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 播放Tween + * @position 播放的起始位置, 默认为从上次位置继续播放 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + play(position?: number): void; + /** + * Pause the Tween + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 暂停Tween + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + pause(): void; + private isStop; + /** + * Stop the Tween + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 停止Tween + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + stop(): void; + private createTween(position); + private applyPaths(); + private applyPath(path); + private pathComplete(path); + } + /** + * TweenGroup is a collection of TweenItem that can be played in parallel with each Item + * + * @event itemComplete Dispatched when some TweenItem has complete. + * @event complete Dispatched when all TweenItems has complete. + * + * @version Egret 3.1.8 + * @platform Web,Native + * @includeExample extension/tween/TweenWrapper.ts + * @language en_US + */ + /** + * TweenGroup是TweenItem的集合,可以并行播放每一个Item + * @version Egret 3.1.8 + * @platform Web,Native + * @includeExample extension/tween/TweenWrapper.ts + * @language zh_CN + */ + class TweenGroup extends EventDispatcher { + private completeCount; + constructor(); + /** + * @private + */ + private _items; + /** + * The Array that TweenItems in TweenGroup. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * TweenGroup要控制的TweenItem集合。 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + items: TweenItem[]; + private registerEvent(add); + /** + * Play the all TweenItems + * @time The starting position, the default is from the last position to play。If use 0, the group will play from the start position. + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 播放所有的TweenItem + * @time 播放的起始位置, 默认为从上次位置继续播放。如果为0,则从起始位置开始播放。 + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + play(time?: number): void; + /** + * Pause the all TweenItems + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 暂停播放所有的TweenItem + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + pause(): void; + /** + * Stop the all TweenItems + * @version Egret 3.1.8 + * @platform Web,Native + * @language en_US + */ + /** + * 停止所有的TweenItem + * @version Egret 3.1.8 + * @platform Web,Native + * @language zh_CN + */ + stop(): void; + private itemComplete(e); + } +} diff --git a/source/src/ECS/Components/SpriteRenderer.ts b/source/src/ECS/Components/SpriteRenderer.ts index 9650871e..a2fff8f9 100644 --- a/source/src/ECS/Components/SpriteRenderer.ts +++ b/source/src/ECS/Components/SpriteRenderer.ts @@ -76,10 +76,10 @@ class SpriteRenderer extends RenderableComponent { this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x; this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y; - this._bitmap.rotation = this.entity.transform.rotation; + this._bitmap.rotation = this.entity.transform.rotation + camera.transform.rotation; this._bitmap.anchorOffsetX = this._origin.x; this._bitmap.anchorOffsetY = this._origin.y; - this._bitmap.scaleX = this.entity.transform.scale.x; - this._bitmap.scaleY = this.entity.transform.scale.y; + this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x; + this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y; } } \ No newline at end of file diff --git a/source/src/ECS/Scene.ts b/source/src/ECS/Scene.ts index 20eaa92a..c7b95787 100644 --- a/source/src/ECS/Scene.ts +++ b/source/src/ECS/Scene.ts @@ -3,11 +3,13 @@ class Scene extends egret.DisplayObjectContainer { public camera: Camera; public readonly entities: EntityList; public readonly renderableComponents: RenderableComponentList; + public readonly content: ContentManager; private _projectionMatrix: Matrix2D; private _transformMatrix: Matrix2D; private _matrixTransformMatrix: Matrix2D; private _renderers: Renderer[] = []; + private _didSceneBegin; public readonly entityProcessors: EntityProcessorList; @@ -18,10 +20,10 @@ class Scene extends egret.DisplayObjectContainer { this.entityProcessors = new EntityProcessorList(); this.renderableComponents = new RenderableComponentList(); this.entities = new EntityList(this); + this.content = new ContentManager(); this.addEventListener(egret.Event.ACTIVATE, this.onActive, this); this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.addEventListener(egret.Event.ENTER_FRAME, this.update, this); } public createEntity(name: string) { @@ -68,12 +70,6 @@ class Scene extends egret.DisplayObjectContainer { return this.entityProcessors.getProcessor(); } - public setActive(): Scene { - SceneManager.setActiveScene(this); - - return this; - } - public addRenderer(renderer: T) { this._renderers.push(renderer); this._renderers.sort(); @@ -96,8 +92,7 @@ class Scene extends egret.DisplayObjectContainer { this._renderers.remove(renderer); } - /** 初始化场景 */ - public initialize() { + public begin(){ if (this._renderers.length == 0) { this.addRenderer(new DefaultRenderer()); console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染"); @@ -106,32 +101,49 @@ class Scene extends egret.DisplayObjectContainer { this.camera = this.createEntity("camera").getOrCreateComponent(new Camera()); Physics.reset(); - Input.initialize(); if (this.entityProcessors) this.entityProcessors.begin(); this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight); + + this._didSceneBegin = true; + this.onStart(); + } + + public end(){ + this._didSceneBegin = false; + + this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); + this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); + + this.entities.removeAllEntities(); + + Physics.clear(); + + this.camera.destory(); + this.camera = null; + this.content.dispose(); + + if (this.entityProcessors) + this.entityProcessors.end(); + } + + protected onStart(){ + } /** 场景激活 */ - public onActive() { + protected onActive() { } /** 场景失去焦点 */ - public onDeactive() { + protected onDeactive() { } public update() { - Time.update(egret.getTimer()); - - for (let i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { - if (GlobalManager.globalManagers[i].enabled) - GlobalManager.globalManagers[i].update(); - } - this.entities.updateLists(); if (this.entityProcessors) @@ -143,7 +155,6 @@ class Scene extends egret.DisplayObjectContainer { this.entityProcessors.lateUpdate(); this.renderableComponents.updateList(); - this.render(); } public render(){ @@ -154,22 +165,4 @@ class Scene extends egret.DisplayObjectContainer { this._renderers[i].render(this); } } - - public prepRenderState() { - this._projectionMatrix.m11 = 2 / this.stage.stageWidth; - this._projectionMatrix.m22 = -2 / this.stage.stageHeight; - - this._transformMatrix = this.camera.transformMatrix; - this._matrixTransformMatrix = Matrix2D.multiply(this._transformMatrix, this._projectionMatrix); - } - - public destory() { - this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this); - this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this); - - this.camera.destory(); - this.camera = null; - - this.entities.removeAllEntities(); - } } \ No newline at end of file diff --git a/source/src/ECS/SceneManager.ts b/source/src/ECS/SceneManager.ts index 6af4d2bd..80b607e0 100644 --- a/source/src/ECS/SceneManager.ts +++ b/source/src/ECS/SceneManager.ts @@ -1,40 +1,94 @@ /** 运行时的场景管理。 */ class SceneManager { - private static _loadedScenes: Map = new Map(); - /** 上一个场景 */ - private static _lastScene: Scene; - /** 当前激活的场景 */ - private static _activeScene: Scene; + private static _scene: Scene; + private static _nextScene: Scene; + public static sceneTransition: SceneTransition; - /** - * 使用给定的名称在运行时创建一个空的新场景。 - * 新场景将与当前打开的任何现有场景一起被添加到层次结构中。 - * 这个函数用于在运行时创建场景。 - * @param name - * @param scene - */ - public static createScene(name: string, scene: Scene){ - scene.name = name; - this._loadedScenes.set(name, scene); - return scene; + constructor(stage: egret.Stage) { + stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this); + + SceneManager.initialize(stage); } - public static setActiveScene(scene: Scene){ - if (this._activeScene){ - // 如果场景相同则不进行切换 - if (this._activeScene == scene) - return; + public static get scene() { + return this._scene; + } + public static set scene(value: Scene) { + if (!value) + throw new Error("场景不能为空"); - this._lastScene = this._activeScene; - this._activeScene.destory(); + if (this._scene == null) { + this._scene = value; + this._scene.begin(); + } else { + this._nextScene = value; + } + } + + public static initialize(stage: egret.Stage) { + Input.initialize(stage); + } + + public static update() { + Time.update(egret.getTimer()); + + if (SceneManager._scene) { + for (let i = GlobalManager.globalManagers.length - 1; i >= 0; i--) { + if (GlobalManager.globalManagers[i].enabled) + GlobalManager.globalManagers[i].update(); + } + + if (!SceneManager.sceneTransition || + (SceneManager.sceneTransition && (!SceneManager.sceneTransition.loadsNewScene || SceneManager.sceneTransition.isNewSceneLoaded))) { + SceneManager._scene.update(); + } + + if (SceneManager._nextScene) { + SceneManager._scene.end(); + + for (let i = 0; i < SceneManager._scene.entities.buffer.length; i++) { + let entity = SceneManager._scene.entities.buffer[i]; + entity.destory(); + } + + SceneManager._scene = SceneManager._nextScene; + SceneManager._nextScene = null; + + SceneManager._scene.begin(); + } } - this._activeScene = scene; - this._activeScene.initialize(); - return scene; + SceneManager.render(); } - public static getActiveScene(){ - return this._activeScene; + public static render() { + if (this.sceneTransition) + this.sceneTransition.preRender(); + + if (this.sceneTransition) { + if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) { + this._scene.render(); + this.sceneTransition.onBeginTransition(); + } else if (this._scene && this.sceneTransition.isNewSceneLoaded) { + this._scene.render(); + } + + this.sceneTransition.render(); + } else if (this.scene) { + this.scene.render(); + } + } + + /** + * 临时运行SceneTransition,允许一个场景过渡到另一个平滑的自定义效果。 + * @param sceneTransition + */ + public static startSceneTransition(sceneTransition: T): T { + if (!this.sceneTransition) { + throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。"); + } + + this.sceneTransition = sceneTransition; + return sceneTransition; } } \ No newline at end of file diff --git a/source/src/Graphics/Renderers/Renderer.ts b/source/src/Graphics/Renderers/Renderer.ts index 418495dd..9e4e3d49 100644 --- a/source/src/Graphics/Renderers/Renderer.ts +++ b/source/src/Graphics/Renderers/Renderer.ts @@ -18,7 +18,7 @@ abstract class Renderer { protected beginRender(cam: Camera){ cam.transform.updateTransform(); - let entities = SceneManager.getActiveScene().entities; + let entities = SceneManager.scene.entities; for (let i = 0; i < entities.buffer.length; i ++){ entities.buffer[i].transform.updateTransform(); } diff --git a/source/src/Graphics/Transitions/FadeTransition.ts b/source/src/Graphics/Transitions/FadeTransition.ts new file mode 100644 index 00000000..55a6cddb --- /dev/null +++ b/source/src/Graphics/Transitions/FadeTransition.ts @@ -0,0 +1,33 @@ +/// +class FadeTransition extends SceneTransition { + public fadeToColor: number = 0x000000; + public fadeOutDuration = 0.4; + private _color: number = 0xFFFFFF; + private _toColor: number = 0xFFFFFF; + private _destinationRect: Rectangle; + private _overlayTexture: egret.RenderTexture; + + constructor(sceneLoadAction: Function){ + super(sceneLoadAction, true); + this._destinationRect = new Rectangle(0, 0, this.previousSceneRender.textureWidth, this.previousSceneRender.textureHeight); + } + + // public onBeginTransition(){ + // this._overlayTexture = new egret.RenderTexture(); + // let shape = new egret.Shape(); + // shape.graphics.beginFill(0xFFFFFF, 1); + // shape.graphics.drawRect(0, 0, 1, 1); + // shape.graphics.endFill(); + // this._overlayTexture.drawToTexture(shape); + + // let elapsed = 0; + // let _toColor; + // while (elapsed < this.fadeOutDuration){ + // elapsed += Time.deltaTime; + + // // egret.Tween.get(this).to({_color: this._toColor, }) + // } + + + // } +} \ No newline at end of file diff --git a/source/src/Graphics/Transitions/SceneTransition.ts b/source/src/Graphics/Transitions/SceneTransition.ts new file mode 100644 index 00000000..1b3672e6 --- /dev/null +++ b/source/src/Graphics/Transitions/SceneTransition.ts @@ -0,0 +1,86 @@ +/** + * SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡 + */ +abstract class SceneTransition { + /** 是否加载新场景的标志 */ + public loadsNewScene: boolean; + /** + * 将此用于两个部分的转换。例如,淡出会先淡出到黑色,然后当isNewSceneLoaded为true,它会淡出。 + * 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。 + */ + public isNewSceneLoaded: boolean; + /** + * 如果为true + * 会将之前的场景渲染到previousSceneRender中,这样你就可以在转换时使用它 + */ + public wantsPreviousSceneRender: boolean; + /** 返回新加载场景的函数 */ + protected sceneLoadAction: Function; + /** 包含上一个场景的最后渲染。可以用来在加载新场景时模糊屏幕。 */ + public previousSceneRender: egret.RenderTexture; + /** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */ + public onScreenObscured: Function; + /** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */ + public onTransitionCompleted: Function; + public progress: number = 0; + + constructor(sceneLoadAction: Function, wantsPreviousSceneRender: boolean = true) { + this.sceneLoadAction = sceneLoadAction; + this.wantsPreviousSceneRender = wantsPreviousSceneRender; + this.loadsNewScene = sceneLoadAction != null; + + if (wantsPreviousSceneRender) + this.previousSceneRender = new egret.RenderTexture(); + } + + private _hasPreviousSceneRender; + public get hasPreviousSceneRender() { + if (!this._hasPreviousSceneRender) { + this._hasPreviousSceneRender = true; + return false; + } + + return true; + } + + public preRender() { } + + public render(){ + + } + + public onBeginTransition(): Promise { + return new Promise((resolve) => { + resolve(this.loadScene()); + this.transitionComplete(); + }); + } + + protected transitionComplete() { + SceneManager.sceneTransition = null; + + if (this.previousSceneRender){ + this.previousSceneRender.dispose(); + this.previousSceneRender = null; + } + + if (this.onTransitionCompleted){ + this.onTransitionCompleted(); + } + } + + protected loadScene(): Promise { + return new Promise(async (resolve) => { + if (this.onScreenObscured) + this.onScreenObscured(); + + if (!this.loadsNewScene) { + this.isNewSceneLoaded = true; + resolve(); + } + + SceneManager.scene = await this.sceneLoadAction(); + this.isNewSceneLoaded = true; + }); + } +} \ No newline at end of file diff --git a/source/src/Physics/Physics.ts b/source/src/Physics/Physics.ts index 01414237..0be248a7 100644 --- a/source/src/Physics/Physics.ts +++ b/source/src/Physics/Physics.ts @@ -9,6 +9,10 @@ class Physics { this._spatialHash = new SpatialHash(this.spatialHashCellSize); } + public static clear(){ + this._spatialHash.clear(); + } + public static overlapCircleAll(center: Vector2, randius: number, results: any[], layerMask = -1){ return this._spatialHash.overlapCircle(center, randius, results, layerMask); } diff --git a/source/src/Physics/Shapes/Polygon.ts b/source/src/Physics/Shapes/Polygon.ts index ff76c3a1..a9f7c2a2 100644 --- a/source/src/Physics/Shapes/Polygon.ts +++ b/source/src/Physics/Shapes/Polygon.ts @@ -53,10 +53,8 @@ class Polygon extends Shape { public collidesWithShape(other: Shape){ let result = new CollisionResult(); if (other instanceof Polygon){ - result = ShapeCollisions.polygonToPolygon(this, other); - return result; + return ShapeCollisions.polygonToPolygon(this, other); } - if (other instanceof Circle){ result = ShapeCollisions.circleToPolygon(other, this); diff --git a/source/src/Physics/Verlet/SpatialHash.ts b/source/src/Physics/Verlet/SpatialHash.ts index 3e49f120..141a2bab 100644 --- a/source/src/Physics/Verlet/SpatialHash.ts +++ b/source/src/Physics/Verlet/SpatialHash.ts @@ -52,6 +52,10 @@ class SpatialHash { } } + public clear(){ + this._cellDict.clear(); + } + public overlapCircle(circleCenter: Vector2, radius: number, results: Collider[], layerMask) { let bounds = new Rectangle(circleCenter.x - radius, circleCenter.y - radius, radius * 2, radius * 2); diff --git a/source/src/Utils/ContentManager.ts b/source/src/Utils/ContentManager.ts new file mode 100644 index 00000000..ba6393aa --- /dev/null +++ b/source/src/Utils/ContentManager.ts @@ -0,0 +1,41 @@ +class ContentManager { + protected loadedAssets: Map = new Map(); + + /** 异步加载资源 */ + public load(name: string, local: boolean = true): Promise { + return new Promise((resolve, reject) => { + let res = this.loadedAssets.get(name); + if (res) { + resolve(res); + return; + } + + if (local) { + RES.getResAsync(name).then((data) => { + this.loadedAssets.set(name, data); + resolve(data); + }).catch((err) => { + console.error("资源加载错误:", name, err); + reject(err); + }); + } else { + RES.getResByUrl(name).then((data) => { + this.loadedAssets.set(name, data); + resolve(data); + }).catch((err) => { + console.error("资源加载错误:", name, err); + reject(err); + }); + } + }) + } + + public dispose(){ + this.loadedAssets.forEach(value => { + let assetsToRemove = value; + assetsToRemove.dispose(); + }); + + this.loadedAssets.clear(); + } +} \ No newline at end of file diff --git a/source/src/Utils/Input.ts b/source/src/Utils/Input.ts index cbb044ec..09d961f9 100644 --- a/source/src/Utils/Input.ts +++ b/source/src/Utils/Input.ts @@ -6,7 +6,7 @@ class TouchState { public get position(){ return new Vector2(this.x, this.y); } - + public reset(){ this.x = 0; this.y = 0; @@ -26,6 +26,8 @@ class Input { private static _totalTouchCount: number = 0; /** 返回第一个触摸点的坐标 */ public static get touchPosition(){ + if (!this._gameTouchs[0]) + return Vector2.zero; return this._gameTouchs[0].position; } /** 获取最大触摸数 */ @@ -65,12 +67,12 @@ class Input { return delta; } - public static initialize(){ + public static initialize(stage: egret.Stage){ if (this._init) return; this._init = true; - this._stage = SceneManager.getActiveScene().stage; + this._stage = stage; 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);