为boxCollider与spriteRenderer新增debugRender
This commit is contained in:
Vendored
+50
-31
@@ -193,6 +193,43 @@ declare module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
class Core extends egret.DisplayObjectContainer {
|
||||||
|
static emitter: Emitter<CoreEvents>;
|
||||||
|
static debugRenderEndabled: boolean;
|
||||||
|
static graphicsDevice: GraphicsDevice;
|
||||||
|
static content: ContentManager;
|
||||||
|
static _instance: Core;
|
||||||
|
_nextScene: Scene;
|
||||||
|
_sceneTransition: SceneTransition;
|
||||||
|
_globalManagers: GlobalManager[];
|
||||||
|
constructor();
|
||||||
|
static readonly Instance: Core;
|
||||||
|
_scene: Scene;
|
||||||
|
static scene: Scene;
|
||||||
|
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
||||||
|
static registerGlobalManager(manager: es.GlobalManager): void;
|
||||||
|
static unregisterGlobalManager(manager: es.GlobalManager): void;
|
||||||
|
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
|
||||||
|
onOrientationChanged(): void;
|
||||||
|
draw(): Promise<void>;
|
||||||
|
startDebugUpdate(): void;
|
||||||
|
endDebugUpdate(): void;
|
||||||
|
onSceneChanged(): void;
|
||||||
|
protected onGraphicsDeviceReset(): void;
|
||||||
|
protected initialize(): void;
|
||||||
|
protected update(): Promise<void>;
|
||||||
|
private onAddToStage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class Colors {
|
||||||
|
static renderableBounds: number;
|
||||||
|
static renderableCenter: number;
|
||||||
|
static colliderBounds: number;
|
||||||
|
}
|
||||||
|
class Size {
|
||||||
|
static readonly lineSizeMultiplier: number;
|
||||||
|
}
|
||||||
class Debug {
|
class Debug {
|
||||||
private static _debugDrawItems;
|
private static _debugDrawItems;
|
||||||
static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void;
|
static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void;
|
||||||
@@ -231,6 +268,7 @@ declare module es {
|
|||||||
abstract class Component extends egret.HashObject {
|
abstract class Component extends egret.HashObject {
|
||||||
entity: Entity;
|
entity: Entity;
|
||||||
updateInterval: number;
|
updateInterval: number;
|
||||||
|
debugDisplayObject: egret.DisplayObjectContainer;
|
||||||
readonly transform: Transform;
|
readonly transform: Transform;
|
||||||
private _enabled;
|
private _enabled;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
@@ -249,35 +287,6 @@ declare module es {
|
|||||||
clone(): Component;
|
clone(): Component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class Core extends egret.DisplayObjectContainer {
|
|
||||||
static emitter: Emitter<CoreEvents>;
|
|
||||||
static debugRenderEndabled: boolean;
|
|
||||||
static graphicsDevice: GraphicsDevice;
|
|
||||||
static content: ContentManager;
|
|
||||||
static _instance: Core;
|
|
||||||
_nextScene: Scene;
|
|
||||||
_sceneTransition: SceneTransition;
|
|
||||||
_globalManagers: GlobalManager[];
|
|
||||||
constructor();
|
|
||||||
static readonly Instance: Core;
|
|
||||||
_scene: Scene;
|
|
||||||
static scene: Scene;
|
|
||||||
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
|
||||||
static registerGlobalManager(manager: es.GlobalManager): void;
|
|
||||||
static unregisterGlobalManager(manager: es.GlobalManager): void;
|
|
||||||
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
|
|
||||||
onOrientationChanged(): void;
|
|
||||||
draw(): Promise<void>;
|
|
||||||
startDebugUpdate(): void;
|
|
||||||
endDebugUpdate(): void;
|
|
||||||
onSceneChanged(): void;
|
|
||||||
protected onGraphicsDeviceReset(): void;
|
|
||||||
protected initialize(): void;
|
|
||||||
protected update(): Promise<void>;
|
|
||||||
private onAddToStage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
enum CoreEvents {
|
enum CoreEvents {
|
||||||
GraphicsDeviceReset = 0,
|
GraphicsDeviceReset = 0,
|
||||||
@@ -562,10 +571,13 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
abstract class RenderableComponent extends Component implements IRenderable {
|
abstract class RenderableComponent extends Component implements IRenderable {
|
||||||
displayObject: egret.DisplayObject;
|
displayObject: egret.DisplayObject;
|
||||||
|
hollowShape: egret.Shape;
|
||||||
|
pixelShape: egret.Shape;
|
||||||
color: number;
|
color: number;
|
||||||
protected _areBoundsDirty: boolean;
|
protected _areBoundsDirty: boolean;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly height: number;
|
readonly height: number;
|
||||||
|
debugRenderEnabled: boolean;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
localOffset: Vector2;
|
localOffset: Vector2;
|
||||||
protected _renderLayer: number;
|
protected _renderLayer: number;
|
||||||
@@ -576,6 +588,7 @@ declare module es {
|
|||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
onEntityTransformChanged(comp: transform.Component): void;
|
onEntityTransformChanged(comp: transform.Component): void;
|
||||||
abstract render(camera: Camera): any;
|
abstract render(camera: Camera): any;
|
||||||
|
debugRender(): void;
|
||||||
isVisibleFromCamera(camera: Camera): boolean;
|
isVisibleFromCamera(camera: Camera): boolean;
|
||||||
setRenderLayer(renderLayer: number): RenderableComponent;
|
setRenderLayer(renderLayer: number): RenderableComponent;
|
||||||
setColor(color: number): RenderableComponent;
|
setColor(color: number): RenderableComponent;
|
||||||
@@ -782,6 +795,7 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
abstract class Collider extends Component {
|
abstract class Collider extends Component {
|
||||||
|
debug: any;
|
||||||
shape: Shape;
|
shape: Shape;
|
||||||
isTrigger: boolean;
|
isTrigger: boolean;
|
||||||
physicsLayer: number;
|
physicsLayer: number;
|
||||||
@@ -815,6 +829,10 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class BoxCollider extends Collider {
|
class BoxCollider extends Collider {
|
||||||
|
hollowShape: egret.Shape;
|
||||||
|
polygonShape: egret.Shape;
|
||||||
|
pixelShape1: egret.Shape;
|
||||||
|
pixelShape2: egret.Shape;
|
||||||
constructor();
|
constructor();
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
@@ -822,6 +840,7 @@ declare module es {
|
|||||||
setSize(width: number, height: number): this;
|
setSize(width: number, height: number): this;
|
||||||
setWidth(width: number): BoxCollider;
|
setWidth(width: number): BoxCollider;
|
||||||
setHeight(height: number): void;
|
setHeight(height: number): void;
|
||||||
|
debugRender(): void;
|
||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1468,7 +1487,7 @@ declare module es {
|
|||||||
static recenterPolygonVerts(points: Vector2[]): void;
|
static recenterPolygonVerts(points: Vector2[]): void;
|
||||||
static findPolygonCenter(points: Vector2[]): Vector2;
|
static findPolygonCenter(points: Vector2[]): Vector2;
|
||||||
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
||||||
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2;
|
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Number, edgeNormal: Vector2): Vector2;
|
||||||
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
|
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
|
||||||
recalculateBounds(collider: Collider): void;
|
recalculateBounds(collider: Collider): void;
|
||||||
overlaps(other: Shape): any;
|
overlaps(other: Shape): any;
|
||||||
@@ -2201,7 +2220,7 @@ declare module es {
|
|||||||
static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
|
static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
|
||||||
static cross(u: Vector2, v: Vector2): number;
|
static cross(u: Vector2, v: Vector2): number;
|
||||||
static perpendicular(first: Vector2, second: Vector2): Vector2;
|
static perpendicular(first: Vector2, second: Vector2): Vector2;
|
||||||
static normalize(vec: Vector2): Vector2;
|
static normalize(vec: Vector2): void;
|
||||||
static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
|
static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
|
||||||
static transformR(position: Vector2, matrix: Matrix2D): Vector2;
|
static transformR(position: Vector2, matrix: Matrix2D): Vector2;
|
||||||
static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
|
static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
|
||||||
|
|||||||
+246
-168
@@ -693,10 +693,11 @@ var es;
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Vector2.normalize = function (value) {
|
Vector2.normalize = function (value) {
|
||||||
var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
|
var nValue = new Vector2(value.x, value.y);
|
||||||
value.x *= val;
|
var val = 1 / Math.sqrt((nValue.x * nValue.x) + (nValue.y * nValue.y));
|
||||||
value.y *= val;
|
nValue.x *= val;
|
||||||
return value;
|
nValue.y *= val;
|
||||||
|
return nValue;
|
||||||
};
|
};
|
||||||
Vector2.dot = function (value1, value2) {
|
Vector2.dot = function (value1, value2) {
|
||||||
return (value1.x * value2.x) + (value1.y * value2.y);
|
return (value1.x * value2.x) + (value1.y * value2.y);
|
||||||
@@ -964,159 +965,6 @@ var es;
|
|||||||
es.WeightedPathfinder = WeightedPathfinder;
|
es.WeightedPathfinder = WeightedPathfinder;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
|
||||||
var Debug = (function () {
|
|
||||||
function Debug() {
|
|
||||||
}
|
|
||||||
Debug.drawHollowRect = function (rectanle, color, duration) {
|
|
||||||
if (duration === void 0) { duration = 0; }
|
|
||||||
this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration));
|
|
||||||
};
|
|
||||||
Debug.render = function () {
|
|
||||||
if (this._debugDrawItems.length > 0) {
|
|
||||||
var debugShape = new egret.Shape();
|
|
||||||
if (es.Core.scene) {
|
|
||||||
es.Core.scene.addChild(debugShape);
|
|
||||||
}
|
|
||||||
for (var i = this._debugDrawItems.length - 1; i >= 0; i--) {
|
|
||||||
var item = this._debugDrawItems[i];
|
|
||||||
if (item.draw(debugShape))
|
|
||||||
this._debugDrawItems.removeAt(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Debug._debugDrawItems = [];
|
|
||||||
return Debug;
|
|
||||||
}());
|
|
||||||
es.Debug = Debug;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
var DebugDefaults = (function () {
|
|
||||||
function DebugDefaults() {
|
|
||||||
}
|
|
||||||
DebugDefaults.verletParticle = 0xDC345E;
|
|
||||||
DebugDefaults.verletConstraintEdge = 0x433E36;
|
|
||||||
return DebugDefaults;
|
|
||||||
}());
|
|
||||||
es.DebugDefaults = DebugDefaults;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
var DebugDrawType;
|
|
||||||
(function (DebugDrawType) {
|
|
||||||
DebugDrawType[DebugDrawType["line"] = 0] = "line";
|
|
||||||
DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle";
|
|
||||||
DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel";
|
|
||||||
DebugDrawType[DebugDrawType["text"] = 3] = "text";
|
|
||||||
})(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {}));
|
|
||||||
var DebugDrawItem = (function () {
|
|
||||||
function DebugDrawItem(rectangle, color, duration) {
|
|
||||||
this.rectangle = rectangle;
|
|
||||||
this.color = color;
|
|
||||||
this.duration = duration;
|
|
||||||
this.drawType = DebugDrawType.hollowRectangle;
|
|
||||||
}
|
|
||||||
DebugDrawItem.prototype.draw = function (shape) {
|
|
||||||
switch (this.drawType) {
|
|
||||||
case DebugDrawType.line:
|
|
||||||
break;
|
|
||||||
case DebugDrawType.hollowRectangle:
|
|
||||||
break;
|
|
||||||
case DebugDrawType.pixel:
|
|
||||||
break;
|
|
||||||
case DebugDrawType.text:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.duration -= es.Time.deltaTime;
|
|
||||||
return this.duration < 0;
|
|
||||||
};
|
|
||||||
return DebugDrawItem;
|
|
||||||
}());
|
|
||||||
es.DebugDrawItem = DebugDrawItem;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
var Component = (function (_super) {
|
|
||||||
__extends(Component, _super);
|
|
||||||
function Component() {
|
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
||||||
_this.updateInterval = 1;
|
|
||||||
_this._enabled = true;
|
|
||||||
_this._updateOrder = 0;
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
Object.defineProperty(Component.prototype, "transform", {
|
|
||||||
get: function () {
|
|
||||||
return this.entity.transform;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Component.prototype, "enabled", {
|
|
||||||
get: function () {
|
|
||||||
return this.entity ? this.entity.enabled && this._enabled : this._enabled;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this.setEnabled(value);
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Component.prototype, "updateOrder", {
|
|
||||||
get: function () {
|
|
||||||
return this._updateOrder;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this.setUpdateOrder(value);
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Component.prototype.initialize = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onAddedToEntity = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onRemovedFromEntity = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onEntityTransformChanged = function (comp) {
|
|
||||||
};
|
|
||||||
Component.prototype.debugRender = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onEnabled = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onDisabled = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.update = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.setEnabled = function (isEnabled) {
|
|
||||||
if (this._enabled != isEnabled) {
|
|
||||||
this._enabled = isEnabled;
|
|
||||||
if (this._enabled) {
|
|
||||||
this.onEnabled();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.onDisabled();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
Component.prototype.setUpdateOrder = function (updateOrder) {
|
|
||||||
if (this._updateOrder != updateOrder) {
|
|
||||||
this._updateOrder = updateOrder;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
Component.prototype.clone = function () {
|
|
||||||
var component = ObjectUtils.clone(this);
|
|
||||||
component.entity = null;
|
|
||||||
return component;
|
|
||||||
};
|
|
||||||
return Component;
|
|
||||||
}(egret.HashObject));
|
|
||||||
es.Component = Component;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var Core = (function (_super) {
|
var Core = (function (_super) {
|
||||||
__extends(Core, _super);
|
__extends(Core, _super);
|
||||||
@@ -1289,6 +1137,182 @@ var es;
|
|||||||
es.Core = Core;
|
es.Core = Core;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Colors = (function () {
|
||||||
|
function Colors() {
|
||||||
|
}
|
||||||
|
Colors.renderableBounds = 0xffff00;
|
||||||
|
Colors.renderableCenter = 0x9932CC;
|
||||||
|
Colors.colliderBounds = 0x555555;
|
||||||
|
return Colors;
|
||||||
|
}());
|
||||||
|
es.Colors = Colors;
|
||||||
|
var Size = (function () {
|
||||||
|
function Size() {
|
||||||
|
}
|
||||||
|
Object.defineProperty(Size, "lineSizeMultiplier", {
|
||||||
|
get: function () {
|
||||||
|
return Math.max(Math.ceil(es.Core.scene.x / es.Core.scene.width), 1);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return Size;
|
||||||
|
}());
|
||||||
|
es.Size = Size;
|
||||||
|
var Debug = (function () {
|
||||||
|
function Debug() {
|
||||||
|
}
|
||||||
|
Debug.drawHollowRect = function (rectanle, color, duration) {
|
||||||
|
if (duration === void 0) { duration = 0; }
|
||||||
|
this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration));
|
||||||
|
};
|
||||||
|
Debug.render = function () {
|
||||||
|
if (this._debugDrawItems.length > 0) {
|
||||||
|
var debugShape = new egret.Shape();
|
||||||
|
if (es.Core.scene) {
|
||||||
|
es.Core.scene.addChild(debugShape);
|
||||||
|
}
|
||||||
|
for (var i = this._debugDrawItems.length - 1; i >= 0; i--) {
|
||||||
|
var item = this._debugDrawItems[i];
|
||||||
|
if (item.draw(debugShape))
|
||||||
|
this._debugDrawItems.removeAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Debug._debugDrawItems = [];
|
||||||
|
return Debug;
|
||||||
|
}());
|
||||||
|
es.Debug = Debug;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var DebugDefaults = (function () {
|
||||||
|
function DebugDefaults() {
|
||||||
|
}
|
||||||
|
DebugDefaults.verletParticle = 0xDC345E;
|
||||||
|
DebugDefaults.verletConstraintEdge = 0x433E36;
|
||||||
|
return DebugDefaults;
|
||||||
|
}());
|
||||||
|
es.DebugDefaults = DebugDefaults;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var DebugDrawType;
|
||||||
|
(function (DebugDrawType) {
|
||||||
|
DebugDrawType[DebugDrawType["line"] = 0] = "line";
|
||||||
|
DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle";
|
||||||
|
DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel";
|
||||||
|
DebugDrawType[DebugDrawType["text"] = 3] = "text";
|
||||||
|
})(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {}));
|
||||||
|
var DebugDrawItem = (function () {
|
||||||
|
function DebugDrawItem(rectangle, color, duration) {
|
||||||
|
this.rectangle = rectangle;
|
||||||
|
this.color = color;
|
||||||
|
this.duration = duration;
|
||||||
|
this.drawType = DebugDrawType.hollowRectangle;
|
||||||
|
}
|
||||||
|
DebugDrawItem.prototype.draw = function (shape) {
|
||||||
|
switch (this.drawType) {
|
||||||
|
case DebugDrawType.line:
|
||||||
|
break;
|
||||||
|
case DebugDrawType.hollowRectangle:
|
||||||
|
break;
|
||||||
|
case DebugDrawType.pixel:
|
||||||
|
break;
|
||||||
|
case DebugDrawType.text:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.duration -= es.Time.deltaTime;
|
||||||
|
return this.duration < 0;
|
||||||
|
};
|
||||||
|
return DebugDrawItem;
|
||||||
|
}());
|
||||||
|
es.DebugDrawItem = DebugDrawItem;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Component = (function (_super) {
|
||||||
|
__extends(Component, _super);
|
||||||
|
function Component() {
|
||||||
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this.updateInterval = 1;
|
||||||
|
_this.debugDisplayObject = new egret.DisplayObjectContainer();
|
||||||
|
_this._enabled = true;
|
||||||
|
_this._updateOrder = 0;
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
Object.defineProperty(Component.prototype, "transform", {
|
||||||
|
get: function () {
|
||||||
|
return this.entity.transform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Component.prototype, "enabled", {
|
||||||
|
get: function () {
|
||||||
|
return this.entity ? this.entity.enabled && this._enabled : this._enabled;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setEnabled(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Component.prototype, "updateOrder", {
|
||||||
|
get: function () {
|
||||||
|
return this._updateOrder;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setUpdateOrder(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Component.prototype.initialize = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onAddedToEntity = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onRemovedFromEntity = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onEntityTransformChanged = function (comp) {
|
||||||
|
};
|
||||||
|
Component.prototype.debugRender = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onEnabled = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onDisabled = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.update = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.setEnabled = function (isEnabled) {
|
||||||
|
if (this._enabled != isEnabled) {
|
||||||
|
this._enabled = isEnabled;
|
||||||
|
if (this._enabled) {
|
||||||
|
this.onEnabled();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.onDisabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Component.prototype.setUpdateOrder = function (updateOrder) {
|
||||||
|
if (this._updateOrder != updateOrder) {
|
||||||
|
this._updateOrder = updateOrder;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Component.prototype.clone = function () {
|
||||||
|
var component = ObjectUtils.clone(this);
|
||||||
|
component.entity = null;
|
||||||
|
return component;
|
||||||
|
};
|
||||||
|
return Component;
|
||||||
|
}(egret.HashObject));
|
||||||
|
es.Component = Component;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var CoreEvents;
|
var CoreEvents;
|
||||||
(function (CoreEvents) {
|
(function (CoreEvents) {
|
||||||
@@ -2450,7 +2474,7 @@ var es;
|
|||||||
this.follow(this._targetEntity, this._cameraStyle);
|
this.follow(this._targetEntity, this._cameraStyle);
|
||||||
};
|
};
|
||||||
Camera.prototype.update = function () {
|
Camera.prototype.update = function () {
|
||||||
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
|
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.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.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||||
@@ -2465,7 +2489,7 @@ var es;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Camera.prototype.clampToMapSize = function (position) {
|
Camera.prototype.clampToMapSize = function (position) {
|
||||||
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
|
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);
|
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||||
};
|
};
|
||||||
@@ -2645,8 +2669,11 @@ var es;
|
|||||||
function RenderableComponent() {
|
function RenderableComponent() {
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
_this.displayObject = new egret.DisplayObject();
|
_this.displayObject = new egret.DisplayObject();
|
||||||
|
_this.hollowShape = new egret.Shape();
|
||||||
|
_this.pixelShape = new egret.Shape();
|
||||||
_this.color = 0x000000;
|
_this.color = 0x000000;
|
||||||
_this._areBoundsDirty = true;
|
_this._areBoundsDirty = true;
|
||||||
|
_this.debugRenderEnabled = true;
|
||||||
_this._localOffset = es.Vector2.zero;
|
_this._localOffset = es.Vector2.zero;
|
||||||
_this._renderLayer = 0;
|
_this._renderLayer = 0;
|
||||||
_this._bounds = new es.Rectangle();
|
_this._bounds = new es.Rectangle();
|
||||||
@@ -2716,6 +2743,27 @@ var es;
|
|||||||
RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
|
RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
|
||||||
this._areBoundsDirty = true;
|
this._areBoundsDirty = true;
|
||||||
};
|
};
|
||||||
|
RenderableComponent.prototype.debugRender = function () {
|
||||||
|
if (!this.debugRenderEnabled)
|
||||||
|
return;
|
||||||
|
if (!this.hollowShape.parent)
|
||||||
|
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.endFill();
|
||||||
|
};
|
||||||
RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
|
RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
|
||||||
if (!camera)
|
if (!camera)
|
||||||
return false;
|
return false;
|
||||||
@@ -2759,9 +2807,11 @@ var es;
|
|||||||
};
|
};
|
||||||
RenderableComponent.prototype.onBecameVisible = function () {
|
RenderableComponent.prototype.onBecameVisible = function () {
|
||||||
this.displayObject.visible = this.isVisible;
|
this.displayObject.visible = this.isVisible;
|
||||||
|
this.debugDisplayObject.visible = this.isVisible;
|
||||||
};
|
};
|
||||||
RenderableComponent.prototype.onBecameInvisible = function () {
|
RenderableComponent.prototype.onBecameInvisible = function () {
|
||||||
this.displayObject.visible = this.isVisible;
|
this.displayObject.visible = this.isVisible;
|
||||||
|
this.debugDisplayObject.visible = this.isVisible;
|
||||||
};
|
};
|
||||||
return RenderableComponent;
|
return RenderableComponent;
|
||||||
}(es.Component));
|
}(es.Component));
|
||||||
@@ -3711,6 +3761,10 @@ var es;
|
|||||||
__extends(BoxCollider, _super);
|
__extends(BoxCollider, _super);
|
||||||
function BoxCollider() {
|
function BoxCollider() {
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
|
_this.hollowShape = new egret.Shape();
|
||||||
|
_this.polygonShape = new egret.Shape();
|
||||||
|
_this.pixelShape1 = new egret.Shape();
|
||||||
|
_this.pixelShape2 = new egret.Shape();
|
||||||
_this.shape = new es.Box(1, 1);
|
_this.shape = new es.Box(1, 1);
|
||||||
_this._colliderRequiresAutoSizing = true;
|
_this._colliderRequiresAutoSizing = true;
|
||||||
return _this;
|
return _this;
|
||||||
@@ -3770,6 +3824,22 @@ var es;
|
|||||||
es.Physics.updateCollider(this);
|
es.Physics.updateCollider(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
BoxCollider.prototype.debugRender = function () {
|
||||||
|
var poly = this.shape;
|
||||||
|
if (!this.hollowShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.hollowShape);
|
||||||
|
if (!this.polygonShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.polygonShape);
|
||||||
|
if (!this.pixelShape1.parent)
|
||||||
|
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();
|
||||||
|
};
|
||||||
BoxCollider.prototype.toString = function () {
|
BoxCollider.prototype.toString = function () {
|
||||||
return "[BoxCollider: bounds: " + this.bounds + "]";
|
return "[BoxCollider: bounds: " + this.bounds + "]";
|
||||||
};
|
};
|
||||||
@@ -4122,9 +4192,12 @@ var es;
|
|||||||
for (var i = 0; i < this._components.length; i++) {
|
for (var i = 0; i < this._components.length; i++) {
|
||||||
var component = this._components[i];
|
var component = this._components[i];
|
||||||
if (component instanceof es.RenderableComponent) {
|
if (component instanceof es.RenderableComponent) {
|
||||||
this._entity.scene.removeChild(component.displayObject);
|
if (component.displayObject.parent)
|
||||||
|
component.displayObject.parent.removeChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
}
|
}
|
||||||
|
if (component.debugDisplayObject.parent)
|
||||||
|
component.debugDisplayObject.parent.removeChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
}
|
}
|
||||||
@@ -4136,6 +4209,7 @@ var es;
|
|||||||
this._entity.scene.addChild(component.displayObject);
|
this._entity.scene.addChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.add(component);
|
this._entity.scene.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
@@ -4155,6 +4229,7 @@ var es;
|
|||||||
this._entity.scene.addChild(component.displayObject);
|
this._entity.scene.addChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.add(component);
|
this._entity.scene.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
@@ -4182,6 +4257,8 @@ var es;
|
|||||||
component.displayObject.parent.removeChild(component.displayObject);
|
component.displayObject.parent.removeChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
}
|
}
|
||||||
|
if (component.debugDisplayObject.parent)
|
||||||
|
component.debugDisplayObject.parent.removeChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
component.onRemovedFromEntity();
|
component.onRemovedFromEntity();
|
||||||
@@ -6854,7 +6931,7 @@ var es;
|
|||||||
else
|
else
|
||||||
p2 = this.points[i + 1];
|
p2 = this.points[i + 1];
|
||||||
var perp = es.Vector2Ext.perpendicular(p1, p2);
|
var perp = es.Vector2Ext.perpendicular(p1, p2);
|
||||||
perp = es.Vector2.normalize(perp);
|
es.Vector2Ext.normalize(perp);
|
||||||
this._edgeNormals[i] = perp;
|
this._edgeNormals[i] = perp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -6862,14 +6939,14 @@ var es;
|
|||||||
var verts = new Array(vertCount);
|
var verts = new Array(vertCount);
|
||||||
for (var i = 0; i < vertCount; i++) {
|
for (var i = 0; i < vertCount; i++) {
|
||||||
var a = 2 * Math.PI * (i / vertCount);
|
var a = 2 * Math.PI * (i / vertCount);
|
||||||
verts[i] = es.Vector2.multiply(new es.Vector2(Math.cos(a), Math.sin(a)), new es.Vector2(radius));
|
verts[i] = new es.Vector2(Math.cos(a) * radius, Math.sin(a) * radius);
|
||||||
}
|
}
|
||||||
return verts;
|
return verts;
|
||||||
};
|
};
|
||||||
Polygon.recenterPolygonVerts = function (points) {
|
Polygon.recenterPolygonVerts = function (points) {
|
||||||
var center = this.findPolygonCenter(points);
|
var center = this.findPolygonCenter(points);
|
||||||
for (var i = 0; i < points.length; i++)
|
for (var i = 0; i < points.length; i++)
|
||||||
points[i] = es.Vector2.subtract(points[i], center);
|
points[i].subtract(center);
|
||||||
};
|
};
|
||||||
Polygon.findPolygonCenter = function (points) {
|
Polygon.findPolygonCenter = function (points) {
|
||||||
var x = 0, y = 0;
|
var x = 0, y = 0;
|
||||||
@@ -6893,7 +6970,8 @@ var es;
|
|||||||
};
|
};
|
||||||
Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) {
|
Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) {
|
||||||
distanceSquared = Number.MAX_VALUE;
|
distanceSquared = Number.MAX_VALUE;
|
||||||
edgeNormal = new es.Vector2(0, 0);
|
edgeNormal.x = 0;
|
||||||
|
edgeNormal.y = 0;
|
||||||
var closestPoint = new es.Vector2(0, 0);
|
var closestPoint = new es.Vector2(0, 0);
|
||||||
var tempDistanceSquared;
|
var tempDistanceSquared;
|
||||||
for (var i = 0; i < points.length; i++) {
|
for (var i = 0; i < points.length; i++) {
|
||||||
@@ -6906,7 +6984,8 @@ var es;
|
|||||||
distanceSquared = tempDistanceSquared;
|
distanceSquared = tempDistanceSquared;
|
||||||
closestPoint = closest;
|
closestPoint = closest;
|
||||||
var line = es.Vector2.subtract(points[j], points[i]);
|
var line = es.Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal = new es.Vector2(-line.y, line.x);
|
edgeNormal.x = -line.y;
|
||||||
|
edgeNormal.y = line.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
es.Vector2Ext.normalize(edgeNormal);
|
es.Vector2Ext.normalize(edgeNormal);
|
||||||
@@ -7295,7 +7374,7 @@ var es;
|
|||||||
result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds);
|
result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds);
|
||||||
var depth = result.normal.length() - circle.radius;
|
var depth = result.normal.length() - circle.radius;
|
||||||
result.point = closestPointOnBounds;
|
result.point = closestPointOnBounds;
|
||||||
result.normal = es.Vector2Ext.normalize(result.normal);
|
es.Vector2Ext.normalize(result.normal);
|
||||||
result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal);
|
result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -10379,12 +10458,11 @@ var es;
|
|||||||
Vector2Ext.normalize = function (vec) {
|
Vector2Ext.normalize = function (vec) {
|
||||||
var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
||||||
if (magnitude > es.MathHelper.Epsilon) {
|
if (magnitude > es.MathHelper.Epsilon) {
|
||||||
vec = es.Vector2.divide(vec, new es.Vector2(magnitude));
|
vec.divide(new es.Vector2(magnitude));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vec.x = vec.y = 0;
|
vec.x = vec.y = 0;
|
||||||
}
|
}
|
||||||
return vec;
|
|
||||||
};
|
};
|
||||||
Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) {
|
Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) {
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -32,6 +32,7 @@ import LoadingView = loading.LoadingView;
|
|||||||
class Main extends es.Core {
|
class Main extends es.Core {
|
||||||
protected initialize() {
|
protected initialize() {
|
||||||
try {
|
try {
|
||||||
|
es.Core.debugRenderEndabled = true;
|
||||||
this.runGame();
|
this.runGame();
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ module sc {
|
|||||||
|
|
||||||
private scItemOnClick(evt: egret.Event){
|
private scItemOnClick(evt: egret.Event){
|
||||||
let data = evt.currentTarget.data;
|
let data = evt.currentTarget.data;
|
||||||
es.Core.scene = new data();
|
es.Core.startSceneTransition(new es.FadeTransition(()=>{
|
||||||
es.Core.scene.camera.position = es.Vector2.zero;
|
es.Core.scene.camera.position = es.Vector2.zero;
|
||||||
|
return new data();
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
|
|||||||
Vendored
+50
-31
@@ -193,6 +193,43 @@ declare module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
class Core extends egret.DisplayObjectContainer {
|
||||||
|
static emitter: Emitter<CoreEvents>;
|
||||||
|
static debugRenderEndabled: boolean;
|
||||||
|
static graphicsDevice: GraphicsDevice;
|
||||||
|
static content: ContentManager;
|
||||||
|
static _instance: Core;
|
||||||
|
_nextScene: Scene;
|
||||||
|
_sceneTransition: SceneTransition;
|
||||||
|
_globalManagers: GlobalManager[];
|
||||||
|
constructor();
|
||||||
|
static readonly Instance: Core;
|
||||||
|
_scene: Scene;
|
||||||
|
static scene: Scene;
|
||||||
|
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
||||||
|
static registerGlobalManager(manager: es.GlobalManager): void;
|
||||||
|
static unregisterGlobalManager(manager: es.GlobalManager): void;
|
||||||
|
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
|
||||||
|
onOrientationChanged(): void;
|
||||||
|
draw(): Promise<void>;
|
||||||
|
startDebugUpdate(): void;
|
||||||
|
endDebugUpdate(): void;
|
||||||
|
onSceneChanged(): void;
|
||||||
|
protected onGraphicsDeviceReset(): void;
|
||||||
|
protected initialize(): void;
|
||||||
|
protected update(): Promise<void>;
|
||||||
|
private onAddToStage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
declare module es {
|
||||||
|
class Colors {
|
||||||
|
static renderableBounds: number;
|
||||||
|
static renderableCenter: number;
|
||||||
|
static colliderBounds: number;
|
||||||
|
}
|
||||||
|
class Size {
|
||||||
|
static readonly lineSizeMultiplier: number;
|
||||||
|
}
|
||||||
class Debug {
|
class Debug {
|
||||||
private static _debugDrawItems;
|
private static _debugDrawItems;
|
||||||
static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void;
|
static drawHollowRect(rectanle: Rectangle, color: number, duration?: number): void;
|
||||||
@@ -231,6 +268,7 @@ declare module es {
|
|||||||
abstract class Component extends egret.HashObject {
|
abstract class Component extends egret.HashObject {
|
||||||
entity: Entity;
|
entity: Entity;
|
||||||
updateInterval: number;
|
updateInterval: number;
|
||||||
|
debugDisplayObject: egret.DisplayObjectContainer;
|
||||||
readonly transform: Transform;
|
readonly transform: Transform;
|
||||||
private _enabled;
|
private _enabled;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
@@ -249,35 +287,6 @@ declare module es {
|
|||||||
clone(): Component;
|
clone(): Component;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
|
||||||
class Core extends egret.DisplayObjectContainer {
|
|
||||||
static emitter: Emitter<CoreEvents>;
|
|
||||||
static debugRenderEndabled: boolean;
|
|
||||||
static graphicsDevice: GraphicsDevice;
|
|
||||||
static content: ContentManager;
|
|
||||||
static _instance: Core;
|
|
||||||
_nextScene: Scene;
|
|
||||||
_sceneTransition: SceneTransition;
|
|
||||||
_globalManagers: GlobalManager[];
|
|
||||||
constructor();
|
|
||||||
static readonly Instance: Core;
|
|
||||||
_scene: Scene;
|
|
||||||
static scene: Scene;
|
|
||||||
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
|
|
||||||
static registerGlobalManager(manager: es.GlobalManager): void;
|
|
||||||
static unregisterGlobalManager(manager: es.GlobalManager): void;
|
|
||||||
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
|
|
||||||
onOrientationChanged(): void;
|
|
||||||
draw(): Promise<void>;
|
|
||||||
startDebugUpdate(): void;
|
|
||||||
endDebugUpdate(): void;
|
|
||||||
onSceneChanged(): void;
|
|
||||||
protected onGraphicsDeviceReset(): void;
|
|
||||||
protected initialize(): void;
|
|
||||||
protected update(): Promise<void>;
|
|
||||||
private onAddToStage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
declare module es {
|
declare module es {
|
||||||
enum CoreEvents {
|
enum CoreEvents {
|
||||||
GraphicsDeviceReset = 0,
|
GraphicsDeviceReset = 0,
|
||||||
@@ -562,10 +571,13 @@ declare module es {
|
|||||||
declare module es {
|
declare module es {
|
||||||
abstract class RenderableComponent extends Component implements IRenderable {
|
abstract class RenderableComponent extends Component implements IRenderable {
|
||||||
displayObject: egret.DisplayObject;
|
displayObject: egret.DisplayObject;
|
||||||
|
hollowShape: egret.Shape;
|
||||||
|
pixelShape: egret.Shape;
|
||||||
color: number;
|
color: number;
|
||||||
protected _areBoundsDirty: boolean;
|
protected _areBoundsDirty: boolean;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
readonly height: number;
|
readonly height: number;
|
||||||
|
debugRenderEnabled: boolean;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
localOffset: Vector2;
|
localOffset: Vector2;
|
||||||
protected _renderLayer: number;
|
protected _renderLayer: number;
|
||||||
@@ -576,6 +588,7 @@ declare module es {
|
|||||||
isVisible: boolean;
|
isVisible: boolean;
|
||||||
onEntityTransformChanged(comp: transform.Component): void;
|
onEntityTransformChanged(comp: transform.Component): void;
|
||||||
abstract render(camera: Camera): any;
|
abstract render(camera: Camera): any;
|
||||||
|
debugRender(): void;
|
||||||
isVisibleFromCamera(camera: Camera): boolean;
|
isVisibleFromCamera(camera: Camera): boolean;
|
||||||
setRenderLayer(renderLayer: number): RenderableComponent;
|
setRenderLayer(renderLayer: number): RenderableComponent;
|
||||||
setColor(color: number): RenderableComponent;
|
setColor(color: number): RenderableComponent;
|
||||||
@@ -782,6 +795,7 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
abstract class Collider extends Component {
|
abstract class Collider extends Component {
|
||||||
|
debug: any;
|
||||||
shape: Shape;
|
shape: Shape;
|
||||||
isTrigger: boolean;
|
isTrigger: boolean;
|
||||||
physicsLayer: number;
|
physicsLayer: number;
|
||||||
@@ -815,6 +829,10 @@ declare module es {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class BoxCollider extends Collider {
|
class BoxCollider extends Collider {
|
||||||
|
hollowShape: egret.Shape;
|
||||||
|
polygonShape: egret.Shape;
|
||||||
|
pixelShape1: egret.Shape;
|
||||||
|
pixelShape2: egret.Shape;
|
||||||
constructor();
|
constructor();
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
@@ -822,6 +840,7 @@ declare module es {
|
|||||||
setSize(width: number, height: number): this;
|
setSize(width: number, height: number): this;
|
||||||
setWidth(width: number): BoxCollider;
|
setWidth(width: number): BoxCollider;
|
||||||
setHeight(height: number): void;
|
setHeight(height: number): void;
|
||||||
|
debugRender(): void;
|
||||||
toString(): string;
|
toString(): string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1468,7 +1487,7 @@ declare module es {
|
|||||||
static recenterPolygonVerts(points: Vector2[]): void;
|
static recenterPolygonVerts(points: Vector2[]): void;
|
||||||
static findPolygonCenter(points: Vector2[]): Vector2;
|
static findPolygonCenter(points: Vector2[]): Vector2;
|
||||||
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
static getFarthestPointInDirection(points: Vector2[], direction: Vector2): Vector2;
|
||||||
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2;
|
static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Number, edgeNormal: Vector2): Vector2;
|
||||||
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
|
static rotatePolygonVerts(radians: number, originalPoints: Vector2[], rotatedPoints: any): void;
|
||||||
recalculateBounds(collider: Collider): void;
|
recalculateBounds(collider: Collider): void;
|
||||||
overlaps(other: Shape): any;
|
overlaps(other: Shape): any;
|
||||||
@@ -2201,7 +2220,7 @@ declare module es {
|
|||||||
static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
|
static isTriangleCCW(a: Vector2, center: Vector2, c: Vector2): boolean;
|
||||||
static cross(u: Vector2, v: Vector2): number;
|
static cross(u: Vector2, v: Vector2): number;
|
||||||
static perpendicular(first: Vector2, second: Vector2): Vector2;
|
static perpendicular(first: Vector2, second: Vector2): Vector2;
|
||||||
static normalize(vec: Vector2): Vector2;
|
static normalize(vec: Vector2): void;
|
||||||
static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
|
static transformA(sourceArray: Vector2[], sourceIndex: number, matrix: Matrix2D, destinationArray: Vector2[], destinationIndex: number, length: number): void;
|
||||||
static transformR(position: Vector2, matrix: Matrix2D): Vector2;
|
static transformR(position: Vector2, matrix: Matrix2D): Vector2;
|
||||||
static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
|
static transform(sourceArray: Vector2[], matrix: Matrix2D, destinationArray: Vector2[]): void;
|
||||||
|
|||||||
+246
-168
@@ -693,10 +693,11 @@ var es;
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Vector2.normalize = function (value) {
|
Vector2.normalize = function (value) {
|
||||||
var val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
|
var nValue = new Vector2(value.x, value.y);
|
||||||
value.x *= val;
|
var val = 1 / Math.sqrt((nValue.x * nValue.x) + (nValue.y * nValue.y));
|
||||||
value.y *= val;
|
nValue.x *= val;
|
||||||
return value;
|
nValue.y *= val;
|
||||||
|
return nValue;
|
||||||
};
|
};
|
||||||
Vector2.dot = function (value1, value2) {
|
Vector2.dot = function (value1, value2) {
|
||||||
return (value1.x * value2.x) + (value1.y * value2.y);
|
return (value1.x * value2.x) + (value1.y * value2.y);
|
||||||
@@ -964,159 +965,6 @@ var es;
|
|||||||
es.WeightedPathfinder = WeightedPathfinder;
|
es.WeightedPathfinder = WeightedPathfinder;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
|
||||||
var Debug = (function () {
|
|
||||||
function Debug() {
|
|
||||||
}
|
|
||||||
Debug.drawHollowRect = function (rectanle, color, duration) {
|
|
||||||
if (duration === void 0) { duration = 0; }
|
|
||||||
this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration));
|
|
||||||
};
|
|
||||||
Debug.render = function () {
|
|
||||||
if (this._debugDrawItems.length > 0) {
|
|
||||||
var debugShape = new egret.Shape();
|
|
||||||
if (es.Core.scene) {
|
|
||||||
es.Core.scene.addChild(debugShape);
|
|
||||||
}
|
|
||||||
for (var i = this._debugDrawItems.length - 1; i >= 0; i--) {
|
|
||||||
var item = this._debugDrawItems[i];
|
|
||||||
if (item.draw(debugShape))
|
|
||||||
this._debugDrawItems.removeAt(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Debug._debugDrawItems = [];
|
|
||||||
return Debug;
|
|
||||||
}());
|
|
||||||
es.Debug = Debug;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
var DebugDefaults = (function () {
|
|
||||||
function DebugDefaults() {
|
|
||||||
}
|
|
||||||
DebugDefaults.verletParticle = 0xDC345E;
|
|
||||||
DebugDefaults.verletConstraintEdge = 0x433E36;
|
|
||||||
return DebugDefaults;
|
|
||||||
}());
|
|
||||||
es.DebugDefaults = DebugDefaults;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
var DebugDrawType;
|
|
||||||
(function (DebugDrawType) {
|
|
||||||
DebugDrawType[DebugDrawType["line"] = 0] = "line";
|
|
||||||
DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle";
|
|
||||||
DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel";
|
|
||||||
DebugDrawType[DebugDrawType["text"] = 3] = "text";
|
|
||||||
})(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {}));
|
|
||||||
var DebugDrawItem = (function () {
|
|
||||||
function DebugDrawItem(rectangle, color, duration) {
|
|
||||||
this.rectangle = rectangle;
|
|
||||||
this.color = color;
|
|
||||||
this.duration = duration;
|
|
||||||
this.drawType = DebugDrawType.hollowRectangle;
|
|
||||||
}
|
|
||||||
DebugDrawItem.prototype.draw = function (shape) {
|
|
||||||
switch (this.drawType) {
|
|
||||||
case DebugDrawType.line:
|
|
||||||
break;
|
|
||||||
case DebugDrawType.hollowRectangle:
|
|
||||||
break;
|
|
||||||
case DebugDrawType.pixel:
|
|
||||||
break;
|
|
||||||
case DebugDrawType.text:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this.duration -= es.Time.deltaTime;
|
|
||||||
return this.duration < 0;
|
|
||||||
};
|
|
||||||
return DebugDrawItem;
|
|
||||||
}());
|
|
||||||
es.DebugDrawItem = DebugDrawItem;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
|
||||||
var Component = (function (_super) {
|
|
||||||
__extends(Component, _super);
|
|
||||||
function Component() {
|
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
||||||
_this.updateInterval = 1;
|
|
||||||
_this._enabled = true;
|
|
||||||
_this._updateOrder = 0;
|
|
||||||
return _this;
|
|
||||||
}
|
|
||||||
Object.defineProperty(Component.prototype, "transform", {
|
|
||||||
get: function () {
|
|
||||||
return this.entity.transform;
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Component.prototype, "enabled", {
|
|
||||||
get: function () {
|
|
||||||
return this.entity ? this.entity.enabled && this._enabled : this._enabled;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this.setEnabled(value);
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Object.defineProperty(Component.prototype, "updateOrder", {
|
|
||||||
get: function () {
|
|
||||||
return this._updateOrder;
|
|
||||||
},
|
|
||||||
set: function (value) {
|
|
||||||
this.setUpdateOrder(value);
|
|
||||||
},
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true
|
|
||||||
});
|
|
||||||
Component.prototype.initialize = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onAddedToEntity = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onRemovedFromEntity = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onEntityTransformChanged = function (comp) {
|
|
||||||
};
|
|
||||||
Component.prototype.debugRender = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onEnabled = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.onDisabled = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.update = function () {
|
|
||||||
};
|
|
||||||
Component.prototype.setEnabled = function (isEnabled) {
|
|
||||||
if (this._enabled != isEnabled) {
|
|
||||||
this._enabled = isEnabled;
|
|
||||||
if (this._enabled) {
|
|
||||||
this.onEnabled();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.onDisabled();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
Component.prototype.setUpdateOrder = function (updateOrder) {
|
|
||||||
if (this._updateOrder != updateOrder) {
|
|
||||||
this._updateOrder = updateOrder;
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
Component.prototype.clone = function () {
|
|
||||||
var component = ObjectUtils.clone(this);
|
|
||||||
component.entity = null;
|
|
||||||
return component;
|
|
||||||
};
|
|
||||||
return Component;
|
|
||||||
}(egret.HashObject));
|
|
||||||
es.Component = Component;
|
|
||||||
})(es || (es = {}));
|
|
||||||
var es;
|
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var Core = (function (_super) {
|
var Core = (function (_super) {
|
||||||
__extends(Core, _super);
|
__extends(Core, _super);
|
||||||
@@ -1289,6 +1137,182 @@ var es;
|
|||||||
es.Core = Core;
|
es.Core = Core;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Colors = (function () {
|
||||||
|
function Colors() {
|
||||||
|
}
|
||||||
|
Colors.renderableBounds = 0xffff00;
|
||||||
|
Colors.renderableCenter = 0x9932CC;
|
||||||
|
Colors.colliderBounds = 0x555555;
|
||||||
|
return Colors;
|
||||||
|
}());
|
||||||
|
es.Colors = Colors;
|
||||||
|
var Size = (function () {
|
||||||
|
function Size() {
|
||||||
|
}
|
||||||
|
Object.defineProperty(Size, "lineSizeMultiplier", {
|
||||||
|
get: function () {
|
||||||
|
return Math.max(Math.ceil(es.Core.scene.x / es.Core.scene.width), 1);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
return Size;
|
||||||
|
}());
|
||||||
|
es.Size = Size;
|
||||||
|
var Debug = (function () {
|
||||||
|
function Debug() {
|
||||||
|
}
|
||||||
|
Debug.drawHollowRect = function (rectanle, color, duration) {
|
||||||
|
if (duration === void 0) { duration = 0; }
|
||||||
|
this._debugDrawItems.push(new es.DebugDrawItem(rectanle, color, duration));
|
||||||
|
};
|
||||||
|
Debug.render = function () {
|
||||||
|
if (this._debugDrawItems.length > 0) {
|
||||||
|
var debugShape = new egret.Shape();
|
||||||
|
if (es.Core.scene) {
|
||||||
|
es.Core.scene.addChild(debugShape);
|
||||||
|
}
|
||||||
|
for (var i = this._debugDrawItems.length - 1; i >= 0; i--) {
|
||||||
|
var item = this._debugDrawItems[i];
|
||||||
|
if (item.draw(debugShape))
|
||||||
|
this._debugDrawItems.removeAt(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Debug._debugDrawItems = [];
|
||||||
|
return Debug;
|
||||||
|
}());
|
||||||
|
es.Debug = Debug;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var DebugDefaults = (function () {
|
||||||
|
function DebugDefaults() {
|
||||||
|
}
|
||||||
|
DebugDefaults.verletParticle = 0xDC345E;
|
||||||
|
DebugDefaults.verletConstraintEdge = 0x433E36;
|
||||||
|
return DebugDefaults;
|
||||||
|
}());
|
||||||
|
es.DebugDefaults = DebugDefaults;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var DebugDrawType;
|
||||||
|
(function (DebugDrawType) {
|
||||||
|
DebugDrawType[DebugDrawType["line"] = 0] = "line";
|
||||||
|
DebugDrawType[DebugDrawType["hollowRectangle"] = 1] = "hollowRectangle";
|
||||||
|
DebugDrawType[DebugDrawType["pixel"] = 2] = "pixel";
|
||||||
|
DebugDrawType[DebugDrawType["text"] = 3] = "text";
|
||||||
|
})(DebugDrawType = es.DebugDrawType || (es.DebugDrawType = {}));
|
||||||
|
var DebugDrawItem = (function () {
|
||||||
|
function DebugDrawItem(rectangle, color, duration) {
|
||||||
|
this.rectangle = rectangle;
|
||||||
|
this.color = color;
|
||||||
|
this.duration = duration;
|
||||||
|
this.drawType = DebugDrawType.hollowRectangle;
|
||||||
|
}
|
||||||
|
DebugDrawItem.prototype.draw = function (shape) {
|
||||||
|
switch (this.drawType) {
|
||||||
|
case DebugDrawType.line:
|
||||||
|
break;
|
||||||
|
case DebugDrawType.hollowRectangle:
|
||||||
|
break;
|
||||||
|
case DebugDrawType.pixel:
|
||||||
|
break;
|
||||||
|
case DebugDrawType.text:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.duration -= es.Time.deltaTime;
|
||||||
|
return this.duration < 0;
|
||||||
|
};
|
||||||
|
return DebugDrawItem;
|
||||||
|
}());
|
||||||
|
es.DebugDrawItem = DebugDrawItem;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var Component = (function (_super) {
|
||||||
|
__extends(Component, _super);
|
||||||
|
function Component() {
|
||||||
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this.updateInterval = 1;
|
||||||
|
_this.debugDisplayObject = new egret.DisplayObjectContainer();
|
||||||
|
_this._enabled = true;
|
||||||
|
_this._updateOrder = 0;
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
Object.defineProperty(Component.prototype, "transform", {
|
||||||
|
get: function () {
|
||||||
|
return this.entity.transform;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Component.prototype, "enabled", {
|
||||||
|
get: function () {
|
||||||
|
return this.entity ? this.entity.enabled && this._enabled : this._enabled;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setEnabled(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Object.defineProperty(Component.prototype, "updateOrder", {
|
||||||
|
get: function () {
|
||||||
|
return this._updateOrder;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setUpdateOrder(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
Component.prototype.initialize = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onAddedToEntity = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onRemovedFromEntity = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onEntityTransformChanged = function (comp) {
|
||||||
|
};
|
||||||
|
Component.prototype.debugRender = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onEnabled = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.onDisabled = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.update = function () {
|
||||||
|
};
|
||||||
|
Component.prototype.setEnabled = function (isEnabled) {
|
||||||
|
if (this._enabled != isEnabled) {
|
||||||
|
this._enabled = isEnabled;
|
||||||
|
if (this._enabled) {
|
||||||
|
this.onEnabled();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.onDisabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Component.prototype.setUpdateOrder = function (updateOrder) {
|
||||||
|
if (this._updateOrder != updateOrder) {
|
||||||
|
this._updateOrder = updateOrder;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
Component.prototype.clone = function () {
|
||||||
|
var component = ObjectUtils.clone(this);
|
||||||
|
component.entity = null;
|
||||||
|
return component;
|
||||||
|
};
|
||||||
|
return Component;
|
||||||
|
}(egret.HashObject));
|
||||||
|
es.Component = Component;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var CoreEvents;
|
var CoreEvents;
|
||||||
(function (CoreEvents) {
|
(function (CoreEvents) {
|
||||||
@@ -2450,7 +2474,7 @@ var es;
|
|||||||
this.follow(this._targetEntity, this._cameraStyle);
|
this.follow(this._targetEntity, this._cameraStyle);
|
||||||
};
|
};
|
||||||
Camera.prototype.update = function () {
|
Camera.prototype.update = function () {
|
||||||
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
|
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.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.y = this.position.y - halfScreen.y * es.Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||||
@@ -2465,7 +2489,7 @@ var es;
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Camera.prototype.clampToMapSize = function (position) {
|
Camera.prototype.clampToMapSize = function (position) {
|
||||||
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5)).add(new es.Vector2(this.mapSize.x, this.mapSize.y));
|
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);
|
var cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||||
};
|
};
|
||||||
@@ -2645,8 +2669,11 @@ var es;
|
|||||||
function RenderableComponent() {
|
function RenderableComponent() {
|
||||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
_this.displayObject = new egret.DisplayObject();
|
_this.displayObject = new egret.DisplayObject();
|
||||||
|
_this.hollowShape = new egret.Shape();
|
||||||
|
_this.pixelShape = new egret.Shape();
|
||||||
_this.color = 0x000000;
|
_this.color = 0x000000;
|
||||||
_this._areBoundsDirty = true;
|
_this._areBoundsDirty = true;
|
||||||
|
_this.debugRenderEnabled = true;
|
||||||
_this._localOffset = es.Vector2.zero;
|
_this._localOffset = es.Vector2.zero;
|
||||||
_this._renderLayer = 0;
|
_this._renderLayer = 0;
|
||||||
_this._bounds = new es.Rectangle();
|
_this._bounds = new es.Rectangle();
|
||||||
@@ -2716,6 +2743,27 @@ var es;
|
|||||||
RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
|
RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
|
||||||
this._areBoundsDirty = true;
|
this._areBoundsDirty = true;
|
||||||
};
|
};
|
||||||
|
RenderableComponent.prototype.debugRender = function () {
|
||||||
|
if (!this.debugRenderEnabled)
|
||||||
|
return;
|
||||||
|
if (!this.hollowShape.parent)
|
||||||
|
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.endFill();
|
||||||
|
};
|
||||||
RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
|
RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
|
||||||
if (!camera)
|
if (!camera)
|
||||||
return false;
|
return false;
|
||||||
@@ -2759,9 +2807,11 @@ var es;
|
|||||||
};
|
};
|
||||||
RenderableComponent.prototype.onBecameVisible = function () {
|
RenderableComponent.prototype.onBecameVisible = function () {
|
||||||
this.displayObject.visible = this.isVisible;
|
this.displayObject.visible = this.isVisible;
|
||||||
|
this.debugDisplayObject.visible = this.isVisible;
|
||||||
};
|
};
|
||||||
RenderableComponent.prototype.onBecameInvisible = function () {
|
RenderableComponent.prototype.onBecameInvisible = function () {
|
||||||
this.displayObject.visible = this.isVisible;
|
this.displayObject.visible = this.isVisible;
|
||||||
|
this.debugDisplayObject.visible = this.isVisible;
|
||||||
};
|
};
|
||||||
return RenderableComponent;
|
return RenderableComponent;
|
||||||
}(es.Component));
|
}(es.Component));
|
||||||
@@ -3711,6 +3761,10 @@ var es;
|
|||||||
__extends(BoxCollider, _super);
|
__extends(BoxCollider, _super);
|
||||||
function BoxCollider() {
|
function BoxCollider() {
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
|
_this.hollowShape = new egret.Shape();
|
||||||
|
_this.polygonShape = new egret.Shape();
|
||||||
|
_this.pixelShape1 = new egret.Shape();
|
||||||
|
_this.pixelShape2 = new egret.Shape();
|
||||||
_this.shape = new es.Box(1, 1);
|
_this.shape = new es.Box(1, 1);
|
||||||
_this._colliderRequiresAutoSizing = true;
|
_this._colliderRequiresAutoSizing = true;
|
||||||
return _this;
|
return _this;
|
||||||
@@ -3770,6 +3824,22 @@ var es;
|
|||||||
es.Physics.updateCollider(this);
|
es.Physics.updateCollider(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
BoxCollider.prototype.debugRender = function () {
|
||||||
|
var poly = this.shape;
|
||||||
|
if (!this.hollowShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.hollowShape);
|
||||||
|
if (!this.polygonShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.polygonShape);
|
||||||
|
if (!this.pixelShape1.parent)
|
||||||
|
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();
|
||||||
|
};
|
||||||
BoxCollider.prototype.toString = function () {
|
BoxCollider.prototype.toString = function () {
|
||||||
return "[BoxCollider: bounds: " + this.bounds + "]";
|
return "[BoxCollider: bounds: " + this.bounds + "]";
|
||||||
};
|
};
|
||||||
@@ -4122,9 +4192,12 @@ var es;
|
|||||||
for (var i = 0; i < this._components.length; i++) {
|
for (var i = 0; i < this._components.length; i++) {
|
||||||
var component = this._components[i];
|
var component = this._components[i];
|
||||||
if (component instanceof es.RenderableComponent) {
|
if (component instanceof es.RenderableComponent) {
|
||||||
this._entity.scene.removeChild(component.displayObject);
|
if (component.displayObject.parent)
|
||||||
|
component.displayObject.parent.removeChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
}
|
}
|
||||||
|
if (component.debugDisplayObject.parent)
|
||||||
|
component.debugDisplayObject.parent.removeChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
}
|
}
|
||||||
@@ -4136,6 +4209,7 @@ var es;
|
|||||||
this._entity.scene.addChild(component.displayObject);
|
this._entity.scene.addChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.add(component);
|
this._entity.scene.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
@@ -4155,6 +4229,7 @@ var es;
|
|||||||
this._entity.scene.addChild(component.displayObject);
|
this._entity.scene.addChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.add(component);
|
this._entity.scene.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
this._components.push(component);
|
this._components.push(component);
|
||||||
@@ -4182,6 +4257,8 @@ var es;
|
|||||||
component.displayObject.parent.removeChild(component.displayObject);
|
component.displayObject.parent.removeChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
}
|
}
|
||||||
|
if (component.debugDisplayObject.parent)
|
||||||
|
component.debugDisplayObject.parent.removeChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(es.ComponentTypeManager.getIndexFor(component), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
component.onRemovedFromEntity();
|
component.onRemovedFromEntity();
|
||||||
@@ -6854,7 +6931,7 @@ var es;
|
|||||||
else
|
else
|
||||||
p2 = this.points[i + 1];
|
p2 = this.points[i + 1];
|
||||||
var perp = es.Vector2Ext.perpendicular(p1, p2);
|
var perp = es.Vector2Ext.perpendicular(p1, p2);
|
||||||
perp = es.Vector2.normalize(perp);
|
es.Vector2Ext.normalize(perp);
|
||||||
this._edgeNormals[i] = perp;
|
this._edgeNormals[i] = perp;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -6862,14 +6939,14 @@ var es;
|
|||||||
var verts = new Array(vertCount);
|
var verts = new Array(vertCount);
|
||||||
for (var i = 0; i < vertCount; i++) {
|
for (var i = 0; i < vertCount; i++) {
|
||||||
var a = 2 * Math.PI * (i / vertCount);
|
var a = 2 * Math.PI * (i / vertCount);
|
||||||
verts[i] = es.Vector2.multiply(new es.Vector2(Math.cos(a), Math.sin(a)), new es.Vector2(radius));
|
verts[i] = new es.Vector2(Math.cos(a) * radius, Math.sin(a) * radius);
|
||||||
}
|
}
|
||||||
return verts;
|
return verts;
|
||||||
};
|
};
|
||||||
Polygon.recenterPolygonVerts = function (points) {
|
Polygon.recenterPolygonVerts = function (points) {
|
||||||
var center = this.findPolygonCenter(points);
|
var center = this.findPolygonCenter(points);
|
||||||
for (var i = 0; i < points.length; i++)
|
for (var i = 0; i < points.length; i++)
|
||||||
points[i] = es.Vector2.subtract(points[i], center);
|
points[i].subtract(center);
|
||||||
};
|
};
|
||||||
Polygon.findPolygonCenter = function (points) {
|
Polygon.findPolygonCenter = function (points) {
|
||||||
var x = 0, y = 0;
|
var x = 0, y = 0;
|
||||||
@@ -6893,7 +6970,8 @@ var es;
|
|||||||
};
|
};
|
||||||
Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) {
|
Polygon.getClosestPointOnPolygonToPoint = function (points, point, distanceSquared, edgeNormal) {
|
||||||
distanceSquared = Number.MAX_VALUE;
|
distanceSquared = Number.MAX_VALUE;
|
||||||
edgeNormal = new es.Vector2(0, 0);
|
edgeNormal.x = 0;
|
||||||
|
edgeNormal.y = 0;
|
||||||
var closestPoint = new es.Vector2(0, 0);
|
var closestPoint = new es.Vector2(0, 0);
|
||||||
var tempDistanceSquared;
|
var tempDistanceSquared;
|
||||||
for (var i = 0; i < points.length; i++) {
|
for (var i = 0; i < points.length; i++) {
|
||||||
@@ -6906,7 +6984,8 @@ var es;
|
|||||||
distanceSquared = tempDistanceSquared;
|
distanceSquared = tempDistanceSquared;
|
||||||
closestPoint = closest;
|
closestPoint = closest;
|
||||||
var line = es.Vector2.subtract(points[j], points[i]);
|
var line = es.Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal = new es.Vector2(-line.y, line.x);
|
edgeNormal.x = -line.y;
|
||||||
|
edgeNormal.y = line.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
es.Vector2Ext.normalize(edgeNormal);
|
es.Vector2Ext.normalize(edgeNormal);
|
||||||
@@ -7295,7 +7374,7 @@ var es;
|
|||||||
result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds);
|
result.normal = es.Vector2.subtract(circle.position, closestPointOnBounds);
|
||||||
var depth = result.normal.length() - circle.radius;
|
var depth = result.normal.length() - circle.radius;
|
||||||
result.point = closestPointOnBounds;
|
result.point = closestPointOnBounds;
|
||||||
result.normal = es.Vector2Ext.normalize(result.normal);
|
es.Vector2Ext.normalize(result.normal);
|
||||||
result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal);
|
result.minimumTranslationVector = es.Vector2.multiply(new es.Vector2(depth), result.normal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -10379,12 +10458,11 @@ var es;
|
|||||||
Vector2Ext.normalize = function (vec) {
|
Vector2Ext.normalize = function (vec) {
|
||||||
var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
var magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
||||||
if (magnitude > es.MathHelper.Epsilon) {
|
if (magnitude > es.MathHelper.Epsilon) {
|
||||||
vec = es.Vector2.divide(vec, new es.Vector2(magnitude));
|
vec.divide(new es.Vector2(magnitude));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vec.x = vec.y = 0;
|
vec.x = vec.y = 0;
|
||||||
}
|
}
|
||||||
return vec;
|
|
||||||
};
|
};
|
||||||
Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) {
|
Vector2Ext.transformA = function (sourceArray, sourceIndex, matrix, destinationArray, destinationIndex, length) {
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,4 +1,17 @@
|
|||||||
|
///<reference path="../ECS/Core.ts" />
|
||||||
module es {
|
module es {
|
||||||
|
export class Colors {
|
||||||
|
public static renderableBounds = 0xffff00;
|
||||||
|
public static renderableCenter = 0x9932CC;
|
||||||
|
public static colliderBounds = 0x555555;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Size {
|
||||||
|
public static get lineSizeMultiplier(){
|
||||||
|
return Math.max(Math.ceil(Core.scene.x / Core.scene.width), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class Debug {
|
export class Debug {
|
||||||
private static _debugDrawItems: DebugDrawItem[] = [];
|
private static _debugDrawItems: DebugDrawItem[] = [];
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ module es {
|
|||||||
* 更新该组件的时间间隔。这与实体的更新间隔无关。
|
* 更新该组件的时间间隔。这与实体的更新间隔无关。
|
||||||
*/
|
*/
|
||||||
public updateInterval: number = 1;
|
public updateInterval: number = 1;
|
||||||
|
/**
|
||||||
|
* 用于装载debug使用的显示容器
|
||||||
|
*/
|
||||||
|
public debugDisplayObject: egret.DisplayObjectContainer = new egret.DisplayObjectContainer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 快速访问 this.entity.transform
|
* 快速访问 this.entity.transform
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ module es {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public update() {
|
public update() {
|
||||||
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5));
|
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.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.y = this.position.y - halfScreen.y * Core.scene.scaleY + this.deadzone.y + this.focusOffset.y;
|
||||||
this._worldSpaceDeadZone.width = this.deadzone.width;
|
this._worldSpaceDeadZone.width = this.deadzone.width;
|
||||||
@@ -385,7 +385,7 @@ module es {
|
|||||||
* @param position
|
* @param position
|
||||||
*/
|
*/
|
||||||
public clampToMapSize(position: Vector2) {
|
public clampToMapSize(position: Vector2) {
|
||||||
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5)).add(new Vector2(this.mapSize.x, this.mapSize.y));
|
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);
|
let cameraMax = new Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||||
|
|
||||||
return Vector2.clamp(position, halfScreen, cameraMax);
|
return Vector2.clamp(position, halfScreen, cameraMax);
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
///<reference path="./Collider.ts" />
|
///<reference path="./Collider.ts" />
|
||||||
module es {
|
module es {
|
||||||
export class BoxCollider extends Collider {
|
export class BoxCollider extends Collider {
|
||||||
|
public hollowShape: egret.Shape = new egret.Shape();
|
||||||
|
public polygonShape: egret.Shape = new egret.Shape();
|
||||||
|
public pixelShape1: egret.Shape = new egret.Shape();
|
||||||
|
public pixelShape2: egret.Shape = new egret.Shape();
|
||||||
/**
|
/**
|
||||||
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
||||||
*/
|
*/
|
||||||
@@ -92,6 +96,27 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public debugRender() {
|
||||||
|
let poly = this.shape;
|
||||||
|
if (!this.hollowShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.hollowShape);
|
||||||
|
|
||||||
|
if (!this.polygonShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.polygonShape);
|
||||||
|
|
||||||
|
if (!this.pixelShape1.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.pixelShape1);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
public toString() {
|
public toString() {
|
||||||
return `[BoxCollider: bounds: ${this.bounds}]`;
|
return `[BoxCollider: bounds: ${this.bounds}]`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
module es {
|
module es {
|
||||||
export abstract class Collider extends Component {
|
export abstract class Collider extends Component {
|
||||||
|
public debug
|
||||||
/**
|
/**
|
||||||
* 对撞机的基本形状
|
* 对撞机的基本形状
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ module es {
|
|||||||
* 用于装载egret显示对象
|
* 用于装载egret显示对象
|
||||||
*/
|
*/
|
||||||
public displayObject: egret.DisplayObject = new egret.DisplayObject();
|
public displayObject: egret.DisplayObject = new egret.DisplayObject();
|
||||||
|
public hollowShape: egret.Shape = new egret.Shape();
|
||||||
|
public pixelShape: egret.Shape = new egret.Shape();
|
||||||
/**
|
/**
|
||||||
* 用于着色器处理精灵
|
* 用于着色器处理精灵
|
||||||
*/
|
*/
|
||||||
@@ -30,6 +32,7 @@ module es {
|
|||||||
return this.bounds.height;
|
return this.bounds.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public debugRenderEnabled: boolean = true;
|
||||||
protected _localOffset: Vector2 = Vector2.zero;
|
protected _localOffset: Vector2 = Vector2.zero;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -109,6 +112,32 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public abstract render(camera: Camera);
|
public abstract render(camera: Camera);
|
||||||
|
|
||||||
|
public debugRender() {
|
||||||
|
if (!this.debugRenderEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!this.hollowShape.parent)
|
||||||
|
this.debugDisplayObject.addChild(this.hollowShape);
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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.endFill();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果renderableComponent的边界与camera.bounds相交 返回true
|
* 如果renderableComponent的边界与camera.bounds相交 返回true
|
||||||
* 用于处理isVisible标志的状态开关
|
* 用于处理isVisible标志的状态开关
|
||||||
@@ -184,6 +213,7 @@ module es {
|
|||||||
*/
|
*/
|
||||||
protected onBecameVisible() {
|
protected onBecameVisible() {
|
||||||
this.displayObject.visible = this.isVisible;
|
this.displayObject.visible = this.isVisible;
|
||||||
|
this.debugDisplayObject.visible = this.isVisible;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,6 +222,7 @@ module es {
|
|||||||
*/
|
*/
|
||||||
protected onBecameInvisible() {
|
protected onBecameInvisible() {
|
||||||
this.displayObject.visible = this.isVisible;
|
this.displayObject.visible = this.isVisible;
|
||||||
|
this.debugDisplayObject.visible = this.isVisible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,10 +77,13 @@ module es {
|
|||||||
|
|
||||||
// 处理渲染层列表
|
// 处理渲染层列表
|
||||||
if (component instanceof RenderableComponent) {
|
if (component instanceof RenderableComponent) {
|
||||||
this._entity.scene.removeChild(component.displayObject);
|
if (component.displayObject.parent)
|
||||||
|
component.displayObject.parent.removeChild(component.displayObject);
|
||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (component.debugDisplayObject.parent)
|
||||||
|
component.debugDisplayObject.parent.removeChild(component.debugDisplayObject);
|
||||||
|
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
@@ -96,6 +99,7 @@ module es {
|
|||||||
this._entity.scene.renderableComponents.add(component);
|
this._entity.scene.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
}
|
}
|
||||||
@@ -122,7 +126,7 @@ module es {
|
|||||||
this._entity.scene.renderableComponents.add(component);
|
this._entity.scene.renderableComponents.add(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._entity.scene.addChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component));
|
||||||
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
this._entity.scene.entityProcessors.onComponentAdded(this._entity);
|
||||||
|
|
||||||
@@ -162,7 +166,8 @@ module es {
|
|||||||
this._entity.scene.renderableComponents.remove(component);
|
this._entity.scene.renderableComponents.remove(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (component.debugDisplayObject.parent)
|
||||||
|
component.debugDisplayObject.parent.removeChild(component.debugDisplayObject);
|
||||||
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
|
this._entity.componentBits.set(ComponentTypeManager.getIndexFor(component), false);
|
||||||
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
this._entity.scene.entityProcessors.onComponentRemoved(this._entity);
|
||||||
|
|
||||||
|
|||||||
@@ -88,10 +88,11 @@ module es {
|
|||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
public static normalize(value: Vector2) {
|
public static normalize(value: Vector2) {
|
||||||
let val = 1 / Math.sqrt((value.x * value.x) + (value.y * value.y));
|
let nValue = new Vector2(value.x, value.y);
|
||||||
value.x *= val;
|
let val = 1 / Math.sqrt((nValue.x * nValue.x) + (nValue.y * nValue.y));
|
||||||
value.y *= val;
|
nValue.x *= val;
|
||||||
return value;
|
nValue.y *= val;
|
||||||
|
return nValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ module es {
|
|||||||
p2 = this.points[i + 1];
|
p2 = this.points[i + 1];
|
||||||
|
|
||||||
let perp = Vector2Ext.perpendicular(p1, p2);
|
let perp = Vector2Ext.perpendicular(p1, p2);
|
||||||
perp = Vector2.normalize(perp);
|
Vector2Ext.normalize(perp);
|
||||||
this._edgeNormals[i] = perp;
|
this._edgeNormals[i] = perp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ module es {
|
|||||||
|
|
||||||
for (let i = 0; i < vertCount; i++) {
|
for (let i = 0; i < vertCount; i++) {
|
||||||
let a = 2 * Math.PI * (i / vertCount);
|
let a = 2 * Math.PI * (i / vertCount);
|
||||||
verts[i] = Vector2.multiply(new Vector2(Math.cos(a), Math.sin(a)), new Vector2(radius));
|
verts[i] = new Vector2(Math.cos(a) * radius, Math.sin(a) * radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
return verts;
|
return verts;
|
||||||
@@ -116,7 +116,7 @@ module es {
|
|||||||
public static recenterPolygonVerts(points: Vector2[]) {
|
public static recenterPolygonVerts(points: Vector2[]) {
|
||||||
let center = this.findPolygonCenter(points);
|
let center = this.findPolygonCenter(points);
|
||||||
for (let i = 0; i < points.length; i++)
|
for (let i = 0; i < points.length; i++)
|
||||||
points[i] = Vector2.subtract(points[i], center);
|
points[i].subtract(center);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,9 +163,10 @@ module es {
|
|||||||
* @param distanceSquared
|
* @param distanceSquared
|
||||||
* @param edgeNormal
|
* @param edgeNormal
|
||||||
*/
|
*/
|
||||||
public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: number, edgeNormal: Vector2): Vector2 {
|
public static getClosestPointOnPolygonToPoint(points: Vector2[], point: Vector2, distanceSquared: Number, edgeNormal: Vector2): Vector2 {
|
||||||
distanceSquared = Number.MAX_VALUE;
|
distanceSquared = Number.MAX_VALUE;
|
||||||
edgeNormal = new Vector2(0, 0);
|
edgeNormal.x = 0;
|
||||||
|
edgeNormal.y = 0;
|
||||||
let closestPoint = new Vector2(0, 0);
|
let closestPoint = new Vector2(0, 0);
|
||||||
|
|
||||||
let tempDistanceSquared;
|
let tempDistanceSquared;
|
||||||
@@ -183,7 +184,8 @@ module es {
|
|||||||
|
|
||||||
// 求直线的法线
|
// 求直线的法线
|
||||||
let line = Vector2.subtract(points[j], points[i]);
|
let line = Vector2.subtract(points[j], points[i]);
|
||||||
edgeNormal = new Vector2(-line.y, line.x);
|
edgeNormal.x = -line.y;
|
||||||
|
edgeNormal.y = line.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ module es {
|
|||||||
let depth = result.normal.length() - circle.radius;
|
let depth = result.normal.length() - circle.radius;
|
||||||
|
|
||||||
result.point = closestPointOnBounds;
|
result.point = closestPointOnBounds;
|
||||||
result.normal = Vector2Ext.normalize(result.normal);
|
Vector2Ext.normalize(result.normal);
|
||||||
result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal);
|
result.minimumTranslationVector = Vector2.multiply(new Vector2(depth), result.normal);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -261,6 +261,7 @@ module es {
|
|||||||
*
|
*
|
||||||
* @param first
|
* @param first
|
||||||
* @param second
|
* @param second
|
||||||
|
* @param result
|
||||||
*/
|
*/
|
||||||
public static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean {
|
public static circleToCircle(first: Circle, second: Circle, result: CollisionResult): boolean {
|
||||||
let distanceSquared = Vector2.distanceSquared(first.position, second.position);
|
let distanceSquared = Vector2.distanceSquared(first.position, second.position);
|
||||||
|
|||||||
@@ -36,12 +36,10 @@ module es {
|
|||||||
public static normalize(vec: Vector2) {
|
public static normalize(vec: Vector2) {
|
||||||
let magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
let magnitude = Math.sqrt((vec.x * vec.x) + (vec.y * vec.y));
|
||||||
if (magnitude > MathHelper.Epsilon) {
|
if (magnitude > MathHelper.Epsilon) {
|
||||||
vec = Vector2.divide(vec, new Vector2(magnitude));
|
vec.divide(new Vector2(magnitude));
|
||||||
} else {
|
} else {
|
||||||
vec.x = vec.y = 0;
|
vec.x = vec.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return vec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user