修复Vector2.zero引起的引用混乱问题
This commit is contained in:
@@ -31,10 +31,6 @@
|
||||
"name": "framework",
|
||||
"path": "./libs/framework"
|
||||
},
|
||||
{
|
||||
"name": "long",
|
||||
"path": "./libs/long"
|
||||
},
|
||||
{
|
||||
"name": "fairygui",
|
||||
"path": "./libs/fairygui"
|
||||
|
||||
Vendored
+80
-41
@@ -103,10 +103,6 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class Vector2 {
|
||||
private static readonly unitYVector;
|
||||
private static readonly unitXVector;
|
||||
private static readonly unitVector2;
|
||||
private static readonly zeroVector2;
|
||||
x: number;
|
||||
y: number;
|
||||
constructor(x?: number, y?: number);
|
||||
@@ -202,6 +198,7 @@ declare module es {
|
||||
_nextScene: Scene;
|
||||
_sceneTransition: SceneTransition;
|
||||
_globalManagers: GlobalManager[];
|
||||
_timerManager: TimerManager;
|
||||
constructor();
|
||||
static readonly Instance: Core;
|
||||
_scene: Scene;
|
||||
@@ -210,6 +207,7 @@ declare module es {
|
||||
static registerGlobalManager(manager: es.GlobalManager): void;
|
||||
static unregisterGlobalManager(manager: es.GlobalManager): void;
|
||||
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
|
||||
static schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
||||
onOrientationChanged(): void;
|
||||
draw(): Promise<void>;
|
||||
startDebugUpdate(): void;
|
||||
@@ -376,6 +374,7 @@ declare module es {
|
||||
onDeactive(): void;
|
||||
begin(): void;
|
||||
end(): void;
|
||||
updateResolutionScaler(): void;
|
||||
update(): void;
|
||||
render(): void;
|
||||
postRender(): void;
|
||||
@@ -478,10 +477,6 @@ declare module es {
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum CameraStyle {
|
||||
lockOn = 0,
|
||||
cameraWindow = 1
|
||||
}
|
||||
class CameraInset {
|
||||
left: number;
|
||||
right: number;
|
||||
@@ -493,20 +488,11 @@ declare module es {
|
||||
_areMatrixedDirty: boolean;
|
||||
_areBoundsDirty: boolean;
|
||||
_isProjectionMatrixDirty: boolean;
|
||||
followLerp: number;
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
mapLockEnabled: boolean;
|
||||
mapSize: Rectangle;
|
||||
_targetEntity: Entity;
|
||||
_targetCollider: Collider;
|
||||
_desiredPositionDelta: Vector2;
|
||||
_cameraStyle: CameraStyle;
|
||||
_worldSpaceDeadZone: Rectangle;
|
||||
constructor(targetEntity?: Entity, cameraStyle?: CameraStyle);
|
||||
constructor();
|
||||
position: Vector2;
|
||||
rotation: number;
|
||||
_zoom: any;
|
||||
rawZoom: number;
|
||||
_zoom: number;
|
||||
zoom: number;
|
||||
_minimumZoom: number;
|
||||
minimumZoom: number;
|
||||
@@ -520,25 +506,20 @@ declare module es {
|
||||
readonly inverseTransformMatrix: Matrix2D;
|
||||
_origin: Vector2;
|
||||
origin: Vector2;
|
||||
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
||||
setInset(left: number, right: number, top: number, bottom: number): Camera;
|
||||
setPosition(position: Vector2): this;
|
||||
setRotation(rotation: number): Camera;
|
||||
setZoom(zoom: number): Camera;
|
||||
setMinimumZoom(minZoom: number): Camera;
|
||||
setMaximumZoom(maxZoom: number): Camera;
|
||||
forceMatrixUpdate(): void;
|
||||
onEntityTransformChanged(comp: transform.Component): void;
|
||||
zoomIn(deltaZoom: number): void;
|
||||
zoomOut(deltaZoom: number): void;
|
||||
worldToScreenPoint(worldPosition: Vector2): Vector2;
|
||||
screenToWorldPoint(screenPosition: Vector2): Vector2;
|
||||
onSceneRenderTargetSizeChanged(newWidth: number, newHeight: number): void;
|
||||
mouseToWorldPoint(): Vector2;
|
||||
onAddedToEntity(): void;
|
||||
update(): void;
|
||||
clampToMapSize(position: Vector2): Vector2;
|
||||
updateFollow(): void;
|
||||
follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
|
||||
setCenteredDeadzone(width: number, height: number): void;
|
||||
protected updateMatrixes(): void;
|
||||
}
|
||||
}
|
||||
@@ -561,6 +542,35 @@ declare module es {
|
||||
free(component: T): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum CameraStyle {
|
||||
lockOn = 0,
|
||||
cameraWindow = 1
|
||||
}
|
||||
class FollowCamera extends Component {
|
||||
camera: Camera;
|
||||
followLerp: number;
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
mapLockEnabled: boolean;
|
||||
mapSize: Rectangle;
|
||||
_targetEntity: Entity;
|
||||
_targetCollider: Collider;
|
||||
_desiredPositionDelta: Vector2;
|
||||
_cameraStyle: CameraStyle;
|
||||
_worldSpaceDeadZone: Rectangle;
|
||||
private rectShape;
|
||||
constructor(targetEntity?: Entity, camera?: Camera, cameraStyle?: CameraStyle);
|
||||
onAddedToEntity(): void;
|
||||
onGraphicsDeviceReset(): void;
|
||||
update(): void;
|
||||
debugRender(): void;
|
||||
clampToMapSize(position: Vector2): Vector2;
|
||||
follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
|
||||
updateFollow(): void;
|
||||
setCenteredDeadzone(width: number, height: number): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class IUpdatableComparer {
|
||||
compare(a: Component, b: Component): number;
|
||||
@@ -849,9 +859,14 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class CircleCollider extends Collider {
|
||||
private rectShape;
|
||||
private circleShape;
|
||||
private pixelShape1;
|
||||
private pixelShape2;
|
||||
constructor(radius?: number);
|
||||
radius: number;
|
||||
setRadius(radius: number): CircleCollider;
|
||||
debugRender(): void;
|
||||
toString(): string;
|
||||
}
|
||||
}
|
||||
@@ -1594,8 +1609,8 @@ declare module es {
|
||||
add(x: number, y: number, list: Collider[]): void;
|
||||
remove(obj: Collider): void;
|
||||
tryGetValue(x: number, y: number): Collider[];
|
||||
getKey(x: number, y: number): string;
|
||||
clear(): void;
|
||||
private getKey;
|
||||
}
|
||||
class RaycastResultParser {
|
||||
hitCounter: number;
|
||||
@@ -2162,17 +2177,6 @@ declare module es {
|
||||
static free<T>(obj: Array<T>): void;
|
||||
}
|
||||
}
|
||||
declare const THREAD_ID: string;
|
||||
declare const nextTick: (fn: any) => void;
|
||||
declare class LockUtils {
|
||||
private _keyX;
|
||||
private _keyY;
|
||||
private setItem;
|
||||
private getItem;
|
||||
private removeItem;
|
||||
constructor(key: any);
|
||||
lock(): Promise<{}>;
|
||||
}
|
||||
declare module es {
|
||||
class Pair<T> {
|
||||
first: T;
|
||||
@@ -2321,8 +2325,6 @@ declare module es {
|
||||
width: number;
|
||||
enabled: true;
|
||||
showLog: boolean;
|
||||
private _frameKey;
|
||||
private _logKey;
|
||||
private _logs;
|
||||
private sampleFrames;
|
||||
private _position;
|
||||
@@ -2334,6 +2336,12 @@ declare module es {
|
||||
private _markerNameToIdMap;
|
||||
private _updateCount;
|
||||
private _frameAdjust;
|
||||
private _rectShape1;
|
||||
private _rectShape2;
|
||||
private _rectShape3;
|
||||
private _rectShape4;
|
||||
private _rectShape5;
|
||||
private _rectShape6;
|
||||
constructor();
|
||||
static readonly Instance: TimeRuler;
|
||||
startFrame(): void;
|
||||
@@ -2461,3 +2469,34 @@ declare module es {
|
||||
constructor(texture: egret.Texture, id: string);
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
interface ITimer {
|
||||
context: any;
|
||||
stop(): any;
|
||||
reset(): any;
|
||||
getContext<T>(): T;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class Timer implements ITimer {
|
||||
context: any;
|
||||
_timeInSeconds: number;
|
||||
_repeats: boolean;
|
||||
_onTime: (timer: ITimer) => void;
|
||||
_isDone: boolean;
|
||||
_elapsedTime: number;
|
||||
getContext<T>(): T;
|
||||
reset(): void;
|
||||
stop(): void;
|
||||
tick(): boolean;
|
||||
initialize(timeInsSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): void;
|
||||
unload(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class TimerManager extends GlobalManager {
|
||||
_timers: Timer[];
|
||||
update(): void;
|
||||
schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
||||
}
|
||||
}
|
||||
|
||||
+378
-222
@@ -642,28 +642,28 @@ var es;
|
||||
}
|
||||
Object.defineProperty(Vector2, "zero", {
|
||||
get: function () {
|
||||
return Vector2.zeroVector2;
|
||||
return new Vector2(0, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Vector2, "one", {
|
||||
get: function () {
|
||||
return Vector2.unitVector2;
|
||||
return new Vector2(1, 1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Vector2, "unitX", {
|
||||
get: function () {
|
||||
return Vector2.unitXVector;
|
||||
return new Vector2(1, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Vector2, "unitY", {
|
||||
get: function () {
|
||||
return Vector2.unitYVector;
|
||||
return new Vector2(0, 1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -767,10 +767,6 @@ var es;
|
||||
Vector2.prototype.equals = function (other) {
|
||||
return other.x == this.x && other.y == this.y;
|
||||
};
|
||||
Vector2.unitYVector = new Vector2(0, 1);
|
||||
Vector2.unitXVector = new Vector2(1, 0);
|
||||
Vector2.unitVector2 = new Vector2(1, 1);
|
||||
Vector2.zeroVector2 = new Vector2(0, 0);
|
||||
return Vector2;
|
||||
}());
|
||||
es.Vector2 = Vector2;
|
||||
@@ -970,10 +966,12 @@ var es;
|
||||
function Core() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._globalManagers = [];
|
||||
_this._timerManager = new es.TimerManager();
|
||||
Core._instance = _this;
|
||||
Core.emitter = new es.Emitter();
|
||||
Core.content = new es.ContentManager();
|
||||
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
|
||||
Core.registerGlobalManager(_this._timerManager);
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(Core, "Instance", {
|
||||
@@ -995,8 +993,8 @@ var es;
|
||||
return;
|
||||
}
|
||||
if (this._instance._scene == null) {
|
||||
this._instance._scene = value;
|
||||
this._instance.addChild(value);
|
||||
this._instance._scene = value;
|
||||
this._instance._scene.begin();
|
||||
Core.Instance.onSceneChanged();
|
||||
}
|
||||
@@ -1030,6 +1028,11 @@ var es;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Core.schedule = function (timeInSeconds, repeats, context, onTime) {
|
||||
if (repeats === void 0) { repeats = false; }
|
||||
if (context === void 0) { context = null; }
|
||||
return this._instance._timerManager.schedule(timeInSeconds, repeats, context, onTime);
|
||||
};
|
||||
Core.prototype.onOrientationChanged = function () {
|
||||
Core.emitter.emit(es.CoreEvents.OrientationChanged);
|
||||
};
|
||||
@@ -1109,10 +1112,10 @@ var es;
|
||||
this._scene = this._nextScene;
|
||||
this._nextScene = null;
|
||||
this.onSceneChanged();
|
||||
this.addChild(this._scene);
|
||||
return [4, this._scene.begin()];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.addChild(this._scene);
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
this.endDebugUpdate();
|
||||
@@ -1682,18 +1685,25 @@ var es;
|
||||
this.addRenderer(new es.DefaultRenderer());
|
||||
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
||||
}
|
||||
this.camera = this.createEntity("camera").getOrCreateComponent(new es.Camera());
|
||||
var cameraEntity = this.findEntity("camera");
|
||||
if (!cameraEntity)
|
||||
cameraEntity = this.createEntity("camera");
|
||||
this.camera = cameraEntity.getOrCreateComponent(new es.Camera());
|
||||
es.Physics.reset();
|
||||
this.updateResolutionScaler();
|
||||
if (this.entityProcessors)
|
||||
this.entityProcessors.begin();
|
||||
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler, this);
|
||||
es.Core.emitter.addObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler, this);
|
||||
this.addEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||
this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||
this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
|
||||
this._didSceneBegin = true;
|
||||
this.onStart();
|
||||
};
|
||||
Scene.prototype.end = function () {
|
||||
this._didSceneBegin = false;
|
||||
es.Core.emitter.removeObserver(es.CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
||||
es.Core.emitter.removeObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||
for (var i = 0; i < this._renderers.length; i++) {
|
||||
@@ -1716,6 +1726,9 @@ var es;
|
||||
this.parent.removeChild(this);
|
||||
this.unload();
|
||||
};
|
||||
Scene.prototype.updateResolutionScaler = function () {
|
||||
this.camera.onSceneRenderTargetSizeChanged(es.Core.Instance.stage.stageWidth, es.Core.Instance.stage.stageHeight);
|
||||
};
|
||||
Scene.prototype.update = function () {
|
||||
this.entities.updateLists();
|
||||
for (var i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||
@@ -2234,11 +2247,6 @@ var es;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var CameraStyle;
|
||||
(function (CameraStyle) {
|
||||
CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn";
|
||||
CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow";
|
||||
})(CameraStyle = es.CameraStyle || (es.CameraStyle = {}));
|
||||
var CameraInset = (function () {
|
||||
function CameraInset() {
|
||||
this.left = 0;
|
||||
@@ -2251,29 +2259,19 @@ var es;
|
||||
es.CameraInset = CameraInset;
|
||||
var Camera = (function (_super) {
|
||||
__extends(Camera, _super);
|
||||
function Camera(targetEntity, cameraStyle) {
|
||||
if (targetEntity === void 0) { targetEntity = null; }
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; }
|
||||
function Camera() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._inset = new CameraInset();
|
||||
_this._areMatrixedDirty = true;
|
||||
_this._areBoundsDirty = true;
|
||||
_this._isProjectionMatrixDirty = true;
|
||||
_this.followLerp = 0.1;
|
||||
_this.deadzone = new es.Rectangle();
|
||||
_this.focusOffset = es.Vector2.zero;
|
||||
_this.mapLockEnabled = false;
|
||||
_this.mapSize = new es.Rectangle();
|
||||
_this._desiredPositionDelta = new es.Vector2();
|
||||
_this._worldSpaceDeadZone = new es.Rectangle();
|
||||
_this._zoom = 0;
|
||||
_this._minimumZoom = 0.3;
|
||||
_this._maximumZoom = 3;
|
||||
_this._bounds = new es.Rectangle();
|
||||
_this._transformMatrix = new es.Matrix2D().identity();
|
||||
_this._inverseTransformMatrix = new es.Matrix2D().identity();
|
||||
_this._origin = es.Vector2.zero;
|
||||
_this._targetEntity = targetEntity;
|
||||
_this._cameraStyle = cameraStyle;
|
||||
_this.setZoom(0);
|
||||
return _this;
|
||||
}
|
||||
@@ -2297,6 +2295,19 @@ var es;
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "rawZoom", {
|
||||
get: function () {
|
||||
return this._zoom;
|
||||
},
|
||||
set: function (value) {
|
||||
if (value != this._zoom) {
|
||||
this._zoom = value;
|
||||
this._areMatrixedDirty = true;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "zoom", {
|
||||
get: function () {
|
||||
if (this._zoom == 0)
|
||||
@@ -2392,11 +2403,6 @@ var es;
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) {
|
||||
var oldOrigin = this._origin;
|
||||
this.origin = new es.Vector2(newWidth / 2, newHeight / 2);
|
||||
this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin));
|
||||
};
|
||||
Camera.prototype.setInset = function (left, right, top, bottom) {
|
||||
this._inset = new CameraInset();
|
||||
this._inset.left = left;
|
||||
@@ -2448,6 +2454,9 @@ var es;
|
||||
this._maximumZoom = maxZoom;
|
||||
return this;
|
||||
};
|
||||
Camera.prototype.forceMatrixUpdate = function () {
|
||||
this._areMatrixedDirty = true;
|
||||
};
|
||||
Camera.prototype.onEntityTransformChanged = function (comp) {
|
||||
this._areMatrixedDirty = true;
|
||||
};
|
||||
@@ -2459,91 +2468,23 @@ var es;
|
||||
};
|
||||
Camera.prototype.worldToScreenPoint = function (worldPosition) {
|
||||
this.updateMatrixes();
|
||||
worldPosition = es.Vector2.transform(worldPosition, this._transformMatrix);
|
||||
worldPosition = es.Vector2Ext.transformR(worldPosition, this._transformMatrix);
|
||||
return worldPosition;
|
||||
};
|
||||
Camera.prototype.screenToWorldPoint = function (screenPosition) {
|
||||
this.updateMatrixes();
|
||||
screenPosition = es.Vector2.transform(screenPosition, this._inverseTransformMatrix);
|
||||
screenPosition = es.Vector2Ext.transformR(screenPosition, this._inverseTransformMatrix);
|
||||
return screenPosition;
|
||||
};
|
||||
Camera.prototype.onSceneRenderTargetSizeChanged = function (newWidth, newHeight) {
|
||||
this._isProjectionMatrixDirty = true;
|
||||
var oldOrigin = this._origin;
|
||||
this.origin = new es.Vector2(newWidth / 2, newHeight / 2);
|
||||
this.entity.transform.position.add(es.Vector2.subtract(this._origin, oldOrigin));
|
||||
};
|
||||
Camera.prototype.mouseToWorldPoint = function () {
|
||||
return this.screenToWorldPoint(es.Input.touchPosition);
|
||||
};
|
||||
Camera.prototype.onAddedToEntity = function () {
|
||||
this.follow(this._targetEntity, this._cameraStyle);
|
||||
};
|
||||
Camera.prototype.update = function () {
|
||||
var halfScreen = es.Vector2.multiply(this.bounds.size, new es.Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
this._worldSpaceDeadZone.height = this.deadzone.height;
|
||||
if (this._targetEntity)
|
||||
this.updateFollow();
|
||||
this.position = es.Vector2.lerp(this.position, es.Vector2.add(this.position, this._desiredPositionDelta), this.followLerp);
|
||||
this.entity.transform.roundPosition();
|
||||
if (this.mapLockEnabled) {
|
||||
this.position = this.clampToMapSize(this.position);
|
||||
this.entity.transform.roundPosition();
|
||||
}
|
||||
};
|
||||
Camera.prototype.clampToMapSize = function (position) {
|
||||
var halfScreen = es.Vector2.multiply(this.bounds.size, new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
|
||||
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||
};
|
||||
Camera.prototype.updateFollow = function () {
|
||||
this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
var targetX = this._targetEntity.transform.position.x;
|
||||
var targetY = this._targetEntity.transform.position.y;
|
||||
if (this._worldSpaceDeadZone.x > targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
else if (this._worldSpaceDeadZone.x < targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
if (this._worldSpaceDeadZone.y < targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
else if (this._worldSpaceDeadZone.y > targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
}
|
||||
else {
|
||||
if (!this._targetCollider) {
|
||||
this._targetCollider = this._targetEntity.getComponent(es.Collider);
|
||||
if (!this._targetCollider)
|
||||
return;
|
||||
}
|
||||
var targetBounds = this._targetEntity.getComponent(es.Collider).bounds;
|
||||
if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
|
||||
if (this._worldSpaceDeadZone.left > targetBounds.left)
|
||||
this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
|
||||
else if (this._worldSpaceDeadZone.right < targetBounds.right)
|
||||
this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
|
||||
if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
|
||||
this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
|
||||
else if (this._worldSpaceDeadZone.top > targetBounds.top)
|
||||
this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
|
||||
}
|
||||
}
|
||||
};
|
||||
Camera.prototype.follow = function (targetEntity, cameraStyle) {
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; }
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
switch (this._cameraStyle) {
|
||||
case CameraStyle.cameraWindow:
|
||||
var w = this.bounds.width / 6;
|
||||
var h = this.bounds.height / 3;
|
||||
this.deadzone = new es.Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h);
|
||||
break;
|
||||
case CameraStyle.lockOn:
|
||||
this.deadzone = new es.Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10);
|
||||
break;
|
||||
}
|
||||
};
|
||||
Camera.prototype.setCenteredDeadzone = function (width, height) {
|
||||
this.deadzone = new es.Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height);
|
||||
};
|
||||
Camera.prototype.updateMatrixes = function () {
|
||||
if (!this._areMatrixedDirty)
|
||||
return;
|
||||
@@ -2640,6 +2581,143 @@ var es;
|
||||
es.ComponentPool = ComponentPool;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var CameraStyle;
|
||||
(function (CameraStyle) {
|
||||
CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn";
|
||||
CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow";
|
||||
})(CameraStyle = es.CameraStyle || (es.CameraStyle = {}));
|
||||
var FollowCamera = (function (_super) {
|
||||
__extends(FollowCamera, _super);
|
||||
function FollowCamera(targetEntity, camera, cameraStyle) {
|
||||
if (targetEntity === void 0) { targetEntity = null; }
|
||||
if (camera === void 0) { camera = null; }
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.followLerp = 0.1;
|
||||
_this.deadzone = new es.Rectangle();
|
||||
_this.focusOffset = es.Vector2.zero;
|
||||
_this.mapLockEnabled = false;
|
||||
_this.mapSize = new es.Rectangle();
|
||||
_this._desiredPositionDelta = new es.Vector2();
|
||||
_this._worldSpaceDeadZone = new es.Rectangle();
|
||||
_this.rectShape = new egret.Shape();
|
||||
_this._targetEntity = targetEntity;
|
||||
_this._cameraStyle = cameraStyle;
|
||||
_this.camera = camera;
|
||||
return _this;
|
||||
}
|
||||
FollowCamera.prototype.onAddedToEntity = function () {
|
||||
if (!this.camera)
|
||||
this.camera = this.entity.scene.camera;
|
||||
this.follow(this._targetEntity, this._cameraStyle);
|
||||
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
|
||||
};
|
||||
FollowCamera.prototype.onGraphicsDeviceReset = function () {
|
||||
es.Core.schedule(0, false, this, function (t) {
|
||||
var self = t.context;
|
||||
self.follow(self._targetEntity, self._cameraStyle);
|
||||
});
|
||||
};
|
||||
FollowCamera.prototype.update = function () {
|
||||
var halfScreen = es.Vector2.multiply(this.camera.bounds.size, new es.Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.camera.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.camera.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
this._worldSpaceDeadZone.height = this.deadzone.height;
|
||||
if (this._targetEntity)
|
||||
this.updateFollow();
|
||||
this.camera.position = es.Vector2.lerp(this.camera.position, es.Vector2.add(this.camera.position, this._desiredPositionDelta), this.followLerp);
|
||||
this.entity.transform.roundPosition();
|
||||
if (this.mapLockEnabled) {
|
||||
this.camera.position = this.clampToMapSize(this.camera.position);
|
||||
this.entity.transform.roundPosition();
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.debugRender = function () {
|
||||
if (!this.rectShape)
|
||||
this.debugDisplayObject.addChild(this.rectShape);
|
||||
this.rectShape.graphics.clear();
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
this.rectShape.graphics.beginFill(0x8B0000, 0);
|
||||
this.rectShape.graphics.lineStyle(1, 0x8B0000);
|
||||
this.rectShape.graphics.drawRect(this._worldSpaceDeadZone.x - 5, this._worldSpaceDeadZone.y - 5, this._worldSpaceDeadZone.width, this._worldSpaceDeadZone.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
}
|
||||
else {
|
||||
this.rectShape.graphics.beginFill(0x8B0000, 0);
|
||||
this.rectShape.graphics.lineStyle(1, 0x8B0000);
|
||||
this.rectShape.graphics.drawRect(this._worldSpaceDeadZone.x, this._worldSpaceDeadZone.y, this._worldSpaceDeadZone.width, this._worldSpaceDeadZone.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.clampToMapSize = function (position) {
|
||||
var halfScreen = es.Vector2.multiply(this.camera.bounds.size, new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
|
||||
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||
};
|
||||
FollowCamera.prototype.follow = function (targetEntity, cameraStyle) {
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; }
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
var cameraBounds = this.camera.bounds;
|
||||
switch (this._cameraStyle) {
|
||||
case CameraStyle.cameraWindow:
|
||||
var w = cameraBounds.width / 6;
|
||||
var h = cameraBounds.height / 3;
|
||||
this.deadzone = new es.Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h);
|
||||
break;
|
||||
case CameraStyle.lockOn:
|
||||
this.deadzone = new es.Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10);
|
||||
break;
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.updateFollow = function () {
|
||||
this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
var targetX = this._targetEntity.transform.position.x;
|
||||
var targetY = this._targetEntity.transform.position.y;
|
||||
if (this._worldSpaceDeadZone.x > targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
else if (this._worldSpaceDeadZone.x < targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
if (this._worldSpaceDeadZone.y < targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
else if (this._worldSpaceDeadZone.y > targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
}
|
||||
else {
|
||||
if (!this._targetCollider) {
|
||||
this._targetCollider = this._targetEntity.getComponent(es.Collider);
|
||||
if (!this._targetCollider)
|
||||
return;
|
||||
}
|
||||
var targetBounds = this._targetEntity.getComponent(es.Collider).bounds;
|
||||
if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
|
||||
if (this._worldSpaceDeadZone.left > targetBounds.left)
|
||||
this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
|
||||
else if (this._worldSpaceDeadZone.right < targetBounds.right)
|
||||
this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
|
||||
if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
|
||||
this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
|
||||
else if (this._worldSpaceDeadZone.top > targetBounds.top)
|
||||
this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
|
||||
}
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.setCenteredDeadzone = function (width, height) {
|
||||
if (!this.camera) {
|
||||
console.error("相机是null。我们不能得到它的边界。请等到该组件添加到实体之后");
|
||||
return;
|
||||
}
|
||||
var cameraBounds = this.camera.bounds;
|
||||
this.deadzone = new es.Rectangle((cameraBounds.width - width) / 2, (cameraBounds.height - height) / 2, width, height);
|
||||
};
|
||||
return FollowCamera;
|
||||
}(es.Component));
|
||||
es.FollowCamera = FollowCamera;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var IUpdatableComparer = (function () {
|
||||
function IUpdatableComparer() {
|
||||
@@ -2750,18 +2828,12 @@ var es;
|
||||
this.debugDisplayObject.addChild(this.hollowShape);
|
||||
if (!this.pixelShape.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape);
|
||||
if (!this.entity.getComponent(es.Collider)) {
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(es.Colors.renderableBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(1, es.Colors.renderableBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
}
|
||||
var pixelPos = es.Vector2.add(this.entity.transform.position, this._localOffset);
|
||||
this.pixelShape.graphics.clear();
|
||||
this.pixelShape.graphics.beginFill(es.Colors.renderableCenter, 0);
|
||||
this.pixelShape.graphics.lineStyle(4, es.Colors.renderableCenter);
|
||||
this.pixelShape.graphics.lineTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.moveTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.endFill();
|
||||
};
|
||||
RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
|
||||
@@ -2948,10 +3020,11 @@ var es;
|
||||
};
|
||||
SpriteRenderer.prototype.render = function (camera) {
|
||||
this.sync(camera);
|
||||
if (this.displayObject.x != this.bounds.x)
|
||||
this.displayObject.x = this.bounds.x;
|
||||
if (this.displayObject.y != this.bounds.y)
|
||||
this.displayObject.y = this.bounds.y;
|
||||
var afterPos = new es.Vector2(this.entity.position.x + this.localOffset.x - this.origin.x - camera.position.x + camera.origin.x, this.entity.position.y + this.localOffset.y - this.origin.y - camera.position.y + camera.origin.y);
|
||||
if (this.displayObject.x != afterPos.x)
|
||||
this.displayObject.x = afterPos.x;
|
||||
if (this.displayObject.y != afterPos.y)
|
||||
this.displayObject.y = afterPos.y;
|
||||
};
|
||||
return SpriteRenderer;
|
||||
}(es.RenderableComponent));
|
||||
@@ -3833,17 +3906,12 @@ var es;
|
||||
this.debugDisplayObject.addChild(this.pixelShape1);
|
||||
if (!this.pixelShape2.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(es.Colors.colliderBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
this.polygonShape.graphics.clear();
|
||||
if (poly.points.length >= 2) {
|
||||
this.polygonShape.graphics.beginFill(es.Colors.colliderEdge, 0);
|
||||
this.polygonShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderEdge);
|
||||
for (var i = 1; i < poly.points.length; i++) {
|
||||
if (i == 1) {
|
||||
for (var i = 0; i < poly.points.length; i++) {
|
||||
if (i == 0) {
|
||||
this.polygonShape.graphics.moveTo(poly.position.x + poly.points[i].x, poly.position.y + poly.points[i].y);
|
||||
}
|
||||
else {
|
||||
@@ -3857,11 +3925,13 @@ var es;
|
||||
this.pixelShape1.graphics.beginFill(es.Colors.colliderPosition, 0);
|
||||
this.pixelShape1.graphics.lineStyle(4 * es.Size.lineSizeMultiplier, es.Colors.colliderPosition);
|
||||
this.pixelShape1.graphics.moveTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.lineTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.endFill();
|
||||
this.pixelShape2.graphics.clear();
|
||||
this.pixelShape2.graphics.beginFill(es.Colors.colliderCenter, 0);
|
||||
this.pixelShape2.graphics.lineStyle(2 * es.Size.lineSizeMultiplier, es.Colors.colliderCenter);
|
||||
this.pixelShape2.graphics.moveTo(this.entity.transform.position.x + this.shape.center.x, this.entity.transform.position.y + this.shape.center.y);
|
||||
this.pixelShape2.graphics.lineTo(this.entity.transform.position.x + this.shape.center.x, this.entity.transform.position.y + this.shape.center.y);
|
||||
this.pixelShape2.graphics.endFill();
|
||||
};
|
||||
BoxCollider.prototype.toString = function () {
|
||||
@@ -3877,6 +3947,10 @@ var es;
|
||||
__extends(CircleCollider, _super);
|
||||
function CircleCollider(radius) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.rectShape = new egret.Shape();
|
||||
_this.circleShape = new egret.Shape();
|
||||
_this.pixelShape1 = new egret.Shape();
|
||||
_this.pixelShape2 = new egret.Shape();
|
||||
if (radius)
|
||||
_this._colliderRequiresAutoSizing = true;
|
||||
_this.shape = new es.Circle(radius ? radius : 1);
|
||||
@@ -3903,6 +3977,38 @@ var es;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
CircleCollider.prototype.debugRender = function () {
|
||||
if (!this.rectShape.parent)
|
||||
this.debugDisplayObject.addChild(this.rectShape);
|
||||
if (!this.circleShape.parent)
|
||||
this.debugDisplayObject.addChild(this.circleShape);
|
||||
if (!this.pixelShape1.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape1);
|
||||
if (!this.pixelShape2.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||
this.rectShape.graphics.clear();
|
||||
this.rectShape.graphics.beginFill(es.Colors.colliderBounds, 0);
|
||||
this.rectShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderBounds);
|
||||
this.rectShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
this.circleShape.graphics.clear();
|
||||
this.circleShape.graphics.beginFill(es.Colors.colliderEdge, 0);
|
||||
this.circleShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderEdge);
|
||||
this.circleShape.graphics.drawCircle(this.shape.position.x, this.shape.position.y, this.shape.radius);
|
||||
this.circleShape.graphics.endFill();
|
||||
this.pixelShape1.graphics.clear();
|
||||
this.pixelShape1.graphics.beginFill(es.Colors.colliderPosition, 0);
|
||||
this.pixelShape1.graphics.lineStyle(4 * es.Size.lineSizeMultiplier, es.Colors.colliderPosition);
|
||||
this.pixelShape1.graphics.moveTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.lineTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.endFill();
|
||||
this.pixelShape2.graphics.clear();
|
||||
this.pixelShape2.graphics.beginFill(es.Colors.colliderCenter, 0);
|
||||
this.pixelShape2.graphics.lineStyle(2 * es.Size.lineSizeMultiplier, es.Colors.colliderCenter);
|
||||
this.pixelShape2.graphics.moveTo(this.shape.position.x, this.shape.position.y);
|
||||
this.pixelShape2.graphics.lineTo(this.shape.position.x, this.shape.position.y);
|
||||
this.pixelShape2.graphics.endFill();
|
||||
};
|
||||
CircleCollider.prototype.toString = function () {
|
||||
return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]";
|
||||
};
|
||||
@@ -7042,7 +7148,7 @@ var es;
|
||||
var hasUnitScale = true;
|
||||
var tempMat = void 0;
|
||||
var combinedMatrix = es.Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y);
|
||||
if (collider.entity.transform.scale != es.Vector2.zero) {
|
||||
if (collider.entity.transform.scale != es.Vector2.one) {
|
||||
tempMat = es.Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y);
|
||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||
hasUnitScale = false;
|
||||
@@ -7054,7 +7160,7 @@ var es;
|
||||
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg;
|
||||
var offsetLength = hasUnitScale ? collider._localOffsetLength :
|
||||
es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
||||
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle);
|
||||
}
|
||||
tempMat = es.Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y);
|
||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||
@@ -7065,7 +7171,7 @@ var es;
|
||||
}
|
||||
this.position = es.Vector2.add(collider.entity.transform.position, this.center);
|
||||
this.bounds = es.Rectangle.rectEncompassingPoints(this.points);
|
||||
this.bounds.location = this.bounds.location.add(this.position);
|
||||
this.bounds.location.add(this.position);
|
||||
};
|
||||
Polygon.prototype.overlaps = function (other) {
|
||||
var result = new es.CollisionResult();
|
||||
@@ -7097,7 +7203,7 @@ var es;
|
||||
return es.ShapeCollisions.lineToPoly(start, end, this, hit);
|
||||
};
|
||||
Polygon.prototype.containsPoint = function (point) {
|
||||
point = es.Vector2.subtract(point, this.position);
|
||||
point.subtract(this.position);
|
||||
var isInside = false;
|
||||
for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
|
||||
if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) &&
|
||||
@@ -7780,12 +7886,12 @@ var es;
|
||||
NumberDictionary.prototype.tryGetValue = function (x, y) {
|
||||
return this._store.get(this.getKey(x, y));
|
||||
};
|
||||
NumberDictionary.prototype.getKey = function (x, y) {
|
||||
return x + "_" + y;
|
||||
};
|
||||
NumberDictionary.prototype.clear = function () {
|
||||
this._store.clear();
|
||||
};
|
||||
NumberDictionary.prototype.getKey = function (x, y) {
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
|
||||
};
|
||||
return NumberDictionary;
|
||||
}());
|
||||
es.NumberDictionary = NumberDictionary;
|
||||
@@ -10177,47 +10283,6 @@ var es;
|
||||
}());
|
||||
es.ListPool = ListPool;
|
||||
})(es || (es = {}));
|
||||
var THREAD_ID = Math.floor(Math.random() * 1000) + "-" + Date.now();
|
||||
var nextTick = function (fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
var LockUtils = (function () {
|
||||
function LockUtils(key) {
|
||||
this._keyX = "mutex_key_" + key + "_X";
|
||||
this._keyY = "mutex_key_" + key + "_Y";
|
||||
this.setItem = egret.localStorage.setItem.bind(localStorage);
|
||||
this.getItem = egret.localStorage.getItem.bind(localStorage);
|
||||
this.removeItem = egret.localStorage.removeItem.bind(localStorage);
|
||||
}
|
||||
LockUtils.prototype.lock = function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var fn = function () {
|
||||
_this.setItem(_this._keyX, THREAD_ID);
|
||||
if (!_this.getItem(_this._keyY) === null) {
|
||||
nextTick(fn);
|
||||
}
|
||||
_this.setItem(_this._keyY, THREAD_ID);
|
||||
if (_this.getItem(_this._keyX) !== THREAD_ID) {
|
||||
setTimeout(function () {
|
||||
if (_this.getItem(_this._keyY) !== THREAD_ID) {
|
||||
nextTick(fn);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
_this.removeItem(_this._keyY);
|
||||
}, 10);
|
||||
}
|
||||
else {
|
||||
resolve();
|
||||
_this.removeItem(_this._keyY);
|
||||
}
|
||||
};
|
||||
fn();
|
||||
});
|
||||
};
|
||||
return LockUtils;
|
||||
}());
|
||||
var es;
|
||||
(function (es) {
|
||||
var Pair = (function () {
|
||||
@@ -10748,11 +10813,15 @@ var es;
|
||||
var TimeRuler = (function () {
|
||||
function TimeRuler() {
|
||||
this.showLog = false;
|
||||
this._frameKey = 'frame';
|
||||
this._logKey = 'log';
|
||||
this.markers = [];
|
||||
this.stopwacth = new stopwatch.Stopwatch();
|
||||
this._markerNameToIdMap = new Map();
|
||||
this._rectShape1 = new egret.Shape();
|
||||
this._rectShape2 = new egret.Shape();
|
||||
this._rectShape3 = new egret.Shape();
|
||||
this._rectShape4 = new egret.Shape();
|
||||
this._rectShape5 = new egret.Shape();
|
||||
this._rectShape6 = new egret.Shape();
|
||||
this._logs = new Array(2);
|
||||
for (var i = 0; i < this._logs.length; ++i)
|
||||
this._logs[i] = new FrameLog();
|
||||
@@ -10771,23 +10840,18 @@ var es;
|
||||
configurable: true
|
||||
});
|
||||
TimeRuler.prototype.startFrame = function () {
|
||||
var _this = this;
|
||||
var lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(function () {
|
||||
_this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10);
|
||||
if (isNaN(_this._updateCount))
|
||||
_this._updateCount = 0;
|
||||
var count = _this._updateCount;
|
||||
if (isNaN(this._updateCount))
|
||||
this._updateCount = 0;
|
||||
var count = this._updateCount;
|
||||
count += 1;
|
||||
egret.localStorage.setItem(_this._frameKey, count.toString());
|
||||
if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames))
|
||||
if (this.enabled && (1 < count && count < TimeRuler.maxSampleFrames))
|
||||
return;
|
||||
_this._prevLog = _this._logs[_this.frameCount++ & 0x1];
|
||||
_this._curLog = _this._logs[_this.frameCount & 0x1];
|
||||
var endFrameTime = _this.stopwacth.getTime();
|
||||
for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) {
|
||||
var prevBar = _this._prevLog.bars[barIndex];
|
||||
var nextBar = _this._curLog.bars[barIndex];
|
||||
this._prevLog = this._logs[this.frameCount++ & 0x1];
|
||||
this._curLog = this._logs[this.frameCount & 0x1];
|
||||
var endFrameTime = this.stopwacth.getTime();
|
||||
for (var barIndex = 0; barIndex < this._prevLog.bars.length; ++barIndex) {
|
||||
var prevBar = this._prevLog.bars[barIndex];
|
||||
var nextBar = this._curLog.bars[barIndex];
|
||||
for (var nest = 0; nest < prevBar.nestCount; ++nest) {
|
||||
var markerIdx = prevBar.markerNests[nest];
|
||||
prevBar.markers[markerIdx].endTime = endFrameTime;
|
||||
@@ -10800,7 +10864,7 @@ var es;
|
||||
for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) {
|
||||
var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime;
|
||||
var markerId = prevBar.markers[markerIdx].markerId;
|
||||
var m = _this.markers[markerId];
|
||||
var m = this.markers[markerId];
|
||||
m.logs[barIndex].color = prevBar.markers[markerIdx].color;
|
||||
if (!m.logs[barIndex].initialized) {
|
||||
m.logs[barIndex].min = duration;
|
||||
@@ -10824,48 +10888,40 @@ var es;
|
||||
nextBar.markCount = prevBar.nestCount;
|
||||
nextBar.nestCount = prevBar.nestCount;
|
||||
}
|
||||
_this.stopwacth.reset();
|
||||
_this.stopwacth.start();
|
||||
});
|
||||
this.stopwacth.reset();
|
||||
this.stopwacth.start();
|
||||
};
|
||||
TimeRuler.prototype.beginMark = function (markerName, color, barIndex) {
|
||||
var _this = this;
|
||||
if (barIndex === void 0) { barIndex = 0; }
|
||||
var lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(function () {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
|
||||
throw new Error("barIndex argument out of range");
|
||||
var bar = _this._curLog.bars[barIndex];
|
||||
var bar = this._curLog.bars[barIndex];
|
||||
if (bar.markCount >= TimeRuler.maxSamples) {
|
||||
throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");
|
||||
}
|
||||
if (bar.nestCount >= TimeRuler.maxNestCall) {
|
||||
throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");
|
||||
}
|
||||
var markerId = _this._markerNameToIdMap.get(markerName);
|
||||
var markerId = this._markerNameToIdMap.get(markerName);
|
||||
if (isNaN(markerId)) {
|
||||
markerId = _this.markers.length;
|
||||
_this._markerNameToIdMap.set(markerName, markerId);
|
||||
markerId = this.markers.length;
|
||||
this._markerNameToIdMap.set(markerName, markerId);
|
||||
}
|
||||
bar.markerNests[bar.nestCount++] = bar.markCount;
|
||||
bar.markers[bar.markCount].markerId = markerId;
|
||||
bar.markers[bar.markCount].color = color;
|
||||
bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime();
|
||||
bar.markers[bar.markCount].beginTime = this.stopwacth.getTime();
|
||||
bar.markers[bar.markCount].endTime = -1;
|
||||
});
|
||||
};
|
||||
TimeRuler.prototype.endMark = function (markerName, barIndex) {
|
||||
var _this = this;
|
||||
if (barIndex === void 0) { barIndex = 0; }
|
||||
var lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(function () {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
|
||||
throw new Error("barIndex argument out of range");
|
||||
var bar = _this._curLog.bars[barIndex];
|
||||
var bar = this._curLog.bars[barIndex];
|
||||
if (bar.nestCount <= 0) {
|
||||
throw new Error("call beginMark method before calling endMark method");
|
||||
}
|
||||
var markerId = _this._markerNameToIdMap.get(markerName);
|
||||
var markerId = this._markerNameToIdMap.get(markerName);
|
||||
if (isNaN(markerId)) {
|
||||
throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method");
|
||||
}
|
||||
@@ -10873,8 +10929,7 @@ var es;
|
||||
if (bar.markers[markerIdx].markerId != markerId) {
|
||||
throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");
|
||||
}
|
||||
bar.markers[markerIdx].endTime = _this.stopwacth.getTime();
|
||||
});
|
||||
bar.markers[markerIdx].endTime = this.stopwacth.getTime();
|
||||
};
|
||||
TimeRuler.prototype.getAverageTime = function (barIndex, markerName) {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars) {
|
||||
@@ -10888,13 +10943,7 @@ var es;
|
||||
return result;
|
||||
};
|
||||
TimeRuler.prototype.resetLog = function () {
|
||||
var _this = this;
|
||||
var lock = new LockUtils(this._logKey);
|
||||
lock.lock().then(function () {
|
||||
var count = parseInt(egret.localStorage.getItem(_this._logKey), 10);
|
||||
count += 1;
|
||||
egret.localStorage.setItem(_this._logKey, count.toString());
|
||||
_this.markers.forEach(function (markerInfo) {
|
||||
this.markers.forEach(function (markerInfo) {
|
||||
for (var i = 0; i < markerInfo.logs.length; ++i) {
|
||||
markerInfo.logs[i].initialized = false;
|
||||
markerInfo.logs[i].snapMin = 0;
|
||||
@@ -10906,12 +10955,10 @@ var es;
|
||||
markerInfo.logs[i].samples = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
TimeRuler.prototype.render = function (position, width) {
|
||||
if (position === void 0) { position = this._position; }
|
||||
if (width === void 0) { width = this.width; }
|
||||
egret.localStorage.setItem(this._frameKey, "0");
|
||||
if (!this.showLog)
|
||||
return;
|
||||
var height = 0;
|
||||
@@ -10938,6 +10985,46 @@ var es;
|
||||
var msToPs = width / sampleSpan;
|
||||
var startY = position.y - (height - TimeRuler.barHeight);
|
||||
var y = startY;
|
||||
var rc = new es.Rectangle(position.x, y, width, height);
|
||||
this._rectShape1.graphics.clear();
|
||||
this._rectShape1.graphics.beginFill(0x000000, 128 / 255);
|
||||
this._rectShape1.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape1.graphics.endFill();
|
||||
rc.height = TimeRuler.barHeight;
|
||||
this._rectShape2.graphics.clear();
|
||||
for (var _i = 0, _a = this._prevLog.bars; _i < _a.length; _i++) {
|
||||
var bar = _a[_i];
|
||||
rc.y = y + TimeRuler.barPadding;
|
||||
if (bar.markCount > 0) {
|
||||
for (var j = 0; j < bar.markCount; ++j) {
|
||||
var bt = bar.markers[j].beginTime;
|
||||
var et = bar.markers[j].endTime;
|
||||
var sx = Math.floor(position.x + bt * msToPs);
|
||||
var ex = Math.floor(position.x + et * msToPs);
|
||||
rc.x = sx;
|
||||
rc.width = Math.max(ex - sx, 1);
|
||||
this._rectShape2.graphics.beginFill(bar.markers[j].color);
|
||||
this._rectShape2.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape2.graphics.endFill();
|
||||
}
|
||||
}
|
||||
y += TimeRuler.barHeight + TimeRuler.barPadding;
|
||||
}
|
||||
rc = new es.Rectangle(position.x, startY, 1, height);
|
||||
this._rectShape3.graphics.clear();
|
||||
for (var t = 1; t < sampleSpan; t += 1) {
|
||||
rc.x = Math.floor(position.x + t * msToPs);
|
||||
this._rectShape3.graphics.beginFill(0x808080);
|
||||
this._rectShape3.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape3.graphics.endFill();
|
||||
}
|
||||
this._rectShape4.graphics.clear();
|
||||
for (var i = 0; i <= this.sampleFrames; ++i) {
|
||||
rc.x = Math.floor(position.x + frameSpan * i * msToPs);
|
||||
this._rectShape4.graphics.beginFill(0xFFFFFF);
|
||||
this._rectShape4.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape4.graphics.endFill();
|
||||
}
|
||||
};
|
||||
TimeRuler.prototype.onGraphicsDeviceReset = function () {
|
||||
var layout = new es.Layout();
|
||||
@@ -11447,3 +11534,72 @@ var es;
|
||||
}());
|
||||
es.TextureToPack = TextureToPack;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Timer = (function () {
|
||||
function Timer() {
|
||||
this._timeInSeconds = 0;
|
||||
this._repeats = false;
|
||||
this._isDone = false;
|
||||
this._elapsedTime = 0;
|
||||
}
|
||||
Timer.prototype.getContext = function () {
|
||||
return this.context;
|
||||
};
|
||||
Timer.prototype.reset = function () {
|
||||
this._elapsedTime = 0;
|
||||
};
|
||||
Timer.prototype.stop = function () {
|
||||
this._isDone = true;
|
||||
};
|
||||
Timer.prototype.tick = function () {
|
||||
if (!this._isDone && this._elapsedTime > this._timeInSeconds) {
|
||||
this._elapsedTime -= this._timeInSeconds;
|
||||
this._onTime(this);
|
||||
if (!this._isDone && !this._repeats)
|
||||
this._isDone = true;
|
||||
}
|
||||
this._elapsedTime += es.Time.deltaTime;
|
||||
return this._isDone;
|
||||
};
|
||||
Timer.prototype.initialize = function (timeInsSeconds, repeats, context, onTime) {
|
||||
this._timeInSeconds = timeInsSeconds;
|
||||
this._repeats = repeats;
|
||||
this.context = context;
|
||||
this._onTime = onTime;
|
||||
};
|
||||
Timer.prototype.unload = function () {
|
||||
this.context = null;
|
||||
this._onTime = null;
|
||||
};
|
||||
return Timer;
|
||||
}());
|
||||
es.Timer = Timer;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var TimerManager = (function (_super) {
|
||||
__extends(TimerManager, _super);
|
||||
function TimerManager() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this._timers = [];
|
||||
return _this;
|
||||
}
|
||||
TimerManager.prototype.update = function () {
|
||||
for (var i = this._timers.length - 1; i >= 0; i--) {
|
||||
if (this._timers[i].tick()) {
|
||||
this._timers[i].unload();
|
||||
this._timers.removeAt(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
TimerManager.prototype.schedule = function (timeInSeconds, repeats, context, onTime) {
|
||||
var timer = new es.Timer();
|
||||
timer.initialize(timeInSeconds, repeats, context, onTime);
|
||||
this._timers.push(timer);
|
||||
return timer;
|
||||
};
|
||||
return TimerManager;
|
||||
}(es.GlobalManager));
|
||||
es.TimerManager = TimerManager;
|
||||
})(es || (es = {}));
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
-1092
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Vendored
-1
File diff suppressed because one or more lines are too long
+3
-3
@@ -9,16 +9,15 @@
|
||||
"libs/modules/promise/promise.js",
|
||||
"libs/modules/dragonBones/dragonBones.js",
|
||||
"libs/framework/framework.js",
|
||||
"libs/long/long.js",
|
||||
"libs/fairygui/fairygui.js"
|
||||
],
|
||||
"game": [
|
||||
"bin-debug/Fgui/common/commonBinder.js",
|
||||
"bin-debug/UI/mvc/BaseView.js",
|
||||
"bin-debug/SampleHelpers/SampleScene.js",
|
||||
"bin-debug/Scenes/Ninja Adventure/ProjectileHitDetector.js",
|
||||
"bin-debug/UI/loading/LoadingView.js",
|
||||
"bin-debug/Scenes/LineCasting/LineCastingScene.js",
|
||||
"bin-debug/Fgui/common/UI_com_tips.js",
|
||||
"bin-debug/Fgui/loading/loadingBinder.js",
|
||||
"bin-debug/Fgui/loading/UI_View_loading.js",
|
||||
"bin-debug/Fgui/sc/scBinder.js",
|
||||
@@ -32,11 +31,12 @@
|
||||
"bin-debug/Main.js",
|
||||
"bin-debug/Scenes/Ninja Adventure/Ninja.js",
|
||||
"bin-debug/Scenes/Ninja Adventure/NinjaAdventureScene.js",
|
||||
"bin-debug/ThemeAdapter.js",
|
||||
"bin-debug/UI/PopManager.js",
|
||||
"bin-debug/UI/loading/LoadingControl.js",
|
||||
"bin-debug/UI/loading/LoadingEvents.js",
|
||||
"bin-debug/ThemeAdapter.js",
|
||||
"bin-debug/AssetAdapter.js",
|
||||
"bin-debug/Fgui/common/UI_com_tips.js",
|
||||
"bin-debug/UI/mvc/EventManager.js",
|
||||
"bin-debug/UI/mvc/Extension.js",
|
||||
"bin-debug/UI/mvc/FguiUtils.js",
|
||||
|
||||
@@ -5,7 +5,6 @@ module samples {
|
||||
|
||||
export class SampleScene extends es.Scene {
|
||||
public static readonly screenSpaceRenderLayer = 999;
|
||||
public canvas: SpriteRenderer;
|
||||
|
||||
public static _needsFullRender: boolean;
|
||||
public _screenSpaceRenderer: ScreenSpaceRenderer;
|
||||
@@ -23,13 +22,6 @@ module samples {
|
||||
|
||||
if (addExcludeRenderer)
|
||||
this.addRenderer(new RenderLayerExcludeRenderer(0, SampleScene.screenSpaceRenderLayer));
|
||||
|
||||
this.canvas = this.createEntity("ui").addComponent(new SpriteRenderer());
|
||||
this.canvas.renderLayer = SampleScene.screenSpaceRenderLayer;
|
||||
this.setupSceneSelector();
|
||||
}
|
||||
|
||||
public setupSceneSelector(){
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ module samples {
|
||||
private _pixelShape2: egret.Shape;
|
||||
private _lineShape: egret.Shape;
|
||||
private _pixelShape3: egret.Shape;
|
||||
private _delayTime = 1;
|
||||
private _delayTime = 0.2;
|
||||
private _pressTime = 0;
|
||||
private _canTouch = true;
|
||||
|
||||
|
||||
@@ -2,14 +2,12 @@ module samples {
|
||||
import CircleCollider = es.CircleCollider;
|
||||
import Flags = es.Flags;
|
||||
import SpriteRenderer = es.SpriteRenderer;
|
||||
import ProjectileHitDetector = es.ProjectileHitDetector;
|
||||
import FollowCamera = es.FollowCamera;
|
||||
|
||||
export class NinjaAdventureScene extends SampleScene {
|
||||
constructor() {
|
||||
super(true, true);
|
||||
}
|
||||
|
||||
public initialize(): void {
|
||||
super.initialize();
|
||||
public async onStart() {
|
||||
super.onStart();
|
||||
|
||||
let playerEntity = this.createEntity("player");
|
||||
playerEntity.position = new es.Vector2(256, 224);
|
||||
@@ -21,12 +19,22 @@ module samples {
|
||||
// 移动到第1层 保证自己的图层不会如果增加攻击方式则不会攻击到自身
|
||||
Flags.setFlagExclusive(collider.physicsLayer, 1);
|
||||
|
||||
this.camera.entity.addComponent(new FollowCamera(playerEntity));
|
||||
|
||||
this.content.loadRes("moon_png").then(moonTexture => {
|
||||
let moonEntity = this.createEntity("moon");
|
||||
moonEntity.position = new es.Vector2(412, 460);
|
||||
moonEntity.addComponent(new SpriteRenderer(moonTexture));
|
||||
moonEntity.addComponent(new ProjectileHitDetector());
|
||||
moonEntity.addComponent(new CircleCollider());
|
||||
});
|
||||
}
|
||||
|
||||
public update(){
|
||||
super.update();
|
||||
|
||||
this.findEntity("player").position.x -= es.Time.deltaTime * 10;
|
||||
this.findEntity("player").position.y -= es.Time.deltaTime * 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
module es {
|
||||
/**
|
||||
* 简单的组件,可以检测它是否被弹丸击中。当被击中时,它会闪烁并在被击中一定次数后自我毁灭。
|
||||
*/
|
||||
export class ProjectileHitDetector extends Component implements ITriggerListener{
|
||||
public hitsUntilDead: number = 10;
|
||||
public _hitCounter: number;
|
||||
public _sprite: SpriteRenderer;
|
||||
|
||||
public onAddedToEntity(): void {
|
||||
this._sprite = this.entity.getComponent<SpriteRenderer>(SpriteRenderer);
|
||||
}
|
||||
|
||||
public onTriggerEnter(other: es.Collider, local: es.Collider): any {
|
||||
this._hitCounter ++;
|
||||
if (this.hitsUntilDead >= this.hitsUntilDead){
|
||||
this.entity.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
this._sprite.color = 0xFF0000;
|
||||
Core.schedule(0.1, false, this, timer => {
|
||||
this._sprite.color = 0x000000;
|
||||
});
|
||||
}
|
||||
|
||||
public onTriggerExit(other: es.Collider, local: es.Collider): any {
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+80
-41
@@ -103,10 +103,6 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class Vector2 {
|
||||
private static readonly unitYVector;
|
||||
private static readonly unitXVector;
|
||||
private static readonly unitVector2;
|
||||
private static readonly zeroVector2;
|
||||
x: number;
|
||||
y: number;
|
||||
constructor(x?: number, y?: number);
|
||||
@@ -202,6 +198,7 @@ declare module es {
|
||||
_nextScene: Scene;
|
||||
_sceneTransition: SceneTransition;
|
||||
_globalManagers: GlobalManager[];
|
||||
_timerManager: TimerManager;
|
||||
constructor();
|
||||
static readonly Instance: Core;
|
||||
_scene: Scene;
|
||||
@@ -210,6 +207,7 @@ declare module es {
|
||||
static registerGlobalManager(manager: es.GlobalManager): void;
|
||||
static unregisterGlobalManager(manager: es.GlobalManager): void;
|
||||
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
|
||||
static schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
||||
onOrientationChanged(): void;
|
||||
draw(): Promise<void>;
|
||||
startDebugUpdate(): void;
|
||||
@@ -376,6 +374,7 @@ declare module es {
|
||||
onDeactive(): void;
|
||||
begin(): void;
|
||||
end(): void;
|
||||
updateResolutionScaler(): void;
|
||||
update(): void;
|
||||
render(): void;
|
||||
postRender(): void;
|
||||
@@ -478,10 +477,6 @@ declare module es {
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum CameraStyle {
|
||||
lockOn = 0,
|
||||
cameraWindow = 1
|
||||
}
|
||||
class CameraInset {
|
||||
left: number;
|
||||
right: number;
|
||||
@@ -493,20 +488,11 @@ declare module es {
|
||||
_areMatrixedDirty: boolean;
|
||||
_areBoundsDirty: boolean;
|
||||
_isProjectionMatrixDirty: boolean;
|
||||
followLerp: number;
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
mapLockEnabled: boolean;
|
||||
mapSize: Rectangle;
|
||||
_targetEntity: Entity;
|
||||
_targetCollider: Collider;
|
||||
_desiredPositionDelta: Vector2;
|
||||
_cameraStyle: CameraStyle;
|
||||
_worldSpaceDeadZone: Rectangle;
|
||||
constructor(targetEntity?: Entity, cameraStyle?: CameraStyle);
|
||||
constructor();
|
||||
position: Vector2;
|
||||
rotation: number;
|
||||
_zoom: any;
|
||||
rawZoom: number;
|
||||
_zoom: number;
|
||||
zoom: number;
|
||||
_minimumZoom: number;
|
||||
minimumZoom: number;
|
||||
@@ -520,25 +506,20 @@ declare module es {
|
||||
readonly inverseTransformMatrix: Matrix2D;
|
||||
_origin: Vector2;
|
||||
origin: Vector2;
|
||||
onSceneSizeChanged(newWidth: number, newHeight: number): void;
|
||||
setInset(left: number, right: number, top: number, bottom: number): Camera;
|
||||
setPosition(position: Vector2): this;
|
||||
setRotation(rotation: number): Camera;
|
||||
setZoom(zoom: number): Camera;
|
||||
setMinimumZoom(minZoom: number): Camera;
|
||||
setMaximumZoom(maxZoom: number): Camera;
|
||||
forceMatrixUpdate(): void;
|
||||
onEntityTransformChanged(comp: transform.Component): void;
|
||||
zoomIn(deltaZoom: number): void;
|
||||
zoomOut(deltaZoom: number): void;
|
||||
worldToScreenPoint(worldPosition: Vector2): Vector2;
|
||||
screenToWorldPoint(screenPosition: Vector2): Vector2;
|
||||
onSceneRenderTargetSizeChanged(newWidth: number, newHeight: number): void;
|
||||
mouseToWorldPoint(): Vector2;
|
||||
onAddedToEntity(): void;
|
||||
update(): void;
|
||||
clampToMapSize(position: Vector2): Vector2;
|
||||
updateFollow(): void;
|
||||
follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
|
||||
setCenteredDeadzone(width: number, height: number): void;
|
||||
protected updateMatrixes(): void;
|
||||
}
|
||||
}
|
||||
@@ -561,6 +542,35 @@ declare module es {
|
||||
free(component: T): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
enum CameraStyle {
|
||||
lockOn = 0,
|
||||
cameraWindow = 1
|
||||
}
|
||||
class FollowCamera extends Component {
|
||||
camera: Camera;
|
||||
followLerp: number;
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
mapLockEnabled: boolean;
|
||||
mapSize: Rectangle;
|
||||
_targetEntity: Entity;
|
||||
_targetCollider: Collider;
|
||||
_desiredPositionDelta: Vector2;
|
||||
_cameraStyle: CameraStyle;
|
||||
_worldSpaceDeadZone: Rectangle;
|
||||
private rectShape;
|
||||
constructor(targetEntity?: Entity, camera?: Camera, cameraStyle?: CameraStyle);
|
||||
onAddedToEntity(): void;
|
||||
onGraphicsDeviceReset(): void;
|
||||
update(): void;
|
||||
debugRender(): void;
|
||||
clampToMapSize(position: Vector2): Vector2;
|
||||
follow(targetEntity: Entity, cameraStyle?: CameraStyle): void;
|
||||
updateFollow(): void;
|
||||
setCenteredDeadzone(width: number, height: number): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class IUpdatableComparer {
|
||||
compare(a: Component, b: Component): number;
|
||||
@@ -849,9 +859,14 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class CircleCollider extends Collider {
|
||||
private rectShape;
|
||||
private circleShape;
|
||||
private pixelShape1;
|
||||
private pixelShape2;
|
||||
constructor(radius?: number);
|
||||
radius: number;
|
||||
setRadius(radius: number): CircleCollider;
|
||||
debugRender(): void;
|
||||
toString(): string;
|
||||
}
|
||||
}
|
||||
@@ -1594,8 +1609,8 @@ declare module es {
|
||||
add(x: number, y: number, list: Collider[]): void;
|
||||
remove(obj: Collider): void;
|
||||
tryGetValue(x: number, y: number): Collider[];
|
||||
getKey(x: number, y: number): string;
|
||||
clear(): void;
|
||||
private getKey;
|
||||
}
|
||||
class RaycastResultParser {
|
||||
hitCounter: number;
|
||||
@@ -2162,17 +2177,6 @@ declare module es {
|
||||
static free<T>(obj: Array<T>): void;
|
||||
}
|
||||
}
|
||||
declare const THREAD_ID: string;
|
||||
declare const nextTick: (fn: any) => void;
|
||||
declare class LockUtils {
|
||||
private _keyX;
|
||||
private _keyY;
|
||||
private setItem;
|
||||
private getItem;
|
||||
private removeItem;
|
||||
constructor(key: any);
|
||||
lock(): Promise<{}>;
|
||||
}
|
||||
declare module es {
|
||||
class Pair<T> {
|
||||
first: T;
|
||||
@@ -2321,8 +2325,6 @@ declare module es {
|
||||
width: number;
|
||||
enabled: true;
|
||||
showLog: boolean;
|
||||
private _frameKey;
|
||||
private _logKey;
|
||||
private _logs;
|
||||
private sampleFrames;
|
||||
private _position;
|
||||
@@ -2334,6 +2336,12 @@ declare module es {
|
||||
private _markerNameToIdMap;
|
||||
private _updateCount;
|
||||
private _frameAdjust;
|
||||
private _rectShape1;
|
||||
private _rectShape2;
|
||||
private _rectShape3;
|
||||
private _rectShape4;
|
||||
private _rectShape5;
|
||||
private _rectShape6;
|
||||
constructor();
|
||||
static readonly Instance: TimeRuler;
|
||||
startFrame(): void;
|
||||
@@ -2461,3 +2469,34 @@ declare module es {
|
||||
constructor(texture: egret.Texture, id: string);
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
interface ITimer {
|
||||
context: any;
|
||||
stop(): any;
|
||||
reset(): any;
|
||||
getContext<T>(): T;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class Timer implements ITimer {
|
||||
context: any;
|
||||
_timeInSeconds: number;
|
||||
_repeats: boolean;
|
||||
_onTime: (timer: ITimer) => void;
|
||||
_isDone: boolean;
|
||||
_elapsedTime: number;
|
||||
getContext<T>(): T;
|
||||
reset(): void;
|
||||
stop(): void;
|
||||
tick(): boolean;
|
||||
initialize(timeInsSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): void;
|
||||
unload(): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
class TimerManager extends GlobalManager {
|
||||
_timers: Timer[];
|
||||
update(): void;
|
||||
schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer) => void): Timer;
|
||||
}
|
||||
}
|
||||
|
||||
+378
-222
@@ -642,28 +642,28 @@ var es;
|
||||
}
|
||||
Object.defineProperty(Vector2, "zero", {
|
||||
get: function () {
|
||||
return Vector2.zeroVector2;
|
||||
return new Vector2(0, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Vector2, "one", {
|
||||
get: function () {
|
||||
return Vector2.unitVector2;
|
||||
return new Vector2(1, 1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Vector2, "unitX", {
|
||||
get: function () {
|
||||
return Vector2.unitXVector;
|
||||
return new Vector2(1, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Vector2, "unitY", {
|
||||
get: function () {
|
||||
return Vector2.unitYVector;
|
||||
return new Vector2(0, 1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -767,10 +767,6 @@ var es;
|
||||
Vector2.prototype.equals = function (other) {
|
||||
return other.x == this.x && other.y == this.y;
|
||||
};
|
||||
Vector2.unitYVector = new Vector2(0, 1);
|
||||
Vector2.unitXVector = new Vector2(1, 0);
|
||||
Vector2.unitVector2 = new Vector2(1, 1);
|
||||
Vector2.zeroVector2 = new Vector2(0, 0);
|
||||
return Vector2;
|
||||
}());
|
||||
es.Vector2 = Vector2;
|
||||
@@ -970,10 +966,12 @@ var es;
|
||||
function Core() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._globalManagers = [];
|
||||
_this._timerManager = new es.TimerManager();
|
||||
Core._instance = _this;
|
||||
Core.emitter = new es.Emitter();
|
||||
Core.content = new es.ContentManager();
|
||||
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
|
||||
Core.registerGlobalManager(_this._timerManager);
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(Core, "Instance", {
|
||||
@@ -995,8 +993,8 @@ var es;
|
||||
return;
|
||||
}
|
||||
if (this._instance._scene == null) {
|
||||
this._instance._scene = value;
|
||||
this._instance.addChild(value);
|
||||
this._instance._scene = value;
|
||||
this._instance._scene.begin();
|
||||
Core.Instance.onSceneChanged();
|
||||
}
|
||||
@@ -1030,6 +1028,11 @@ var es;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Core.schedule = function (timeInSeconds, repeats, context, onTime) {
|
||||
if (repeats === void 0) { repeats = false; }
|
||||
if (context === void 0) { context = null; }
|
||||
return this._instance._timerManager.schedule(timeInSeconds, repeats, context, onTime);
|
||||
};
|
||||
Core.prototype.onOrientationChanged = function () {
|
||||
Core.emitter.emit(es.CoreEvents.OrientationChanged);
|
||||
};
|
||||
@@ -1109,10 +1112,10 @@ var es;
|
||||
this._scene = this._nextScene;
|
||||
this._nextScene = null;
|
||||
this.onSceneChanged();
|
||||
this.addChild(this._scene);
|
||||
return [4, this._scene.begin()];
|
||||
case 1:
|
||||
_a.sent();
|
||||
this.addChild(this._scene);
|
||||
_a.label = 2;
|
||||
case 2:
|
||||
this.endDebugUpdate();
|
||||
@@ -1682,18 +1685,25 @@ var es;
|
||||
this.addRenderer(new es.DefaultRenderer());
|
||||
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
||||
}
|
||||
this.camera = this.createEntity("camera").getOrCreateComponent(new es.Camera());
|
||||
var cameraEntity = this.findEntity("camera");
|
||||
if (!cameraEntity)
|
||||
cameraEntity = this.createEntity("camera");
|
||||
this.camera = cameraEntity.getOrCreateComponent(new es.Camera());
|
||||
es.Physics.reset();
|
||||
this.updateResolutionScaler();
|
||||
if (this.entityProcessors)
|
||||
this.entityProcessors.begin();
|
||||
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler, this);
|
||||
es.Core.emitter.addObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler, this);
|
||||
this.addEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||
this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||
this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
|
||||
this._didSceneBegin = true;
|
||||
this.onStart();
|
||||
};
|
||||
Scene.prototype.end = function () {
|
||||
this._didSceneBegin = false;
|
||||
es.Core.emitter.removeObserver(es.CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
||||
es.Core.emitter.removeObserver(es.CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||
for (var i = 0; i < this._renderers.length; i++) {
|
||||
@@ -1716,6 +1726,9 @@ var es;
|
||||
this.parent.removeChild(this);
|
||||
this.unload();
|
||||
};
|
||||
Scene.prototype.updateResolutionScaler = function () {
|
||||
this.camera.onSceneRenderTargetSizeChanged(es.Core.Instance.stage.stageWidth, es.Core.Instance.stage.stageHeight);
|
||||
};
|
||||
Scene.prototype.update = function () {
|
||||
this.entities.updateLists();
|
||||
for (var i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||
@@ -2234,11 +2247,6 @@ var es;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var CameraStyle;
|
||||
(function (CameraStyle) {
|
||||
CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn";
|
||||
CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow";
|
||||
})(CameraStyle = es.CameraStyle || (es.CameraStyle = {}));
|
||||
var CameraInset = (function () {
|
||||
function CameraInset() {
|
||||
this.left = 0;
|
||||
@@ -2251,29 +2259,19 @@ var es;
|
||||
es.CameraInset = CameraInset;
|
||||
var Camera = (function (_super) {
|
||||
__extends(Camera, _super);
|
||||
function Camera(targetEntity, cameraStyle) {
|
||||
if (targetEntity === void 0) { targetEntity = null; }
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; }
|
||||
function Camera() {
|
||||
var _this = _super.call(this) || this;
|
||||
_this._inset = new CameraInset();
|
||||
_this._areMatrixedDirty = true;
|
||||
_this._areBoundsDirty = true;
|
||||
_this._isProjectionMatrixDirty = true;
|
||||
_this.followLerp = 0.1;
|
||||
_this.deadzone = new es.Rectangle();
|
||||
_this.focusOffset = es.Vector2.zero;
|
||||
_this.mapLockEnabled = false;
|
||||
_this.mapSize = new es.Rectangle();
|
||||
_this._desiredPositionDelta = new es.Vector2();
|
||||
_this._worldSpaceDeadZone = new es.Rectangle();
|
||||
_this._zoom = 0;
|
||||
_this._minimumZoom = 0.3;
|
||||
_this._maximumZoom = 3;
|
||||
_this._bounds = new es.Rectangle();
|
||||
_this._transformMatrix = new es.Matrix2D().identity();
|
||||
_this._inverseTransformMatrix = new es.Matrix2D().identity();
|
||||
_this._origin = es.Vector2.zero;
|
||||
_this._targetEntity = targetEntity;
|
||||
_this._cameraStyle = cameraStyle;
|
||||
_this.setZoom(0);
|
||||
return _this;
|
||||
}
|
||||
@@ -2297,6 +2295,19 @@ var es;
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "rawZoom", {
|
||||
get: function () {
|
||||
return this._zoom;
|
||||
},
|
||||
set: function (value) {
|
||||
if (value != this._zoom) {
|
||||
this._zoom = value;
|
||||
this._areMatrixedDirty = true;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "zoom", {
|
||||
get: function () {
|
||||
if (this._zoom == 0)
|
||||
@@ -2392,11 +2403,6 @@ var es;
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Camera.prototype.onSceneSizeChanged = function (newWidth, newHeight) {
|
||||
var oldOrigin = this._origin;
|
||||
this.origin = new es.Vector2(newWidth / 2, newHeight / 2);
|
||||
this.entity.transform.position = es.Vector2.add(this.entity.transform.position, es.Vector2.subtract(this._origin, oldOrigin));
|
||||
};
|
||||
Camera.prototype.setInset = function (left, right, top, bottom) {
|
||||
this._inset = new CameraInset();
|
||||
this._inset.left = left;
|
||||
@@ -2448,6 +2454,9 @@ var es;
|
||||
this._maximumZoom = maxZoom;
|
||||
return this;
|
||||
};
|
||||
Camera.prototype.forceMatrixUpdate = function () {
|
||||
this._areMatrixedDirty = true;
|
||||
};
|
||||
Camera.prototype.onEntityTransformChanged = function (comp) {
|
||||
this._areMatrixedDirty = true;
|
||||
};
|
||||
@@ -2459,91 +2468,23 @@ var es;
|
||||
};
|
||||
Camera.prototype.worldToScreenPoint = function (worldPosition) {
|
||||
this.updateMatrixes();
|
||||
worldPosition = es.Vector2.transform(worldPosition, this._transformMatrix);
|
||||
worldPosition = es.Vector2Ext.transformR(worldPosition, this._transformMatrix);
|
||||
return worldPosition;
|
||||
};
|
||||
Camera.prototype.screenToWorldPoint = function (screenPosition) {
|
||||
this.updateMatrixes();
|
||||
screenPosition = es.Vector2.transform(screenPosition, this._inverseTransformMatrix);
|
||||
screenPosition = es.Vector2Ext.transformR(screenPosition, this._inverseTransformMatrix);
|
||||
return screenPosition;
|
||||
};
|
||||
Camera.prototype.onSceneRenderTargetSizeChanged = function (newWidth, newHeight) {
|
||||
this._isProjectionMatrixDirty = true;
|
||||
var oldOrigin = this._origin;
|
||||
this.origin = new es.Vector2(newWidth / 2, newHeight / 2);
|
||||
this.entity.transform.position.add(es.Vector2.subtract(this._origin, oldOrigin));
|
||||
};
|
||||
Camera.prototype.mouseToWorldPoint = function () {
|
||||
return this.screenToWorldPoint(es.Input.touchPosition);
|
||||
};
|
||||
Camera.prototype.onAddedToEntity = function () {
|
||||
this.follow(this._targetEntity, this._cameraStyle);
|
||||
};
|
||||
Camera.prototype.update = function () {
|
||||
var halfScreen = es.Vector2.multiply(this.bounds.size, new es.Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
this._worldSpaceDeadZone.height = this.deadzone.height;
|
||||
if (this._targetEntity)
|
||||
this.updateFollow();
|
||||
this.position = es.Vector2.lerp(this.position, es.Vector2.add(this.position, this._desiredPositionDelta), this.followLerp);
|
||||
this.entity.transform.roundPosition();
|
||||
if (this.mapLockEnabled) {
|
||||
this.position = this.clampToMapSize(this.position);
|
||||
this.entity.transform.roundPosition();
|
||||
}
|
||||
};
|
||||
Camera.prototype.clampToMapSize = function (position) {
|
||||
var halfScreen = es.Vector2.multiply(this.bounds.size, new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
|
||||
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||
};
|
||||
Camera.prototype.updateFollow = function () {
|
||||
this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
var targetX = this._targetEntity.transform.position.x;
|
||||
var targetY = this._targetEntity.transform.position.y;
|
||||
if (this._worldSpaceDeadZone.x > targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
else if (this._worldSpaceDeadZone.x < targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
if (this._worldSpaceDeadZone.y < targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
else if (this._worldSpaceDeadZone.y > targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
}
|
||||
else {
|
||||
if (!this._targetCollider) {
|
||||
this._targetCollider = this._targetEntity.getComponent(es.Collider);
|
||||
if (!this._targetCollider)
|
||||
return;
|
||||
}
|
||||
var targetBounds = this._targetEntity.getComponent(es.Collider).bounds;
|
||||
if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
|
||||
if (this._worldSpaceDeadZone.left > targetBounds.left)
|
||||
this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
|
||||
else if (this._worldSpaceDeadZone.right < targetBounds.right)
|
||||
this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
|
||||
if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
|
||||
this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
|
||||
else if (this._worldSpaceDeadZone.top > targetBounds.top)
|
||||
this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
|
||||
}
|
||||
}
|
||||
};
|
||||
Camera.prototype.follow = function (targetEntity, cameraStyle) {
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; }
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
switch (this._cameraStyle) {
|
||||
case CameraStyle.cameraWindow:
|
||||
var w = this.bounds.width / 6;
|
||||
var h = this.bounds.height / 3;
|
||||
this.deadzone = new es.Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h);
|
||||
break;
|
||||
case CameraStyle.lockOn:
|
||||
this.deadzone = new es.Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10);
|
||||
break;
|
||||
}
|
||||
};
|
||||
Camera.prototype.setCenteredDeadzone = function (width, height) {
|
||||
this.deadzone = new es.Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height);
|
||||
};
|
||||
Camera.prototype.updateMatrixes = function () {
|
||||
if (!this._areMatrixedDirty)
|
||||
return;
|
||||
@@ -2640,6 +2581,143 @@ var es;
|
||||
es.ComponentPool = ComponentPool;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var CameraStyle;
|
||||
(function (CameraStyle) {
|
||||
CameraStyle[CameraStyle["lockOn"] = 0] = "lockOn";
|
||||
CameraStyle[CameraStyle["cameraWindow"] = 1] = "cameraWindow";
|
||||
})(CameraStyle = es.CameraStyle || (es.CameraStyle = {}));
|
||||
var FollowCamera = (function (_super) {
|
||||
__extends(FollowCamera, _super);
|
||||
function FollowCamera(targetEntity, camera, cameraStyle) {
|
||||
if (targetEntity === void 0) { targetEntity = null; }
|
||||
if (camera === void 0) { camera = null; }
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.lockOn; }
|
||||
var _this = _super.call(this) || this;
|
||||
_this.followLerp = 0.1;
|
||||
_this.deadzone = new es.Rectangle();
|
||||
_this.focusOffset = es.Vector2.zero;
|
||||
_this.mapLockEnabled = false;
|
||||
_this.mapSize = new es.Rectangle();
|
||||
_this._desiredPositionDelta = new es.Vector2();
|
||||
_this._worldSpaceDeadZone = new es.Rectangle();
|
||||
_this.rectShape = new egret.Shape();
|
||||
_this._targetEntity = targetEntity;
|
||||
_this._cameraStyle = cameraStyle;
|
||||
_this.camera = camera;
|
||||
return _this;
|
||||
}
|
||||
FollowCamera.prototype.onAddedToEntity = function () {
|
||||
if (!this.camera)
|
||||
this.camera = this.entity.scene.camera;
|
||||
this.follow(this._targetEntity, this._cameraStyle);
|
||||
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
|
||||
};
|
||||
FollowCamera.prototype.onGraphicsDeviceReset = function () {
|
||||
es.Core.schedule(0, false, this, function (t) {
|
||||
var self = t.context;
|
||||
self.follow(self._targetEntity, self._cameraStyle);
|
||||
});
|
||||
};
|
||||
FollowCamera.prototype.update = function () {
|
||||
var halfScreen = es.Vector2.multiply(this.camera.bounds.size, new es.Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.camera.position.x - halfScreen.x * es.Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.camera.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
this._worldSpaceDeadZone.height = this.deadzone.height;
|
||||
if (this._targetEntity)
|
||||
this.updateFollow();
|
||||
this.camera.position = es.Vector2.lerp(this.camera.position, es.Vector2.add(this.camera.position, this._desiredPositionDelta), this.followLerp);
|
||||
this.entity.transform.roundPosition();
|
||||
if (this.mapLockEnabled) {
|
||||
this.camera.position = this.clampToMapSize(this.camera.position);
|
||||
this.entity.transform.roundPosition();
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.debugRender = function () {
|
||||
if (!this.rectShape)
|
||||
this.debugDisplayObject.addChild(this.rectShape);
|
||||
this.rectShape.graphics.clear();
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
this.rectShape.graphics.beginFill(0x8B0000, 0);
|
||||
this.rectShape.graphics.lineStyle(1, 0x8B0000);
|
||||
this.rectShape.graphics.drawRect(this._worldSpaceDeadZone.x - 5, this._worldSpaceDeadZone.y - 5, this._worldSpaceDeadZone.width, this._worldSpaceDeadZone.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
}
|
||||
else {
|
||||
this.rectShape.graphics.beginFill(0x8B0000, 0);
|
||||
this.rectShape.graphics.lineStyle(1, 0x8B0000);
|
||||
this.rectShape.graphics.drawRect(this._worldSpaceDeadZone.x, this._worldSpaceDeadZone.y, this._worldSpaceDeadZone.width, this._worldSpaceDeadZone.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.clampToMapSize = function (position) {
|
||||
var halfScreen = es.Vector2.multiply(this.camera.bounds.size, new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
|
||||
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||
};
|
||||
FollowCamera.prototype.follow = function (targetEntity, cameraStyle) {
|
||||
if (cameraStyle === void 0) { cameraStyle = CameraStyle.cameraWindow; }
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
var cameraBounds = this.camera.bounds;
|
||||
switch (this._cameraStyle) {
|
||||
case CameraStyle.cameraWindow:
|
||||
var w = cameraBounds.width / 6;
|
||||
var h = cameraBounds.height / 3;
|
||||
this.deadzone = new es.Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h);
|
||||
break;
|
||||
case CameraStyle.lockOn:
|
||||
this.deadzone = new es.Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10);
|
||||
break;
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.updateFollow = function () {
|
||||
this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
var targetX = this._targetEntity.transform.position.x;
|
||||
var targetY = this._targetEntity.transform.position.y;
|
||||
if (this._worldSpaceDeadZone.x > targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
else if (this._worldSpaceDeadZone.x < targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
if (this._worldSpaceDeadZone.y < targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
else if (this._worldSpaceDeadZone.y > targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
}
|
||||
else {
|
||||
if (!this._targetCollider) {
|
||||
this._targetCollider = this._targetEntity.getComponent(es.Collider);
|
||||
if (!this._targetCollider)
|
||||
return;
|
||||
}
|
||||
var targetBounds = this._targetEntity.getComponent(es.Collider).bounds;
|
||||
if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
|
||||
if (this._worldSpaceDeadZone.left > targetBounds.left)
|
||||
this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
|
||||
else if (this._worldSpaceDeadZone.right < targetBounds.right)
|
||||
this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
|
||||
if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
|
||||
this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
|
||||
else if (this._worldSpaceDeadZone.top > targetBounds.top)
|
||||
this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
|
||||
}
|
||||
}
|
||||
};
|
||||
FollowCamera.prototype.setCenteredDeadzone = function (width, height) {
|
||||
if (!this.camera) {
|
||||
console.error("相机是null。我们不能得到它的边界。请等到该组件添加到实体之后");
|
||||
return;
|
||||
}
|
||||
var cameraBounds = this.camera.bounds;
|
||||
this.deadzone = new es.Rectangle((cameraBounds.width - width) / 2, (cameraBounds.height - height) / 2, width, height);
|
||||
};
|
||||
return FollowCamera;
|
||||
}(es.Component));
|
||||
es.FollowCamera = FollowCamera;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var IUpdatableComparer = (function () {
|
||||
function IUpdatableComparer() {
|
||||
@@ -2750,18 +2828,12 @@ var es;
|
||||
this.debugDisplayObject.addChild(this.hollowShape);
|
||||
if (!this.pixelShape.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape);
|
||||
if (!this.entity.getComponent(es.Collider)) {
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(es.Colors.renderableBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(1, es.Colors.renderableBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
}
|
||||
var pixelPos = es.Vector2.add(this.entity.transform.position, this._localOffset);
|
||||
this.pixelShape.graphics.clear();
|
||||
this.pixelShape.graphics.beginFill(es.Colors.renderableCenter, 0);
|
||||
this.pixelShape.graphics.lineStyle(4, es.Colors.renderableCenter);
|
||||
this.pixelShape.graphics.lineTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.moveTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.endFill();
|
||||
};
|
||||
RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
|
||||
@@ -2948,10 +3020,11 @@ var es;
|
||||
};
|
||||
SpriteRenderer.prototype.render = function (camera) {
|
||||
this.sync(camera);
|
||||
if (this.displayObject.x != this.bounds.x)
|
||||
this.displayObject.x = this.bounds.x;
|
||||
if (this.displayObject.y != this.bounds.y)
|
||||
this.displayObject.y = this.bounds.y;
|
||||
var afterPos = new es.Vector2(this.entity.position.x + this.localOffset.x - this.origin.x - camera.position.x + camera.origin.x, this.entity.position.y + this.localOffset.y - this.origin.y - camera.position.y + camera.origin.y);
|
||||
if (this.displayObject.x != afterPos.x)
|
||||
this.displayObject.x = afterPos.x;
|
||||
if (this.displayObject.y != afterPos.y)
|
||||
this.displayObject.y = afterPos.y;
|
||||
};
|
||||
return SpriteRenderer;
|
||||
}(es.RenderableComponent));
|
||||
@@ -3833,17 +3906,12 @@ var es;
|
||||
this.debugDisplayObject.addChild(this.pixelShape1);
|
||||
if (!this.pixelShape2.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(es.Colors.colliderBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
this.polygonShape.graphics.clear();
|
||||
if (poly.points.length >= 2) {
|
||||
this.polygonShape.graphics.beginFill(es.Colors.colliderEdge, 0);
|
||||
this.polygonShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderEdge);
|
||||
for (var i = 1; i < poly.points.length; i++) {
|
||||
if (i == 1) {
|
||||
for (var i = 0; i < poly.points.length; i++) {
|
||||
if (i == 0) {
|
||||
this.polygonShape.graphics.moveTo(poly.position.x + poly.points[i].x, poly.position.y + poly.points[i].y);
|
||||
}
|
||||
else {
|
||||
@@ -3857,11 +3925,13 @@ var es;
|
||||
this.pixelShape1.graphics.beginFill(es.Colors.colliderPosition, 0);
|
||||
this.pixelShape1.graphics.lineStyle(4 * es.Size.lineSizeMultiplier, es.Colors.colliderPosition);
|
||||
this.pixelShape1.graphics.moveTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.lineTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.endFill();
|
||||
this.pixelShape2.graphics.clear();
|
||||
this.pixelShape2.graphics.beginFill(es.Colors.colliderCenter, 0);
|
||||
this.pixelShape2.graphics.lineStyle(2 * es.Size.lineSizeMultiplier, es.Colors.colliderCenter);
|
||||
this.pixelShape2.graphics.moveTo(this.entity.transform.position.x + this.shape.center.x, this.entity.transform.position.y + this.shape.center.y);
|
||||
this.pixelShape2.graphics.lineTo(this.entity.transform.position.x + this.shape.center.x, this.entity.transform.position.y + this.shape.center.y);
|
||||
this.pixelShape2.graphics.endFill();
|
||||
};
|
||||
BoxCollider.prototype.toString = function () {
|
||||
@@ -3877,6 +3947,10 @@ var es;
|
||||
__extends(CircleCollider, _super);
|
||||
function CircleCollider(radius) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.rectShape = new egret.Shape();
|
||||
_this.circleShape = new egret.Shape();
|
||||
_this.pixelShape1 = new egret.Shape();
|
||||
_this.pixelShape2 = new egret.Shape();
|
||||
if (radius)
|
||||
_this._colliderRequiresAutoSizing = true;
|
||||
_this.shape = new es.Circle(radius ? radius : 1);
|
||||
@@ -3903,6 +3977,38 @@ var es;
|
||||
}
|
||||
return this;
|
||||
};
|
||||
CircleCollider.prototype.debugRender = function () {
|
||||
if (!this.rectShape.parent)
|
||||
this.debugDisplayObject.addChild(this.rectShape);
|
||||
if (!this.circleShape.parent)
|
||||
this.debugDisplayObject.addChild(this.circleShape);
|
||||
if (!this.pixelShape1.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape1);
|
||||
if (!this.pixelShape2.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||
this.rectShape.graphics.clear();
|
||||
this.rectShape.graphics.beginFill(es.Colors.colliderBounds, 0);
|
||||
this.rectShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderBounds);
|
||||
this.rectShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
this.circleShape.graphics.clear();
|
||||
this.circleShape.graphics.beginFill(es.Colors.colliderEdge, 0);
|
||||
this.circleShape.graphics.lineStyle(es.Size.lineSizeMultiplier, es.Colors.colliderEdge);
|
||||
this.circleShape.graphics.drawCircle(this.shape.position.x, this.shape.position.y, this.shape.radius);
|
||||
this.circleShape.graphics.endFill();
|
||||
this.pixelShape1.graphics.clear();
|
||||
this.pixelShape1.graphics.beginFill(es.Colors.colliderPosition, 0);
|
||||
this.pixelShape1.graphics.lineStyle(4 * es.Size.lineSizeMultiplier, es.Colors.colliderPosition);
|
||||
this.pixelShape1.graphics.moveTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.lineTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.endFill();
|
||||
this.pixelShape2.graphics.clear();
|
||||
this.pixelShape2.graphics.beginFill(es.Colors.colliderCenter, 0);
|
||||
this.pixelShape2.graphics.lineStyle(2 * es.Size.lineSizeMultiplier, es.Colors.colliderCenter);
|
||||
this.pixelShape2.graphics.moveTo(this.shape.position.x, this.shape.position.y);
|
||||
this.pixelShape2.graphics.lineTo(this.shape.position.x, this.shape.position.y);
|
||||
this.pixelShape2.graphics.endFill();
|
||||
};
|
||||
CircleCollider.prototype.toString = function () {
|
||||
return "[CircleCollider: bounds: " + this.bounds + ", radius: " + this.shape.radius + "]";
|
||||
};
|
||||
@@ -7042,7 +7148,7 @@ var es;
|
||||
var hasUnitScale = true;
|
||||
var tempMat = void 0;
|
||||
var combinedMatrix = es.Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y);
|
||||
if (collider.entity.transform.scale != es.Vector2.zero) {
|
||||
if (collider.entity.transform.scale != es.Vector2.one) {
|
||||
tempMat = es.Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y);
|
||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||
hasUnitScale = false;
|
||||
@@ -7054,7 +7160,7 @@ var es;
|
||||
var offsetAngle = Math.atan2(collider.localOffset.y, collider.localOffset.x) * es.MathHelper.Rad2Deg;
|
||||
var offsetLength = hasUnitScale ? collider._localOffsetLength :
|
||||
es.Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotation + offsetAngle);
|
||||
this.center = es.MathHelper.pointOnCirlce(es.Vector2.zero, offsetLength, collider.entity.transform.rotationDegrees + offsetAngle);
|
||||
}
|
||||
tempMat = es.Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y);
|
||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||
@@ -7065,7 +7171,7 @@ var es;
|
||||
}
|
||||
this.position = es.Vector2.add(collider.entity.transform.position, this.center);
|
||||
this.bounds = es.Rectangle.rectEncompassingPoints(this.points);
|
||||
this.bounds.location = this.bounds.location.add(this.position);
|
||||
this.bounds.location.add(this.position);
|
||||
};
|
||||
Polygon.prototype.overlaps = function (other) {
|
||||
var result = new es.CollisionResult();
|
||||
@@ -7097,7 +7203,7 @@ var es;
|
||||
return es.ShapeCollisions.lineToPoly(start, end, this, hit);
|
||||
};
|
||||
Polygon.prototype.containsPoint = function (point) {
|
||||
point = es.Vector2.subtract(point, this.position);
|
||||
point.subtract(this.position);
|
||||
var isInside = false;
|
||||
for (var i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
|
||||
if (((this.points[i].y > point.y) != (this.points[j].y > point.y)) &&
|
||||
@@ -7780,12 +7886,12 @@ var es;
|
||||
NumberDictionary.prototype.tryGetValue = function (x, y) {
|
||||
return this._store.get(this.getKey(x, y));
|
||||
};
|
||||
NumberDictionary.prototype.getKey = function (x, y) {
|
||||
return x + "_" + y;
|
||||
};
|
||||
NumberDictionary.prototype.clear = function () {
|
||||
this._store.clear();
|
||||
};
|
||||
NumberDictionary.prototype.getKey = function (x, y) {
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
|
||||
};
|
||||
return NumberDictionary;
|
||||
}());
|
||||
es.NumberDictionary = NumberDictionary;
|
||||
@@ -10177,47 +10283,6 @@ var es;
|
||||
}());
|
||||
es.ListPool = ListPool;
|
||||
})(es || (es = {}));
|
||||
var THREAD_ID = Math.floor(Math.random() * 1000) + "-" + Date.now();
|
||||
var nextTick = function (fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
var LockUtils = (function () {
|
||||
function LockUtils(key) {
|
||||
this._keyX = "mutex_key_" + key + "_X";
|
||||
this._keyY = "mutex_key_" + key + "_Y";
|
||||
this.setItem = egret.localStorage.setItem.bind(localStorage);
|
||||
this.getItem = egret.localStorage.getItem.bind(localStorage);
|
||||
this.removeItem = egret.localStorage.removeItem.bind(localStorage);
|
||||
}
|
||||
LockUtils.prototype.lock = function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var fn = function () {
|
||||
_this.setItem(_this._keyX, THREAD_ID);
|
||||
if (!_this.getItem(_this._keyY) === null) {
|
||||
nextTick(fn);
|
||||
}
|
||||
_this.setItem(_this._keyY, THREAD_ID);
|
||||
if (_this.getItem(_this._keyX) !== THREAD_ID) {
|
||||
setTimeout(function () {
|
||||
if (_this.getItem(_this._keyY) !== THREAD_ID) {
|
||||
nextTick(fn);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
_this.removeItem(_this._keyY);
|
||||
}, 10);
|
||||
}
|
||||
else {
|
||||
resolve();
|
||||
_this.removeItem(_this._keyY);
|
||||
}
|
||||
};
|
||||
fn();
|
||||
});
|
||||
};
|
||||
return LockUtils;
|
||||
}());
|
||||
var es;
|
||||
(function (es) {
|
||||
var Pair = (function () {
|
||||
@@ -10748,11 +10813,15 @@ var es;
|
||||
var TimeRuler = (function () {
|
||||
function TimeRuler() {
|
||||
this.showLog = false;
|
||||
this._frameKey = 'frame';
|
||||
this._logKey = 'log';
|
||||
this.markers = [];
|
||||
this.stopwacth = new stopwatch.Stopwatch();
|
||||
this._markerNameToIdMap = new Map();
|
||||
this._rectShape1 = new egret.Shape();
|
||||
this._rectShape2 = new egret.Shape();
|
||||
this._rectShape3 = new egret.Shape();
|
||||
this._rectShape4 = new egret.Shape();
|
||||
this._rectShape5 = new egret.Shape();
|
||||
this._rectShape6 = new egret.Shape();
|
||||
this._logs = new Array(2);
|
||||
for (var i = 0; i < this._logs.length; ++i)
|
||||
this._logs[i] = new FrameLog();
|
||||
@@ -10771,23 +10840,18 @@ var es;
|
||||
configurable: true
|
||||
});
|
||||
TimeRuler.prototype.startFrame = function () {
|
||||
var _this = this;
|
||||
var lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(function () {
|
||||
_this._updateCount = parseInt(egret.localStorage.getItem(_this._frameKey), 10);
|
||||
if (isNaN(_this._updateCount))
|
||||
_this._updateCount = 0;
|
||||
var count = _this._updateCount;
|
||||
if (isNaN(this._updateCount))
|
||||
this._updateCount = 0;
|
||||
var count = this._updateCount;
|
||||
count += 1;
|
||||
egret.localStorage.setItem(_this._frameKey, count.toString());
|
||||
if (_this.enabled && (1 < count && count < TimeRuler.maxSampleFrames))
|
||||
if (this.enabled && (1 < count && count < TimeRuler.maxSampleFrames))
|
||||
return;
|
||||
_this._prevLog = _this._logs[_this.frameCount++ & 0x1];
|
||||
_this._curLog = _this._logs[_this.frameCount & 0x1];
|
||||
var endFrameTime = _this.stopwacth.getTime();
|
||||
for (var barIndex = 0; barIndex < _this._prevLog.bars.length; ++barIndex) {
|
||||
var prevBar = _this._prevLog.bars[barIndex];
|
||||
var nextBar = _this._curLog.bars[barIndex];
|
||||
this._prevLog = this._logs[this.frameCount++ & 0x1];
|
||||
this._curLog = this._logs[this.frameCount & 0x1];
|
||||
var endFrameTime = this.stopwacth.getTime();
|
||||
for (var barIndex = 0; barIndex < this._prevLog.bars.length; ++barIndex) {
|
||||
var prevBar = this._prevLog.bars[barIndex];
|
||||
var nextBar = this._curLog.bars[barIndex];
|
||||
for (var nest = 0; nest < prevBar.nestCount; ++nest) {
|
||||
var markerIdx = prevBar.markerNests[nest];
|
||||
prevBar.markers[markerIdx].endTime = endFrameTime;
|
||||
@@ -10800,7 +10864,7 @@ var es;
|
||||
for (var markerIdx = 0; markerIdx < prevBar.markCount; ++markerIdx) {
|
||||
var duration = prevBar.markers[markerIdx].endTime - prevBar.markers[markerIdx].beginTime;
|
||||
var markerId = prevBar.markers[markerIdx].markerId;
|
||||
var m = _this.markers[markerId];
|
||||
var m = this.markers[markerId];
|
||||
m.logs[barIndex].color = prevBar.markers[markerIdx].color;
|
||||
if (!m.logs[barIndex].initialized) {
|
||||
m.logs[barIndex].min = duration;
|
||||
@@ -10824,48 +10888,40 @@ var es;
|
||||
nextBar.markCount = prevBar.nestCount;
|
||||
nextBar.nestCount = prevBar.nestCount;
|
||||
}
|
||||
_this.stopwacth.reset();
|
||||
_this.stopwacth.start();
|
||||
});
|
||||
this.stopwacth.reset();
|
||||
this.stopwacth.start();
|
||||
};
|
||||
TimeRuler.prototype.beginMark = function (markerName, color, barIndex) {
|
||||
var _this = this;
|
||||
if (barIndex === void 0) { barIndex = 0; }
|
||||
var lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(function () {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
|
||||
throw new Error("barIndex argument out of range");
|
||||
var bar = _this._curLog.bars[barIndex];
|
||||
var bar = this._curLog.bars[barIndex];
|
||||
if (bar.markCount >= TimeRuler.maxSamples) {
|
||||
throw new Error("exceeded sample count. either set larger number to timeruler.maxsaple or lower sample count");
|
||||
}
|
||||
if (bar.nestCount >= TimeRuler.maxNestCall) {
|
||||
throw new Error("exceeded nest count. either set larger number to timeruler.maxnestcall or lower nest calls");
|
||||
}
|
||||
var markerId = _this._markerNameToIdMap.get(markerName);
|
||||
var markerId = this._markerNameToIdMap.get(markerName);
|
||||
if (isNaN(markerId)) {
|
||||
markerId = _this.markers.length;
|
||||
_this._markerNameToIdMap.set(markerName, markerId);
|
||||
markerId = this.markers.length;
|
||||
this._markerNameToIdMap.set(markerName, markerId);
|
||||
}
|
||||
bar.markerNests[bar.nestCount++] = bar.markCount;
|
||||
bar.markers[bar.markCount].markerId = markerId;
|
||||
bar.markers[bar.markCount].color = color;
|
||||
bar.markers[bar.markCount].beginTime = _this.stopwacth.getTime();
|
||||
bar.markers[bar.markCount].beginTime = this.stopwacth.getTime();
|
||||
bar.markers[bar.markCount].endTime = -1;
|
||||
});
|
||||
};
|
||||
TimeRuler.prototype.endMark = function (markerName, barIndex) {
|
||||
var _this = this;
|
||||
if (barIndex === void 0) { barIndex = 0; }
|
||||
var lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(function () {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
|
||||
throw new Error("barIndex argument out of range");
|
||||
var bar = _this._curLog.bars[barIndex];
|
||||
var bar = this._curLog.bars[barIndex];
|
||||
if (bar.nestCount <= 0) {
|
||||
throw new Error("call beginMark method before calling endMark method");
|
||||
}
|
||||
var markerId = _this._markerNameToIdMap.get(markerName);
|
||||
var markerId = this._markerNameToIdMap.get(markerName);
|
||||
if (isNaN(markerId)) {
|
||||
throw new Error("Marker " + markerName + " is not registered. Make sure you specifed same name as you used for beginMark method");
|
||||
}
|
||||
@@ -10873,8 +10929,7 @@ var es;
|
||||
if (bar.markers[markerIdx].markerId != markerId) {
|
||||
throw new Error("Incorrect call order of beginMark/endMark method. beginMark(A), beginMark(B), endMark(B), endMark(A) But you can't called it like beginMark(A), beginMark(B), endMark(A), endMark(B).");
|
||||
}
|
||||
bar.markers[markerIdx].endTime = _this.stopwacth.getTime();
|
||||
});
|
||||
bar.markers[markerIdx].endTime = this.stopwacth.getTime();
|
||||
};
|
||||
TimeRuler.prototype.getAverageTime = function (barIndex, markerName) {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars) {
|
||||
@@ -10888,13 +10943,7 @@ var es;
|
||||
return result;
|
||||
};
|
||||
TimeRuler.prototype.resetLog = function () {
|
||||
var _this = this;
|
||||
var lock = new LockUtils(this._logKey);
|
||||
lock.lock().then(function () {
|
||||
var count = parseInt(egret.localStorage.getItem(_this._logKey), 10);
|
||||
count += 1;
|
||||
egret.localStorage.setItem(_this._logKey, count.toString());
|
||||
_this.markers.forEach(function (markerInfo) {
|
||||
this.markers.forEach(function (markerInfo) {
|
||||
for (var i = 0; i < markerInfo.logs.length; ++i) {
|
||||
markerInfo.logs[i].initialized = false;
|
||||
markerInfo.logs[i].snapMin = 0;
|
||||
@@ -10906,12 +10955,10 @@ var es;
|
||||
markerInfo.logs[i].samples = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
TimeRuler.prototype.render = function (position, width) {
|
||||
if (position === void 0) { position = this._position; }
|
||||
if (width === void 0) { width = this.width; }
|
||||
egret.localStorage.setItem(this._frameKey, "0");
|
||||
if (!this.showLog)
|
||||
return;
|
||||
var height = 0;
|
||||
@@ -10938,6 +10985,46 @@ var es;
|
||||
var msToPs = width / sampleSpan;
|
||||
var startY = position.y - (height - TimeRuler.barHeight);
|
||||
var y = startY;
|
||||
var rc = new es.Rectangle(position.x, y, width, height);
|
||||
this._rectShape1.graphics.clear();
|
||||
this._rectShape1.graphics.beginFill(0x000000, 128 / 255);
|
||||
this._rectShape1.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape1.graphics.endFill();
|
||||
rc.height = TimeRuler.barHeight;
|
||||
this._rectShape2.graphics.clear();
|
||||
for (var _i = 0, _a = this._prevLog.bars; _i < _a.length; _i++) {
|
||||
var bar = _a[_i];
|
||||
rc.y = y + TimeRuler.barPadding;
|
||||
if (bar.markCount > 0) {
|
||||
for (var j = 0; j < bar.markCount; ++j) {
|
||||
var bt = bar.markers[j].beginTime;
|
||||
var et = bar.markers[j].endTime;
|
||||
var sx = Math.floor(position.x + bt * msToPs);
|
||||
var ex = Math.floor(position.x + et * msToPs);
|
||||
rc.x = sx;
|
||||
rc.width = Math.max(ex - sx, 1);
|
||||
this._rectShape2.graphics.beginFill(bar.markers[j].color);
|
||||
this._rectShape2.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape2.graphics.endFill();
|
||||
}
|
||||
}
|
||||
y += TimeRuler.barHeight + TimeRuler.barPadding;
|
||||
}
|
||||
rc = new es.Rectangle(position.x, startY, 1, height);
|
||||
this._rectShape3.graphics.clear();
|
||||
for (var t = 1; t < sampleSpan; t += 1) {
|
||||
rc.x = Math.floor(position.x + t * msToPs);
|
||||
this._rectShape3.graphics.beginFill(0x808080);
|
||||
this._rectShape3.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape3.graphics.endFill();
|
||||
}
|
||||
this._rectShape4.graphics.clear();
|
||||
for (var i = 0; i <= this.sampleFrames; ++i) {
|
||||
rc.x = Math.floor(position.x + frameSpan * i * msToPs);
|
||||
this._rectShape4.graphics.beginFill(0xFFFFFF);
|
||||
this._rectShape4.graphics.drawRect(rc.x, rc.y, rc.width, rc.height);
|
||||
this._rectShape4.graphics.endFill();
|
||||
}
|
||||
};
|
||||
TimeRuler.prototype.onGraphicsDeviceReset = function () {
|
||||
var layout = new es.Layout();
|
||||
@@ -11447,3 +11534,72 @@ var es;
|
||||
}());
|
||||
es.TextureToPack = TextureToPack;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Timer = (function () {
|
||||
function Timer() {
|
||||
this._timeInSeconds = 0;
|
||||
this._repeats = false;
|
||||
this._isDone = false;
|
||||
this._elapsedTime = 0;
|
||||
}
|
||||
Timer.prototype.getContext = function () {
|
||||
return this.context;
|
||||
};
|
||||
Timer.prototype.reset = function () {
|
||||
this._elapsedTime = 0;
|
||||
};
|
||||
Timer.prototype.stop = function () {
|
||||
this._isDone = true;
|
||||
};
|
||||
Timer.prototype.tick = function () {
|
||||
if (!this._isDone && this._elapsedTime > this._timeInSeconds) {
|
||||
this._elapsedTime -= this._timeInSeconds;
|
||||
this._onTime(this);
|
||||
if (!this._isDone && !this._repeats)
|
||||
this._isDone = true;
|
||||
}
|
||||
this._elapsedTime += es.Time.deltaTime;
|
||||
return this._isDone;
|
||||
};
|
||||
Timer.prototype.initialize = function (timeInsSeconds, repeats, context, onTime) {
|
||||
this._timeInSeconds = timeInsSeconds;
|
||||
this._repeats = repeats;
|
||||
this.context = context;
|
||||
this._onTime = onTime;
|
||||
};
|
||||
Timer.prototype.unload = function () {
|
||||
this.context = null;
|
||||
this._onTime = null;
|
||||
};
|
||||
return Timer;
|
||||
}());
|
||||
es.Timer = Timer;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var TimerManager = (function (_super) {
|
||||
__extends(TimerManager, _super);
|
||||
function TimerManager() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this._timers = [];
|
||||
return _this;
|
||||
}
|
||||
TimerManager.prototype.update = function () {
|
||||
for (var i = this._timers.length - 1; i >= 0; i--) {
|
||||
if (this._timers[i].tick()) {
|
||||
this._timers[i].unload();
|
||||
this._timers.removeAt(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
TimerManager.prototype.schedule = function (timeInSeconds, repeats, context, onTime) {
|
||||
var timer = new es.Timer();
|
||||
timer.initialize(timeInSeconds, repeats, context, onTime);
|
||||
this._timers.push(timer);
|
||||
return timer;
|
||||
};
|
||||
return TimerManager;
|
||||
}(es.GlobalManager));
|
||||
es.TimerManager = TimerManager;
|
||||
})(es || (es = {}));
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
-1092
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,4 @@
|
||||
module es {
|
||||
export enum CameraStyle {
|
||||
lockOn,
|
||||
cameraWindow,
|
||||
}
|
||||
|
||||
export class CameraInset {
|
||||
public left: number = 0;
|
||||
public right: number = 0;
|
||||
@@ -16,39 +11,9 @@ module es {
|
||||
public _areMatrixedDirty: boolean = true;
|
||||
public _areBoundsDirty: boolean = true;
|
||||
public _isProjectionMatrixDirty = true;
|
||||
/**
|
||||
* 如果相机模式为cameraWindow 则会进行缓动移动
|
||||
* 该值为移动速度
|
||||
*/
|
||||
public followLerp = 0.1;
|
||||
/**
|
||||
* 在cameraWindow模式下,宽度/高度被用做边界框,允许在不移动相机的情况下移动
|
||||
* 在lockOn模式下,只使用deadZone的x/y值 你可以通过直接setCenteredDeadzone重写它来自定义deadZone
|
||||
*/
|
||||
public deadzone: Rectangle = new Rectangle();
|
||||
/**
|
||||
* 相机聚焦于屏幕中心的偏移
|
||||
*/
|
||||
public focusOffset: Vector2 = Vector2.zero;
|
||||
/**
|
||||
* 如果为true 相机位置则不会超出地图矩形(0, 0, mapwidth, mapheight)
|
||||
*/
|
||||
public mapLockEnabled: boolean = false;
|
||||
/**
|
||||
* 當前地圖映射的寬度和高度
|
||||
*/
|
||||
public mapSize: Rectangle = new Rectangle();
|
||||
public _targetEntity: Entity;
|
||||
public _targetCollider: Collider;
|
||||
public _desiredPositionDelta: Vector2 = new Vector2();
|
||||
public _cameraStyle: CameraStyle;
|
||||
public _worldSpaceDeadZone: Rectangle = new Rectangle();
|
||||
|
||||
constructor(targetEntity: Entity = null, cameraStyle: CameraStyle = CameraStyle.lockOn) {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
this.setZoom(0);
|
||||
}
|
||||
|
||||
@@ -82,7 +47,25 @@ module es {
|
||||
this.entity.transform.rotation = value;
|
||||
}
|
||||
|
||||
public _zoom;
|
||||
/**
|
||||
* 原始的缩放值。这就是用于比例矩阵的精确值。默认值为1。
|
||||
*/
|
||||
public get rawZoom(){
|
||||
return this._zoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* 原始的缩放值。这就是用于比例矩阵的精确值。默认值为1。
|
||||
* @param value
|
||||
*/
|
||||
public set rawZoom(value: number){
|
||||
if (value != this._zoom){
|
||||
this._zoom = value;
|
||||
this._areMatrixedDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
public _zoom: number = 0;
|
||||
|
||||
/**
|
||||
* 缩放值应该在-1和1之间、然后将该值从minimumZoom转换为maximumZoom。
|
||||
@@ -218,18 +201,6 @@ module es {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当场景渲染目标的大小发生变化时,我们会更新相机的原点并调整它的位置以保持它原来的位置
|
||||
* @param newWidth
|
||||
* @param newHeight
|
||||
*/
|
||||
public onSceneSizeChanged(newWidth: number, newHeight: number) {
|
||||
let oldOrigin = this._origin;
|
||||
this.origin = new Vector2(newWidth / 2, newHeight / 2);
|
||||
|
||||
this.entity.transform.position = Vector2.add(this.entity.transform.position, Vector2.subtract(this._origin, oldOrigin));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置用于从视口边缘插入摄像机边界的量
|
||||
* @param left
|
||||
@@ -318,6 +289,11 @@ module es {
|
||||
return this;
|
||||
}
|
||||
|
||||
public forceMatrixUpdate(){
|
||||
// 弄脏矩阵也会自动弄脏边界
|
||||
this._areMatrixedDirty = true;
|
||||
}
|
||||
|
||||
public onEntityTransformChanged(comp: transform.Component) {
|
||||
this._areMatrixedDirty = true;
|
||||
}
|
||||
@@ -336,7 +312,7 @@ module es {
|
||||
*/
|
||||
public worldToScreenPoint(worldPosition: Vector2): Vector2 {
|
||||
this.updateMatrixes();
|
||||
worldPosition = Vector2.transform(worldPosition, this._transformMatrix);
|
||||
worldPosition = Vector2Ext.transformR(worldPosition, this._transformMatrix);
|
||||
return worldPosition;
|
||||
}
|
||||
|
||||
@@ -346,10 +322,23 @@ module es {
|
||||
*/
|
||||
public screenToWorldPoint(screenPosition: Vector2): Vector2 {
|
||||
this.updateMatrixes();
|
||||
screenPosition = Vector2.transform(screenPosition, this._inverseTransformMatrix);
|
||||
screenPosition = Vector2Ext.transformR(screenPosition, this._inverseTransformMatrix);
|
||||
return screenPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当场景渲染目标的大小发生变化时,我们会更新相机的原点并调整它的位置以保持它原来的位置
|
||||
* @param newWidth
|
||||
* @param newHeight
|
||||
*/
|
||||
public onSceneRenderTargetSizeChanged(newWidth: number, newHeight: number){
|
||||
this._isProjectionMatrixDirty = true;
|
||||
let oldOrigin = this._origin;
|
||||
this.origin = new Vector2(newWidth / 2, newHeight / 2);
|
||||
|
||||
this.entity.transform.position.add(Vector2.subtract(this._origin, oldOrigin));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回鼠标在世界空间中的位置
|
||||
*/
|
||||
@@ -357,103 +346,6 @@ module es {
|
||||
return this.screenToWorldPoint(Input.touchPosition);
|
||||
}
|
||||
|
||||
public onAddedToEntity() {
|
||||
this.follow(this._targetEntity, this._cameraStyle);
|
||||
}
|
||||
|
||||
public update() {
|
||||
let halfScreen = Vector2.multiply(this.bounds.size, new Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.position.x - halfScreen.x * Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.position.y - halfScreen.y * Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
this._worldSpaceDeadZone.height = this.deadzone.height;
|
||||
|
||||
if (this._targetEntity)
|
||||
this.updateFollow();
|
||||
|
||||
this.position = Vector2.lerp(this.position, Vector2.add(this.position, this._desiredPositionDelta), this.followLerp);
|
||||
this.entity.transform.roundPosition();
|
||||
|
||||
if (this.mapLockEnabled) {
|
||||
this.position = this.clampToMapSize(this.position);
|
||||
this.entity.transform.roundPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 固定相机 永远不会离开地图的可见区域
|
||||
* @param position
|
||||
*/
|
||||
public clampToMapSize(position: Vector2) {
|
||||
let halfScreen = Vector2.multiply(this.bounds.size, new Vector2(0.5)).add(new Vector2(this.mapSize.x, this.mapSize.y));
|
||||
let cameraMax = new Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
|
||||
return Vector2.clamp(position, halfScreen, cameraMax);
|
||||
}
|
||||
|
||||
public updateFollow() {
|
||||
this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
|
||||
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
let targetX = this._targetEntity.transform.position.x;
|
||||
let targetY = this._targetEntity.transform.position.y;
|
||||
|
||||
if (this._worldSpaceDeadZone.x > targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
else if (this._worldSpaceDeadZone.x < targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
|
||||
if (this._worldSpaceDeadZone.y < targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
else if (this._worldSpaceDeadZone.y > targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
} else {
|
||||
if (!this._targetCollider) {
|
||||
this._targetCollider = this._targetEntity.getComponent<Collider>(Collider);
|
||||
if (!this._targetCollider)
|
||||
return;
|
||||
}
|
||||
|
||||
let targetBounds = this._targetEntity.getComponent<Collider>(Collider).bounds;
|
||||
if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
|
||||
if (this._worldSpaceDeadZone.left > targetBounds.left)
|
||||
this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
|
||||
else if (this._worldSpaceDeadZone.right < targetBounds.right)
|
||||
this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
|
||||
|
||||
if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
|
||||
this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
|
||||
else if (this._worldSpaceDeadZone.top > targetBounds.top)
|
||||
this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public follow(targetEntity: Entity, cameraStyle: CameraStyle = CameraStyle.cameraWindow) {
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
|
||||
switch (this._cameraStyle) {
|
||||
case CameraStyle.cameraWindow:
|
||||
let w = this.bounds.width / 6;
|
||||
let h = this.bounds.height / 3;
|
||||
this.deadzone = new Rectangle((this.bounds.width - w) / 2, (this.bounds.height - h) / 2, w, h);
|
||||
break;
|
||||
case CameraStyle.lockOn:
|
||||
this.deadzone = new Rectangle(this.bounds.width / 2, this.bounds.height / 2, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以给定的尺寸设置当前相机边界中心的死区
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public setCenteredDeadzone(width: number, height: number) {
|
||||
this.deadzone = new Rectangle((this.bounds.width - width) / 2, (this.bounds.height - height) / 2, width, height);
|
||||
}
|
||||
|
||||
protected updateMatrixes() {
|
||||
if (!this._areMatrixedDirty)
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
module es {
|
||||
export enum CameraStyle {
|
||||
lockOn,
|
||||
cameraWindow,
|
||||
}
|
||||
|
||||
export class FollowCamera extends Component {
|
||||
public camera: Camera;
|
||||
|
||||
/**
|
||||
* 如果相机模式为cameraWindow 则会进行缓动移动
|
||||
* 该值为移动速度
|
||||
*/
|
||||
public followLerp = 0.1;
|
||||
/**
|
||||
* 在cameraWindow模式下,宽度/高度被用做边界框,允许在不移动相机的情况下移动
|
||||
* 在lockOn模式下,只使用deadZone的x/y值 你可以通过直接setCenteredDeadzone重写它来自定义deadZone
|
||||
*/
|
||||
public deadzone: Rectangle = new Rectangle();
|
||||
/**
|
||||
* 相机聚焦于屏幕中心的偏移
|
||||
*/
|
||||
public focusOffset: Vector2 = Vector2.zero;
|
||||
/**
|
||||
* 如果为true 相机位置则不会超出地图矩形(0, 0, mapwidth, mapheight)
|
||||
*/
|
||||
public mapLockEnabled: boolean = false;
|
||||
/**
|
||||
* 當前地圖映射的寬度和高度
|
||||
*/
|
||||
public mapSize: Rectangle = new Rectangle();
|
||||
|
||||
public _targetEntity: Entity;
|
||||
public _targetCollider: Collider;
|
||||
public _desiredPositionDelta: Vector2 = new Vector2();
|
||||
public _cameraStyle: CameraStyle;
|
||||
public _worldSpaceDeadZone: Rectangle = new Rectangle();
|
||||
|
||||
private rectShape: egret.Shape = new egret.Shape();
|
||||
|
||||
constructor(targetEntity: Entity = null, camera: Camera = null, cameraStyle: CameraStyle = CameraStyle.lockOn) {
|
||||
super();
|
||||
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
this.camera = camera;
|
||||
}
|
||||
|
||||
public onAddedToEntity() {
|
||||
if (!this.camera)
|
||||
this.camera = this.entity.scene.camera;
|
||||
|
||||
this.follow(this._targetEntity, this._cameraStyle);
|
||||
|
||||
Core.emitter.addObserver(CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
|
||||
}
|
||||
|
||||
public onGraphicsDeviceReset(){
|
||||
// 我们需要这个在下一帧触发 这样相机边界就会更新
|
||||
Core.schedule(0, false, this, t => {
|
||||
let self = t.context as FollowCamera;
|
||||
self.follow(self._targetEntity, self._cameraStyle);
|
||||
});
|
||||
}
|
||||
|
||||
public update() {
|
||||
let halfScreen = Vector2.multiply(this.camera.bounds.size, new Vector2(0.5));
|
||||
this._worldSpaceDeadZone.x = this.camera.position.x - halfScreen.x * Core.scene.scaleX + this.deadzone.x + this.focusOffset.x;
|
||||
this._worldSpaceDeadZone.y = this.camera.position.y - halfScreen.y * Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||
this._worldSpaceDeadZone.height = this.deadzone.height;
|
||||
|
||||
if (this._targetEntity)
|
||||
this.updateFollow();
|
||||
|
||||
this.camera.position = Vector2.lerp(this.camera.position, Vector2.add(this.camera.position, this._desiredPositionDelta), this.followLerp);
|
||||
this.entity.transform.roundPosition();
|
||||
|
||||
if (this.mapLockEnabled) {
|
||||
this.camera.position = this.clampToMapSize(this.camera.position);
|
||||
this.entity.transform.roundPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public debugRender() {
|
||||
if (!this.rectShape)
|
||||
this.debugDisplayObject.addChild(this.rectShape);
|
||||
|
||||
this.rectShape.graphics.clear();
|
||||
if (this._cameraStyle == CameraStyle.lockOn){
|
||||
this.rectShape.graphics.beginFill(0x8B0000, 0);
|
||||
this.rectShape.graphics.lineStyle(1, 0x8B0000);
|
||||
this.rectShape.graphics.drawRect(this._worldSpaceDeadZone.x - 5, this._worldSpaceDeadZone.y - 5,
|
||||
this._worldSpaceDeadZone.width, this._worldSpaceDeadZone.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
} else {
|
||||
this.rectShape.graphics.beginFill(0x8B0000, 0);
|
||||
this.rectShape.graphics.lineStyle(1, 0x8B0000);
|
||||
this.rectShape.graphics.drawRect(this._worldSpaceDeadZone.x, this._worldSpaceDeadZone.y,
|
||||
this._worldSpaceDeadZone.width, this._worldSpaceDeadZone.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 固定相机 永远不会离开地图的可见区域
|
||||
* @param position
|
||||
*/
|
||||
public clampToMapSize(position: Vector2) {
|
||||
let halfScreen = Vector2.multiply(this.camera.bounds.size, new Vector2(0.5)).add(new Vector2(this.mapSize.x, this.mapSize.y));
|
||||
let cameraMax = new Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
|
||||
return Vector2.clamp(position, halfScreen, cameraMax);
|
||||
}
|
||||
|
||||
public follow(targetEntity: Entity, cameraStyle: CameraStyle = CameraStyle.cameraWindow) {
|
||||
this._targetEntity = targetEntity;
|
||||
this._cameraStyle = cameraStyle;
|
||||
let cameraBounds = this.camera.bounds;
|
||||
|
||||
switch (this._cameraStyle) {
|
||||
case CameraStyle.cameraWindow:
|
||||
let w = cameraBounds.width / 6;
|
||||
let h = cameraBounds.height / 3;
|
||||
this.deadzone = new Rectangle((cameraBounds.width - w) / 2, (cameraBounds.height - h) / 2, w, h);
|
||||
break;
|
||||
case CameraStyle.lockOn:
|
||||
this.deadzone = new Rectangle(cameraBounds.width / 2, cameraBounds.height / 2, 10, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public updateFollow() {
|
||||
this._desiredPositionDelta.x = this._desiredPositionDelta.y = 0;
|
||||
|
||||
if (this._cameraStyle == CameraStyle.lockOn) {
|
||||
let targetX = this._targetEntity.transform.position.x;
|
||||
let targetY = this._targetEntity.transform.position.y;
|
||||
|
||||
if (this._worldSpaceDeadZone.x > targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
else if (this._worldSpaceDeadZone.x < targetX)
|
||||
this._desiredPositionDelta.x = targetX - this._worldSpaceDeadZone.x;
|
||||
|
||||
if (this._worldSpaceDeadZone.y < targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
else if (this._worldSpaceDeadZone.y > targetY)
|
||||
this._desiredPositionDelta.y = targetY - this._worldSpaceDeadZone.y;
|
||||
} else {
|
||||
if (!this._targetCollider) {
|
||||
this._targetCollider = this._targetEntity.getComponent<Collider>(Collider);
|
||||
if (!this._targetCollider)
|
||||
return;
|
||||
}
|
||||
|
||||
let targetBounds = this._targetEntity.getComponent<Collider>(Collider).bounds;
|
||||
if (!this._worldSpaceDeadZone.containsRect(targetBounds)) {
|
||||
if (this._worldSpaceDeadZone.left > targetBounds.left)
|
||||
this._desiredPositionDelta.x = targetBounds.left - this._worldSpaceDeadZone.left;
|
||||
else if (this._worldSpaceDeadZone.right < targetBounds.right)
|
||||
this._desiredPositionDelta.x = targetBounds.right - this._worldSpaceDeadZone.right;
|
||||
|
||||
if (this._worldSpaceDeadZone.bottom < targetBounds.bottom)
|
||||
this._desiredPositionDelta.y = targetBounds.bottom - this._worldSpaceDeadZone.bottom;
|
||||
else if (this._worldSpaceDeadZone.top > targetBounds.top)
|
||||
this._desiredPositionDelta.y = targetBounds.top - this._worldSpaceDeadZone.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 以给定的尺寸设置当前相机边界中心的死区
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public setCenteredDeadzone(width: number, height: number) {
|
||||
if (!this.camera){
|
||||
console.error("相机是null。我们不能得到它的边界。请等到该组件添加到实体之后");
|
||||
return;
|
||||
}
|
||||
let cameraBounds = this.camera.bounds;
|
||||
this.deadzone = new Rectangle((cameraBounds.width - width) / 2, (cameraBounds.height - height) / 2, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,18 +110,18 @@ module es {
|
||||
if (!this.pixelShape2.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(Colors.colliderBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
// this.hollowShape.graphics.clear();
|
||||
// this.hollowShape.graphics.beginFill(Colors.colliderBounds, 0);
|
||||
// this.hollowShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderBounds);
|
||||
// this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
// this.hollowShape.graphics.endFill();
|
||||
|
||||
this.polygonShape.graphics.clear();
|
||||
if (poly.points.length >= 2){
|
||||
this.polygonShape.graphics.beginFill(Colors.colliderEdge, 0);
|
||||
this.polygonShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderEdge);
|
||||
for (let i = 1; i < poly.points.length; i ++){
|
||||
if (i == 1){
|
||||
for (let i = 0; i < poly.points.length; i ++){
|
||||
if (i == 0){
|
||||
this.polygonShape.graphics.moveTo(poly.position.x + poly.points[i].x, poly.position.y + poly.points[i].y);
|
||||
}else{
|
||||
this.polygonShape.graphics.lineTo(poly.position.x + poly.points[i].x, poly.position.y + poly.points[i].y);
|
||||
@@ -136,6 +136,7 @@ module es {
|
||||
this.pixelShape1.graphics.beginFill(Colors.colliderPosition, 0);
|
||||
this.pixelShape1.graphics.lineStyle(4 * Size.lineSizeMultiplier, Colors.colliderPosition);
|
||||
this.pixelShape1.graphics.moveTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.lineTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.endFill();
|
||||
|
||||
this.pixelShape2.graphics.clear();
|
||||
@@ -143,6 +144,8 @@ module es {
|
||||
this.pixelShape2.graphics.lineStyle(2 * Size.lineSizeMultiplier, Colors.colliderCenter);
|
||||
this.pixelShape2.graphics.moveTo(this.entity.transform.position.x + this.shape.center.x,
|
||||
this.entity.transform.position.y + this.shape.center.y);
|
||||
this.pixelShape2.graphics.lineTo(this.entity.transform.position.x + this.shape.center.x,
|
||||
this.entity.transform.position.y + this.shape.center.y);
|
||||
this.pixelShape2.graphics.endFill();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
module es {
|
||||
export class CircleCollider extends Collider {
|
||||
private rectShape: egret.Shape = new egret.Shape();
|
||||
private circleShape: egret.Shape = new egret.Shape();
|
||||
private pixelShape1: egret.Shape = new egret.Shape();
|
||||
private pixelShape2: egret.Shape = new egret.Shape();
|
||||
|
||||
/**
|
||||
* 创建一个有半径的圆
|
||||
*
|
||||
@@ -41,6 +46,46 @@ module es {
|
||||
return this;
|
||||
}
|
||||
|
||||
public debugRender() {
|
||||
if (!this.rectShape.parent)
|
||||
this.debugDisplayObject.addChild(this.rectShape);
|
||||
|
||||
if (!this.circleShape.parent)
|
||||
this.debugDisplayObject.addChild(this.circleShape);
|
||||
|
||||
if (!this.pixelShape1.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape1);
|
||||
|
||||
if (!this.pixelShape2.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape2);
|
||||
|
||||
this.rectShape.graphics.clear();
|
||||
this.rectShape.graphics.beginFill(Colors.colliderBounds, 0);
|
||||
this.rectShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderBounds);
|
||||
this.rectShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.rectShape.graphics.endFill();
|
||||
|
||||
this.circleShape.graphics.clear();
|
||||
this.circleShape.graphics.beginFill(Colors.colliderEdge, 0);
|
||||
this.circleShape.graphics.lineStyle(Size.lineSizeMultiplier, Colors.colliderEdge);
|
||||
this.circleShape.graphics.drawCircle(this.shape.position.x, this.shape.position.y, (this.shape as Circle).radius);
|
||||
this.circleShape.graphics.endFill();
|
||||
|
||||
this.pixelShape1.graphics.clear();
|
||||
this.pixelShape1.graphics.beginFill(Colors.colliderPosition, 0);
|
||||
this.pixelShape1.graphics.lineStyle(4 * Size.lineSizeMultiplier, Colors.colliderPosition);
|
||||
this.pixelShape1.graphics.moveTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.lineTo(this.entity.transform.position.x, this.entity.transform.position.y);
|
||||
this.pixelShape1.graphics.endFill();
|
||||
|
||||
this.pixelShape2.graphics.clear();
|
||||
this.pixelShape2.graphics.beginFill(Colors.colliderCenter, 0);
|
||||
this.pixelShape2.graphics.lineStyle(2 * Size.lineSizeMultiplier, Colors.colliderCenter);
|
||||
this.pixelShape2.graphics.moveTo(this.shape.position.x, this.shape.position.y);
|
||||
this.pixelShape2.graphics.lineTo(this.shape.position.x, this.shape.position.y);
|
||||
this.pixelShape2.graphics.endFill();
|
||||
}
|
||||
|
||||
public toString() {
|
||||
return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]`
|
||||
}
|
||||
|
||||
@@ -122,19 +122,20 @@ module es {
|
||||
if (!this.pixelShape.parent)
|
||||
this.debugDisplayObject.addChild(this.pixelShape);
|
||||
|
||||
if (!this.entity.getComponent(Collider)){
|
||||
this.hollowShape.graphics.clear();
|
||||
this.hollowShape.graphics.beginFill(Colors.renderableBounds, 0);
|
||||
this.hollowShape.graphics.lineStyle(1, Colors.renderableBounds);
|
||||
this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
this.hollowShape.graphics.endFill();
|
||||
}
|
||||
// if (!this.entity.getComponent(Collider)){
|
||||
// this.hollowShape.graphics.clear();
|
||||
// this.hollowShape.graphics.beginFill(Colors.renderableBounds, 0);
|
||||
// this.hollowShape.graphics.lineStyle(1, Colors.renderableBounds);
|
||||
// this.hollowShape.graphics.drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
|
||||
// this.hollowShape.graphics.endFill();
|
||||
// }
|
||||
|
||||
let pixelPos = Vector2.add(this.entity.transform.position, this._localOffset);
|
||||
this.pixelShape.graphics.clear();
|
||||
this.pixelShape.graphics.beginFill(Colors.renderableCenter, 0);
|
||||
this.pixelShape.graphics.lineStyle(4, Colors.renderableCenter);
|
||||
this.pixelShape.graphics.lineTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.moveTo(pixelPos.x, pixelPos.y);
|
||||
this.pixelShape.graphics.endFill();
|
||||
}
|
||||
|
||||
|
||||
@@ -123,8 +123,10 @@ module es {
|
||||
public render(camera: Camera) {
|
||||
this.sync(camera);
|
||||
|
||||
if (this.displayObject.x != this.bounds.x) this.displayObject.x = this.bounds.x;
|
||||
if (this.displayObject.y != this.bounds.y) this.displayObject.y = this.bounds.y;
|
||||
let afterPos = new Vector2(this.entity.position.x + this.localOffset.x - this.origin.x - camera.position.x + camera.origin.x,
|
||||
this.entity.position.y + this.localOffset.y - this.origin.y - camera.position.y + camera.origin.y);
|
||||
if (this.displayObject.x != afterPos.x) this.displayObject.x = afterPos.x;
|
||||
if (this.displayObject.y != afterPos.y) this.displayObject.y = afterPos.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -29,6 +29,7 @@ module es {
|
||||
* 全局访问系统
|
||||
*/
|
||||
public _globalManagers: GlobalManager[] = [];
|
||||
public _timerManager: TimerManager = new TimerManager();
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -38,6 +39,8 @@ module es {
|
||||
Core.content = new ContentManager();
|
||||
|
||||
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
|
||||
|
||||
Core.registerGlobalManager(this._timerManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,8 +73,8 @@ module es {
|
||||
}
|
||||
|
||||
if (this._instance._scene == null) {
|
||||
this._instance._scene = value;
|
||||
this._instance.addChild(value);
|
||||
this._instance._scene = value;
|
||||
this._instance._scene.begin();
|
||||
Core.Instance.onSceneChanged();
|
||||
} else {
|
||||
@@ -123,6 +126,17 @@ module es {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调度一个一次性或重复的计时器,该计时器将调用已传递的动作
|
||||
* @param timeInSeconds
|
||||
* @param repeats
|
||||
* @param context
|
||||
* @param onTime
|
||||
*/
|
||||
public static schedule(timeInSeconds: number, repeats: boolean = false, context: any = null, onTime: (timer: ITimer)=>void){
|
||||
return this._instance._timerManager.schedule(timeInSeconds, repeats, context, onTime);
|
||||
}
|
||||
|
||||
public onOrientationChanged() {
|
||||
Core.emitter.emit(CoreEvents.OrientationChanged);
|
||||
}
|
||||
@@ -210,8 +224,8 @@ module es {
|
||||
this._nextScene = null;
|
||||
this.onSceneChanged();
|
||||
|
||||
this.addChild(this._scene);
|
||||
await this._scene.begin();
|
||||
this.addChild(this._scene);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-2
@@ -91,24 +91,34 @@ module es {
|
||||
console.warn("场景开始时没有渲染器 自动添加DefaultRenderer以保证能够正常渲染");
|
||||
}
|
||||
|
||||
this.camera = this.createEntity("camera").getOrCreateComponent(new Camera());
|
||||
let cameraEntity = this.findEntity("camera");
|
||||
if (!cameraEntity)
|
||||
cameraEntity = this.createEntity("camera");
|
||||
this.camera = cameraEntity.getOrCreateComponent(new Camera());
|
||||
|
||||
Physics.reset();
|
||||
this.updateResolutionScaler();
|
||||
|
||||
if (this.entityProcessors)
|
||||
this.entityProcessors.begin();
|
||||
|
||||
Core.emitter.addObserver(CoreEvents.GraphicsDeviceReset,this.updateResolutionScaler, this);
|
||||
Core.emitter.addObserver(CoreEvents.OrientationChanged, this.updateResolutionScaler, this);
|
||||
|
||||
this.addEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||
this.addEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||
this.camera.onSceneSizeChanged(this.stage.stageWidth, this.stage.stageHeight);
|
||||
|
||||
this._didSceneBegin = true;
|
||||
this.onStart();
|
||||
|
||||
}
|
||||
|
||||
public end() {
|
||||
this._didSceneBegin = false;
|
||||
|
||||
Core.emitter.removeObserver(CoreEvents.GraphicsDeviceReset, this.updateResolutionScaler);
|
||||
Core.emitter.removeObserver(CoreEvents.OrientationChanged, this.updateResolutionScaler);
|
||||
|
||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||
|
||||
@@ -140,6 +150,10 @@ module es {
|
||||
this.unload();
|
||||
}
|
||||
|
||||
public updateResolutionScaler(){
|
||||
this.camera.onSceneRenderTargetSizeChanged(Core.Instance.stage.stageWidth, Core.Instance.stage.stageHeight);
|
||||
}
|
||||
|
||||
public update() {
|
||||
// 更新我们的列表,以防它们有任何变化
|
||||
this.entities.updateLists();
|
||||
|
||||
@@ -50,9 +50,16 @@ module es {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定圆心、半径和角度,得到圆周上的一个点。0度是3点钟。
|
||||
* @param circleCenter
|
||||
* @param radius
|
||||
* @param angleInDegrees
|
||||
*/
|
||||
public static pointOnCirlce(circleCenter: Vector2, radius: number, angleInDegrees: number) {
|
||||
let radians = MathHelper.toRadians(angleInDegrees);
|
||||
return new Vector2(Math.cos(radians) * radians + circleCenter.x, Math.sin(radians) * radians + circleCenter.y);
|
||||
return new Vector2(Math.cos(radians) * radians + circleCenter.x,
|
||||
Math.sin(radians) * radians + circleCenter.y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
module es {
|
||||
/** 2d 向量 */
|
||||
export class Vector2 {
|
||||
private static readonly unitYVector = new Vector2(0, 1);
|
||||
private static readonly unitXVector = new Vector2(1, 0);
|
||||
private static readonly unitVector2 = new Vector2(1, 1);
|
||||
private static readonly zeroVector2 = new Vector2(0, 0);
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
|
||||
@@ -19,19 +15,19 @@ module es {
|
||||
}
|
||||
|
||||
public static get zero() {
|
||||
return Vector2.zeroVector2;
|
||||
return new Vector2(0, 0);
|
||||
}
|
||||
|
||||
public static get one() {
|
||||
return Vector2.unitVector2;
|
||||
return new Vector2(1, 1);
|
||||
}
|
||||
|
||||
public static get unitX() {
|
||||
return Vector2.unitXVector;
|
||||
return new Vector2(1, 0);
|
||||
}
|
||||
|
||||
public static get unitY() {
|
||||
return Vector2.unitYVector;
|
||||
return new Vector2(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -219,7 +219,7 @@ module es {
|
||||
let tempMat: Matrix2D;
|
||||
let combinedMatrix = Matrix2D.create().translate(-this._polygonCenter.x, -this._polygonCenter.y);
|
||||
|
||||
if (collider.entity.transform.scale != Vector2.zero) {
|
||||
if (collider.entity.transform.scale != Vector2.one) {
|
||||
tempMat = Matrix2D.create().scale(collider.entity.transform.scale.x, collider.entity.transform.scale.y);
|
||||
combinedMatrix = combinedMatrix.multiply(tempMat);
|
||||
hasUnitScale = false;
|
||||
@@ -238,7 +238,7 @@ module es {
|
||||
let offsetLength = hasUnitScale ? collider._localOffsetLength :
|
||||
Vector2.multiply(collider.localOffset, collider.entity.transform.scale).length();
|
||||
this.center = MathHelper.pointOnCirlce(Vector2.zero, offsetLength,
|
||||
collider.entity.transform.rotation + offsetAngle);
|
||||
collider.entity.transform.rotationDegrees + offsetAngle);
|
||||
}
|
||||
|
||||
tempMat = Matrix2D.create().translate(this._polygonCenter.x, this._polygonCenter.y);
|
||||
@@ -256,7 +256,7 @@ module es {
|
||||
|
||||
this.position = Vector2.add(collider.entity.transform.position, this.center);
|
||||
this.bounds = Rectangle.rectEncompassingPoints(this.points);
|
||||
this.bounds.location = this.bounds.location.add(this.position);
|
||||
this.bounds.location.add(this.position);
|
||||
}
|
||||
|
||||
public overlaps(other: Shape) {
|
||||
@@ -304,7 +304,7 @@ module es {
|
||||
*/
|
||||
public containsPoint(point: Vector2) {
|
||||
// 将点归一化到多边形坐标空间中
|
||||
point = Vector2.subtract(point, this.position);
|
||||
point.subtract(this.position);
|
||||
|
||||
let isInside = false;
|
||||
for (let i = 0, j = this.points.length - 1; i < this.points.length; j = i++) {
|
||||
|
||||
@@ -311,21 +311,16 @@ module es {
|
||||
return this._store.get(this.getKey(x, y));
|
||||
}
|
||||
|
||||
public getKey(x: number, y: number){
|
||||
return `${x}_${y}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除字典数据
|
||||
*/
|
||||
public clear() {
|
||||
this._store.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据x和y值计算并返回散列键
|
||||
* @param x
|
||||
* @param y
|
||||
*/
|
||||
private getKey(x: number, y: number): string {
|
||||
return Long.fromNumber(x).shiftLeft(32).or(Long.fromNumber(y, true)).toString();
|
||||
}
|
||||
}
|
||||
|
||||
export class RaycastResultParser {
|
||||
|
||||
@@ -25,8 +25,6 @@ module es {
|
||||
public enabled: true;
|
||||
/** 获取/设置日志显示或否 */
|
||||
public showLog = false;
|
||||
private _frameKey = 'frame';
|
||||
private _logKey = 'log';
|
||||
/** 每帧的日志 */
|
||||
private _logs: FrameLog[];
|
||||
/** 当前显示帧计数 */
|
||||
@@ -85,14 +83,10 @@ module es {
|
||||
*/
|
||||
public startFrame() {
|
||||
// 当这个方法被多次调用时,我们跳过重置帧。
|
||||
let lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(() => {
|
||||
this._updateCount = parseInt(egret.localStorage.getItem(this._frameKey), 10);
|
||||
if (isNaN(this._updateCount))
|
||||
this._updateCount = 0;
|
||||
let count = this._updateCount;
|
||||
count += 1;
|
||||
egret.localStorage.setItem(this._frameKey, count.toString());
|
||||
if (this.enabled && (1 < count && count < TimeRuler.maxSampleFrames))
|
||||
return;
|
||||
|
||||
@@ -150,17 +144,15 @@ module es {
|
||||
|
||||
this.stopwacth.reset();
|
||||
this.stopwacth.start();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始测量时间。
|
||||
* @param markerName
|
||||
* @param color
|
||||
* @param barIndex
|
||||
*/
|
||||
public beginMark(markerName: string, color: number, barIndex: number = 0) {
|
||||
let lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(() => {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
|
||||
throw new Error("barIndex argument out of range");
|
||||
|
||||
@@ -186,7 +178,6 @@ module es {
|
||||
bar.markers[bar.markCount].color = color;
|
||||
bar.markers[bar.markCount].beginTime = this.stopwacth.getTime();
|
||||
bar.markers[bar.markCount].endTime = -1;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,8 +186,6 @@ module es {
|
||||
* @param barIndex
|
||||
*/
|
||||
public endMark(markerName: string, barIndex: number = 0) {
|
||||
let lock = new LockUtils(this._frameKey);
|
||||
lock.lock().then(() => {
|
||||
if (barIndex < 0 || barIndex >= TimeRuler.maxBars)
|
||||
throw new Error("barIndex argument out of range");
|
||||
|
||||
@@ -216,7 +205,6 @@ module es {
|
||||
}
|
||||
|
||||
bar.markers[markerIdx].endTime = this.stopwacth.getTime();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,11 +229,6 @@ module es {
|
||||
*
|
||||
*/
|
||||
public resetLog() {
|
||||
let lock = new LockUtils(this._logKey);
|
||||
lock.lock().then(() => {
|
||||
let count = parseInt(egret.localStorage.getItem(this._logKey), 10);
|
||||
count += 1;
|
||||
egret.localStorage.setItem(this._logKey, count.toString());
|
||||
this.markers.forEach(markerInfo => {
|
||||
for (let i = 0; i < markerInfo.logs.length; ++i) {
|
||||
markerInfo.logs[i].initialized = false;
|
||||
@@ -260,12 +243,9 @@ module es {
|
||||
markerInfo.logs[i].samples = 0;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public render(position: Vector2 = this._position, width: number = this.width) {
|
||||
egret.localStorage.setItem(this._frameKey, "0");
|
||||
|
||||
if (!this.showLog)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
const THREAD_ID = `${Math.floor(Math.random() * 1000)}-${Date.now()}`;
|
||||
|
||||
const nextTick = fn => {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* 利用共享区域实现快速锁
|
||||
*/
|
||||
class LockUtils {
|
||||
private _keyX: string;
|
||||
private _keyY: string;
|
||||
private setItem;
|
||||
private getItem;
|
||||
private removeItem;
|
||||
|
||||
constructor(key) {
|
||||
this._keyX = `mutex_key_${key}_X`;
|
||||
this._keyY = `mutex_key_${key}_Y`;
|
||||
this.setItem = egret.localStorage.setItem.bind(localStorage);
|
||||
this.getItem = egret.localStorage.getItem.bind(localStorage);
|
||||
this.removeItem = egret.localStorage.removeItem.bind(localStorage);
|
||||
}
|
||||
|
||||
public lock() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fn = () => {
|
||||
this.setItem(this._keyX, THREAD_ID);
|
||||
if (!this.getItem(this._keyY) === null) {
|
||||
// restart
|
||||
nextTick(fn);
|
||||
}
|
||||
this.setItem(this._keyY, THREAD_ID);
|
||||
if (this.getItem(this._keyX) !== THREAD_ID) {
|
||||
// delay
|
||||
setTimeout(() => {
|
||||
if (this.getItem(this._keyY) !== THREAD_ID) {
|
||||
// restart
|
||||
nextTick(fn);
|
||||
return;
|
||||
}
|
||||
// critical section
|
||||
resolve();
|
||||
this.removeItem(this._keyY);
|
||||
}, 10);
|
||||
} else {
|
||||
resolve();
|
||||
this.removeItem(this._keyY);
|
||||
}
|
||||
};
|
||||
|
||||
fn();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
module es {
|
||||
export interface ITimer {
|
||||
context: any;
|
||||
|
||||
/**
|
||||
* 调用stop以停止此计时器再次运行。这对非重复计时器没有影响。
|
||||
*/
|
||||
stop();
|
||||
|
||||
/**
|
||||
* 将计时器的运行时间重置为0
|
||||
*/
|
||||
reset();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
getContext<T>(): T;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
module es {
|
||||
export class Timer implements ITimer{
|
||||
public context: any;
|
||||
public _timeInSeconds: number = 0;
|
||||
public _repeats: boolean = false;
|
||||
public _onTime: (timer: ITimer) => void;
|
||||
public _isDone: boolean = false;
|
||||
public _elapsedTime: number = 0;
|
||||
|
||||
public getContext<T>(): T {
|
||||
return this.context as T;
|
||||
}
|
||||
|
||||
public reset() {
|
||||
this._elapsedTime = 0;
|
||||
}
|
||||
|
||||
public stop() {
|
||||
this._isDone = true;
|
||||
}
|
||||
|
||||
public tick(){
|
||||
// 如果stop在tick之前被调用,那么isDone将为true,我们不应该再做任何事情
|
||||
if (!this._isDone && this._elapsedTime > this._timeInSeconds){
|
||||
this._elapsedTime -= this._timeInSeconds;
|
||||
this._onTime(this);
|
||||
|
||||
if (!this._isDone && !this._repeats)
|
||||
this._isDone = true;
|
||||
}
|
||||
|
||||
this._elapsedTime += Time.deltaTime;
|
||||
|
||||
return this._isDone;
|
||||
}
|
||||
|
||||
public initialize(timeInsSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer)=>void){
|
||||
this._timeInSeconds = timeInsSeconds;
|
||||
this._repeats = repeats;
|
||||
this.context = context;
|
||||
this._onTime = onTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* 空出对象引用,以便在js需要时GC可以清理它们的引用
|
||||
*/
|
||||
public unload(){
|
||||
this.context = null;
|
||||
this._onTime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
module es {
|
||||
/**
|
||||
* 允许动作的延迟和重复执行
|
||||
*/
|
||||
export class TimerManager extends GlobalManager {
|
||||
public _timers: Timer[] = [];
|
||||
|
||||
public update() {
|
||||
for (let i = this._timers.length - 1; i >= 0; i --){
|
||||
if (this._timers[i].tick()){
|
||||
this._timers[i].unload();
|
||||
this._timers.removeAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调度一个一次性或重复的计时器,该计时器将调用已传递的动作
|
||||
* @param timeInSeconds
|
||||
* @param repeats
|
||||
* @param context
|
||||
* @param onTime
|
||||
*/
|
||||
public schedule(timeInSeconds: number, repeats: boolean, context: any, onTime: (timer: ITimer)=>void){
|
||||
let timer = new Timer();
|
||||
timer.initialize(timeInSeconds, repeats, context, onTime);
|
||||
this._timers.push(timer);
|
||||
|
||||
return timer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user