修复box因缺少初始化报错问题
This commit is contained in:
6
demo/libs/framework/framework.d.ts
vendored
6
demo/libs/framework/framework.d.ts
vendored
@@ -402,7 +402,7 @@ declare abstract class Collider extends Component {
|
|||||||
protected _isParentEntityAddedToScene: any;
|
protected _isParentEntityAddedToScene: any;
|
||||||
protected _colliderRequiresAutoSizing: any;
|
protected _colliderRequiresAutoSizing: any;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
protected _isColliderRegisterd: any;
|
protected _isColliderRegistered: any;
|
||||||
readonly bounds: Rectangle;
|
readonly bounds: Rectangle;
|
||||||
localOffset: Vector2;
|
localOffset: Vector2;
|
||||||
setLocalOffset(offset: Vector2): void;
|
setLocalOffset(offset: Vector2): void;
|
||||||
@@ -701,7 +701,7 @@ declare class Polygon extends Shape {
|
|||||||
_edgeNormals: Vector2[];
|
_edgeNormals: Vector2[];
|
||||||
readonly edgeNormals: Vector2[];
|
readonly edgeNormals: Vector2[];
|
||||||
isBox: boolean;
|
isBox: boolean;
|
||||||
constructor(vertCount: number, radius: number);
|
constructor(points: Vector2[], isBox?: boolean);
|
||||||
private buildEdgeNormals;
|
private buildEdgeNormals;
|
||||||
setPoints(points: Vector2[]): void;
|
setPoints(points: Vector2[]): void;
|
||||||
collidesWithShape(other: Shape): CollisionResult;
|
collidesWithShape(other: Shape): CollisionResult;
|
||||||
@@ -721,6 +721,8 @@ declare class Polygon extends Shape {
|
|||||||
declare class Box extends Polygon {
|
declare class Box extends Polygon {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
constructor(width: number, height: number);
|
||||||
|
private static buildBox;
|
||||||
updateBox(width: number, height: number): void;
|
updateBox(width: number, height: number): void;
|
||||||
containsPoint(point: Vector2): boolean;
|
containsPoint(point: Vector2): boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1186,7 +1186,7 @@ var Transform = (function () {
|
|||||||
this._worldInverseTransform = Matrix2D.identity;
|
this._worldInverseTransform = Matrix2D.identity;
|
||||||
this._rotation = 0;
|
this._rotation = 0;
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this._scale = this._localScale = new Vector2(0, 0);
|
this._scale = this._localScale = Vector2.one;
|
||||||
this._children = [];
|
this._children = [];
|
||||||
}
|
}
|
||||||
Object.defineProperty(Transform.prototype, "childCount", {
|
Object.defineProperty(Transform.prototype, "childCount", {
|
||||||
@@ -1882,16 +1882,16 @@ var Collider = (function (_super) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Collider.prototype.registerColliderWithPhysicsSystem = function () {
|
Collider.prototype.registerColliderWithPhysicsSystem = function () {
|
||||||
if (this._isParentEntityAddedToScene && !this._isColliderRegisterd) {
|
if (this._isParentEntityAddedToScene && !this._isColliderRegistered) {
|
||||||
Physics.addCollider(this);
|
Physics.addCollider(this);
|
||||||
this._isColliderRegisterd = true;
|
this._isColliderRegistered = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Collider.prototype.unregisterColliderWithPhysicsSystem = function () {
|
Collider.prototype.unregisterColliderWithPhysicsSystem = function () {
|
||||||
if (this._isParentEntityAddedToScene && this._isColliderRegisterd) {
|
if (this._isParentEntityAddedToScene && this._isColliderRegistered) {
|
||||||
Physics.removeCollider(this);
|
Physics.removeCollider(this);
|
||||||
}
|
}
|
||||||
this._isColliderRegisterd = false;
|
this._isColliderRegistered = false;
|
||||||
};
|
};
|
||||||
Collider.prototype.overlaps = function (other) {
|
Collider.prototype.overlaps = function (other) {
|
||||||
return this.shape.overlaps(other.shape);
|
return this.shape.overlaps(other.shape);
|
||||||
@@ -1938,7 +1938,7 @@ var Collider = (function (_super) {
|
|||||||
this._isRotationDirty = true;
|
this._isRotationDirty = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this._isColliderRegisterd)
|
if (this._isColliderRegistered)
|
||||||
Physics.updateCollider(this);
|
Physics.updateCollider(this);
|
||||||
};
|
};
|
||||||
Collider.prototype.onEnabled = function () {
|
Collider.prototype.onEnabled = function () {
|
||||||
@@ -2308,20 +2308,30 @@ var ComponentList = (function () {
|
|||||||
components = [];
|
components = [];
|
||||||
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 (typeof (typeName) == "string" && egret.is(component, typeName))
|
if (typeof (typeName) == "string") {
|
||||||
|
if (egret.is(component, typeName)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
else if (component instanceof typeName) {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
||||||
var component = this._componentsToAdd[i];
|
var component = this._componentsToAdd[i];
|
||||||
if (typeof (typeName) == "string" && egret.is(component, typeName))
|
if (typeof (typeName) == "string") {
|
||||||
|
if (egret.is(component, typeName)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
else if (component instanceof typeName) {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return components;
|
return components;
|
||||||
};
|
};
|
||||||
ComponentList.prototype.update = function () {
|
ComponentList.prototype.update = function () {
|
||||||
@@ -3099,9 +3109,13 @@ var ColliderTriggerHelper = (function () {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
this._previousTriggerIntersections.forEach(function (pair) { return _this.notifyTriggerListeners(pair, false); });
|
for (var i = 0; i < this._previousTriggerIntersections.length; i++) {
|
||||||
|
this.notifyTriggerListeners(this._previousTriggerIntersections[i], false);
|
||||||
|
}
|
||||||
this._previousTriggerIntersections.length = 0;
|
this._previousTriggerIntersections.length = 0;
|
||||||
tempIntersections.forEach(function (value) { return _this._previousTriggerIntersections.push(value); });
|
for (var i = 0; i < tempIntersections.length; i++) {
|
||||||
|
this._previousTriggerIntersections.push(tempIntersections[i]);
|
||||||
|
}
|
||||||
this._activeTriggerIntersections.length = 0;
|
this._activeTriggerIntersections.length = 0;
|
||||||
};
|
};
|
||||||
ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
|
ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
|
||||||
@@ -3296,11 +3310,12 @@ var Shape = (function () {
|
|||||||
}());
|
}());
|
||||||
var Polygon = (function (_super) {
|
var Polygon = (function (_super) {
|
||||||
__extends(Polygon, _super);
|
__extends(Polygon, _super);
|
||||||
function Polygon(vertCount, radius) {
|
function Polygon(points, isBox) {
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.isUnrotated = true;
|
_this.isUnrotated = true;
|
||||||
_this._areEdgeNormalsDirty = true;
|
_this._areEdgeNormalsDirty = true;
|
||||||
_this.setPoints(Polygon.buildSymmertricalPolygon(vertCount, radius));
|
_this.setPoints(points);
|
||||||
|
_this.isBox = isBox;
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
Object.defineProperty(Polygon.prototype, "edgeNormals", {
|
Object.defineProperty(Polygon.prototype, "edgeNormals", {
|
||||||
@@ -3329,11 +3344,12 @@ var Polygon = (function (_super) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Polygon.prototype.setPoints = function (points) {
|
Polygon.prototype.setPoints = function (points) {
|
||||||
var _this = this;
|
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.recalculateCenterAndEdgeNormals();
|
this.recalculateCenterAndEdgeNormals();
|
||||||
this._originalPoints = new Array(this.points.length);
|
this._originalPoints = [];
|
||||||
this.points.forEach(function (point) { return _this._originalPoints.push(point); });
|
for (var i = 0; i < this.points.length; i++) {
|
||||||
|
this._originalPoints.push(this.points[i]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Polygon.prototype.collidesWithShape = function (other) {
|
Polygon.prototype.collidesWithShape = function (other) {
|
||||||
var result = new CollisionResult();
|
var result = new CollisionResult();
|
||||||
@@ -3457,9 +3473,22 @@ var Polygon = (function (_super) {
|
|||||||
}(Shape));
|
}(Shape));
|
||||||
var Box = (function (_super) {
|
var Box = (function (_super) {
|
||||||
__extends(Box, _super);
|
__extends(Box, _super);
|
||||||
function Box() {
|
function Box(width, height) {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super.call(this, Box.buildBox(width, height), true) || this;
|
||||||
|
_this.width = width;
|
||||||
|
_this.height = height;
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
|
Box.buildBox = function (width, height) {
|
||||||
|
var halfWidth = width / 2;
|
||||||
|
var halfHeight = height / 2;
|
||||||
|
var verts = new Array(4);
|
||||||
|
verts[0] = new Vector2(-halfWidth, -halfHeight);
|
||||||
|
verts[1] = new Vector2(halfWidth, -halfHeight);
|
||||||
|
verts[2] = new Vector2(halfWidth, halfHeight);
|
||||||
|
verts[3] = new Vector2(-halfWidth, halfHeight);
|
||||||
|
return verts;
|
||||||
|
};
|
||||||
Box.prototype.updateBox = function (width, height) {
|
Box.prototype.updateBox = function (width, height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
@@ -3755,10 +3784,18 @@ var SpatialHash = (function () {
|
|||||||
this._overlapTestCircle.position = circleCenter;
|
this._overlapTestCircle.position = circleCenter;
|
||||||
var resultCounter = 0;
|
var resultCounter = 0;
|
||||||
var potentials = this.aabbBroadphase(bounds, null, layerMask);
|
var potentials = this.aabbBroadphase(bounds, null, layerMask);
|
||||||
potentials.forEach(function (collider) {
|
for (var i = 0; i < potentials.length; i++) {
|
||||||
|
var collider = potentials[i];
|
||||||
|
if (collider instanceof BoxCollider) {
|
||||||
|
results[resultCounter] = collider;
|
||||||
|
resultCounter++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error("overlapCircle against this collider type is not implemented!");
|
||||||
|
}
|
||||||
if (resultCounter == results.length)
|
if (resultCounter == results.length)
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
});
|
}
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
};
|
};
|
||||||
SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) {
|
SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) {
|
||||||
@@ -4020,7 +4057,7 @@ var Vector2Ext = (function () {
|
|||||||
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++) {
|
||||||
var position = sourceArray[sourceIndex + i];
|
var position = sourceArray[sourceIndex + i];
|
||||||
var destination = destinationArray[destinationIndex + 1];
|
var destination = destinationArray[destinationIndex + i];
|
||||||
destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
||||||
destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
||||||
destinationArray[destinationIndex + i] = destination;
|
destinationArray[destinationIndex + i] = destination;
|
||||||
|
|||||||
2
demo/libs/framework/framework.min.js
vendored
2
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -105,7 +105,7 @@ class Main extends eui.UILayer {
|
|||||||
new Vector2(0, 10),
|
new Vector2(0, 10),
|
||||||
new Vector2(0, 0)]));
|
new Vector2(0, 0)]));
|
||||||
player.addComponent(new SpawnComponent(EnemyType.worm));
|
player.addComponent(new SpawnComponent(EnemyType.worm));
|
||||||
player.addComponent(new BoxCollider()).setSize(100, 100);
|
player.addComponent(new BoxCollider()).setSize(100, 100).isTrigger = true;
|
||||||
player.addComponent(new Mover());
|
player.addComponent(new Mover());
|
||||||
|
|
||||||
let player2 = scene.createEntity("player2");
|
let player2 = scene.createEntity("player2");
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ class SpawnComponent extends Component implements ITriggerListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onTriggerEnter(other: Collider, local: Collider){
|
public onTriggerEnter(other: Collider, local: Collider){
|
||||||
console.log("enter collider", other, local);
|
console.log("enter collider");
|
||||||
}
|
}
|
||||||
|
|
||||||
public onTriggerExit(other: Collider, local: Collider){
|
public onTriggerExit(other: Collider, local: Collider){
|
||||||
console.log("exit collider", other, local);
|
console.log("exit collider");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
source/bin/framework.d.ts
vendored
6
source/bin/framework.d.ts
vendored
@@ -402,7 +402,7 @@ declare abstract class Collider extends Component {
|
|||||||
protected _isParentEntityAddedToScene: any;
|
protected _isParentEntityAddedToScene: any;
|
||||||
protected _colliderRequiresAutoSizing: any;
|
protected _colliderRequiresAutoSizing: any;
|
||||||
protected _localOffset: Vector2;
|
protected _localOffset: Vector2;
|
||||||
protected _isColliderRegisterd: any;
|
protected _isColliderRegistered: any;
|
||||||
readonly bounds: Rectangle;
|
readonly bounds: Rectangle;
|
||||||
localOffset: Vector2;
|
localOffset: Vector2;
|
||||||
setLocalOffset(offset: Vector2): void;
|
setLocalOffset(offset: Vector2): void;
|
||||||
@@ -701,7 +701,7 @@ declare class Polygon extends Shape {
|
|||||||
_edgeNormals: Vector2[];
|
_edgeNormals: Vector2[];
|
||||||
readonly edgeNormals: Vector2[];
|
readonly edgeNormals: Vector2[];
|
||||||
isBox: boolean;
|
isBox: boolean;
|
||||||
constructor(vertCount: number, radius: number);
|
constructor(points: Vector2[], isBox?: boolean);
|
||||||
private buildEdgeNormals;
|
private buildEdgeNormals;
|
||||||
setPoints(points: Vector2[]): void;
|
setPoints(points: Vector2[]): void;
|
||||||
collidesWithShape(other: Shape): CollisionResult;
|
collidesWithShape(other: Shape): CollisionResult;
|
||||||
@@ -721,6 +721,8 @@ declare class Polygon extends Shape {
|
|||||||
declare class Box extends Polygon {
|
declare class Box extends Polygon {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
constructor(width: number, height: number);
|
||||||
|
private static buildBox;
|
||||||
updateBox(width: number, height: number): void;
|
updateBox(width: number, height: number): void;
|
||||||
containsPoint(point: Vector2): boolean;
|
containsPoint(point: Vector2): boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1186,7 +1186,7 @@ var Transform = (function () {
|
|||||||
this._worldInverseTransform = Matrix2D.identity;
|
this._worldInverseTransform = Matrix2D.identity;
|
||||||
this._rotation = 0;
|
this._rotation = 0;
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this._scale = this._localScale = new Vector2(0, 0);
|
this._scale = this._localScale = Vector2.one;
|
||||||
this._children = [];
|
this._children = [];
|
||||||
}
|
}
|
||||||
Object.defineProperty(Transform.prototype, "childCount", {
|
Object.defineProperty(Transform.prototype, "childCount", {
|
||||||
@@ -1882,16 +1882,16 @@ var Collider = (function (_super) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Collider.prototype.registerColliderWithPhysicsSystem = function () {
|
Collider.prototype.registerColliderWithPhysicsSystem = function () {
|
||||||
if (this._isParentEntityAddedToScene && !this._isColliderRegisterd) {
|
if (this._isParentEntityAddedToScene && !this._isColliderRegistered) {
|
||||||
Physics.addCollider(this);
|
Physics.addCollider(this);
|
||||||
this._isColliderRegisterd = true;
|
this._isColliderRegistered = true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Collider.prototype.unregisterColliderWithPhysicsSystem = function () {
|
Collider.prototype.unregisterColliderWithPhysicsSystem = function () {
|
||||||
if (this._isParentEntityAddedToScene && this._isColliderRegisterd) {
|
if (this._isParentEntityAddedToScene && this._isColliderRegistered) {
|
||||||
Physics.removeCollider(this);
|
Physics.removeCollider(this);
|
||||||
}
|
}
|
||||||
this._isColliderRegisterd = false;
|
this._isColliderRegistered = false;
|
||||||
};
|
};
|
||||||
Collider.prototype.overlaps = function (other) {
|
Collider.prototype.overlaps = function (other) {
|
||||||
return this.shape.overlaps(other.shape);
|
return this.shape.overlaps(other.shape);
|
||||||
@@ -1938,7 +1938,7 @@ var Collider = (function (_super) {
|
|||||||
this._isRotationDirty = true;
|
this._isRotationDirty = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (this._isColliderRegisterd)
|
if (this._isColliderRegistered)
|
||||||
Physics.updateCollider(this);
|
Physics.updateCollider(this);
|
||||||
};
|
};
|
||||||
Collider.prototype.onEnabled = function () {
|
Collider.prototype.onEnabled = function () {
|
||||||
@@ -2308,20 +2308,30 @@ var ComponentList = (function () {
|
|||||||
components = [];
|
components = [];
|
||||||
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 (typeof (typeName) == "string" && egret.is(component, typeName))
|
if (typeof (typeName) == "string") {
|
||||||
|
if (egret.is(component, typeName)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
else if (component instanceof typeName) {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
for (var i = 0; i < this._componentsToAdd.length; i++) {
|
||||||
var component = this._componentsToAdd[i];
|
var component = this._componentsToAdd[i];
|
||||||
if (typeof (typeName) == "string" && egret.is(component, typeName))
|
if (typeof (typeName) == "string") {
|
||||||
|
if (egret.is(component, typeName)) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
else if (component instanceof typeName) {
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (component instanceof typeName) {
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return components;
|
return components;
|
||||||
};
|
};
|
||||||
ComponentList.prototype.update = function () {
|
ComponentList.prototype.update = function () {
|
||||||
@@ -3099,9 +3109,13 @@ var ColliderTriggerHelper = (function () {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
this._previousTriggerIntersections.forEach(function (pair) { return _this.notifyTriggerListeners(pair, false); });
|
for (var i = 0; i < this._previousTriggerIntersections.length; i++) {
|
||||||
|
this.notifyTriggerListeners(this._previousTriggerIntersections[i], false);
|
||||||
|
}
|
||||||
this._previousTriggerIntersections.length = 0;
|
this._previousTriggerIntersections.length = 0;
|
||||||
tempIntersections.forEach(function (value) { return _this._previousTriggerIntersections.push(value); });
|
for (var i = 0; i < tempIntersections.length; i++) {
|
||||||
|
this._previousTriggerIntersections.push(tempIntersections[i]);
|
||||||
|
}
|
||||||
this._activeTriggerIntersections.length = 0;
|
this._activeTriggerIntersections.length = 0;
|
||||||
};
|
};
|
||||||
ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
|
ColliderTriggerHelper.prototype.notifyTriggerListeners = function (collisionPair, isEntering) {
|
||||||
@@ -3296,11 +3310,12 @@ var Shape = (function () {
|
|||||||
}());
|
}());
|
||||||
var Polygon = (function (_super) {
|
var Polygon = (function (_super) {
|
||||||
__extends(Polygon, _super);
|
__extends(Polygon, _super);
|
||||||
function Polygon(vertCount, radius) {
|
function Polygon(points, isBox) {
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.isUnrotated = true;
|
_this.isUnrotated = true;
|
||||||
_this._areEdgeNormalsDirty = true;
|
_this._areEdgeNormalsDirty = true;
|
||||||
_this.setPoints(Polygon.buildSymmertricalPolygon(vertCount, radius));
|
_this.setPoints(points);
|
||||||
|
_this.isBox = isBox;
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
Object.defineProperty(Polygon.prototype, "edgeNormals", {
|
Object.defineProperty(Polygon.prototype, "edgeNormals", {
|
||||||
@@ -3329,11 +3344,12 @@ var Polygon = (function (_super) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Polygon.prototype.setPoints = function (points) {
|
Polygon.prototype.setPoints = function (points) {
|
||||||
var _this = this;
|
|
||||||
this.points = points;
|
this.points = points;
|
||||||
this.recalculateCenterAndEdgeNormals();
|
this.recalculateCenterAndEdgeNormals();
|
||||||
this._originalPoints = new Array(this.points.length);
|
this._originalPoints = [];
|
||||||
this.points.forEach(function (point) { return _this._originalPoints.push(point); });
|
for (var i = 0; i < this.points.length; i++) {
|
||||||
|
this._originalPoints.push(this.points[i]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Polygon.prototype.collidesWithShape = function (other) {
|
Polygon.prototype.collidesWithShape = function (other) {
|
||||||
var result = new CollisionResult();
|
var result = new CollisionResult();
|
||||||
@@ -3457,9 +3473,22 @@ var Polygon = (function (_super) {
|
|||||||
}(Shape));
|
}(Shape));
|
||||||
var Box = (function (_super) {
|
var Box = (function (_super) {
|
||||||
__extends(Box, _super);
|
__extends(Box, _super);
|
||||||
function Box() {
|
function Box(width, height) {
|
||||||
return _super !== null && _super.apply(this, arguments) || this;
|
var _this = _super.call(this, Box.buildBox(width, height), true) || this;
|
||||||
|
_this.width = width;
|
||||||
|
_this.height = height;
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
|
Box.buildBox = function (width, height) {
|
||||||
|
var halfWidth = width / 2;
|
||||||
|
var halfHeight = height / 2;
|
||||||
|
var verts = new Array(4);
|
||||||
|
verts[0] = new Vector2(-halfWidth, -halfHeight);
|
||||||
|
verts[1] = new Vector2(halfWidth, -halfHeight);
|
||||||
|
verts[2] = new Vector2(halfWidth, halfHeight);
|
||||||
|
verts[3] = new Vector2(-halfWidth, halfHeight);
|
||||||
|
return verts;
|
||||||
|
};
|
||||||
Box.prototype.updateBox = function (width, height) {
|
Box.prototype.updateBox = function (width, height) {
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
@@ -3755,10 +3784,18 @@ var SpatialHash = (function () {
|
|||||||
this._overlapTestCircle.position = circleCenter;
|
this._overlapTestCircle.position = circleCenter;
|
||||||
var resultCounter = 0;
|
var resultCounter = 0;
|
||||||
var potentials = this.aabbBroadphase(bounds, null, layerMask);
|
var potentials = this.aabbBroadphase(bounds, null, layerMask);
|
||||||
potentials.forEach(function (collider) {
|
for (var i = 0; i < potentials.length; i++) {
|
||||||
|
var collider = potentials[i];
|
||||||
|
if (collider instanceof BoxCollider) {
|
||||||
|
results[resultCounter] = collider;
|
||||||
|
resultCounter++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error("overlapCircle against this collider type is not implemented!");
|
||||||
|
}
|
||||||
if (resultCounter == results.length)
|
if (resultCounter == results.length)
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
});
|
}
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
};
|
};
|
||||||
SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) {
|
SpatialHash.prototype.aabbBroadphase = function (bounds, excludeCollider, layerMask) {
|
||||||
@@ -4020,7 +4057,7 @@ var Vector2Ext = (function () {
|
|||||||
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++) {
|
||||||
var position = sourceArray[sourceIndex + i];
|
var position = sourceArray[sourceIndex + i];
|
||||||
var destination = destinationArray[destinationIndex + 1];
|
var destination = destinationArray[destinationIndex + i];
|
||||||
destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
||||||
destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
||||||
destinationArray[destinationIndex + i] = destination;
|
destinationArray[destinationIndex + i] = destination;
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
832
source/package-lock.json
generated
832
source/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,8 @@
|
|||||||
"lib": "lib"
|
"lib": "lib"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --recursive --reporter tap --growl"
|
"test": "mocha --recursive --reporter tap --growl",
|
||||||
|
"eslint": "eslint src --ext .ts"
|
||||||
},
|
},
|
||||||
"author": "yhh",
|
"author": "yhh",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
"gulp": "^3.9.1",
|
"gulp": "^3.9.1",
|
||||||
"gulp-babel": "^8.0.0",
|
"gulp-babel": "^8.0.0",
|
||||||
"gulp-concat": "^2.6.1",
|
"gulp-concat": "^2.6.1",
|
||||||
|
"gulp-inject-string": "^1.1.2",
|
||||||
"gulp-minify": "^3.1.0",
|
"gulp-minify": "^3.1.0",
|
||||||
"gulp-string-replace": "^1.1.2",
|
"gulp-string-replace": "^1.1.2",
|
||||||
"gulp-typescript": "^3.1.6",
|
"gulp-typescript": "^3.1.6",
|
||||||
@@ -25,14 +27,10 @@
|
|||||||
"tsify": "^3.0.1",
|
"tsify": "^3.0.1",
|
||||||
"typescript": "^2.2.2",
|
"typescript": "^2.2.2",
|
||||||
"vinyl-source-stream": "^1.1.0",
|
"vinyl-source-stream": "^1.1.0",
|
||||||
"watchify": "^3.9.0",
|
"watchify": "^3.9.0"
|
||||||
"gulp-inject-string": "^1.1.2"
|
|
||||||
},
|
},
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"registry": "https://npm.pkg.github.com/359807859@qq.com"
|
"registry": "https://npm.pkg.github.com/359807859@qq.com"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {}
|
||||||
"chai": "^4.2.0",
|
|
||||||
"mocha": "^8.0.1"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ abstract class Collider extends Component{
|
|||||||
protected _isParentEntityAddedToScene;
|
protected _isParentEntityAddedToScene;
|
||||||
protected _colliderRequiresAutoSizing;
|
protected _colliderRequiresAutoSizing;
|
||||||
protected _localOffset: Vector2 = new Vector2(0, 0);
|
protected _localOffset: Vector2 = new Vector2(0, 0);
|
||||||
protected _isColliderRegisterd;
|
protected _isColliderRegistered;
|
||||||
|
|
||||||
public get bounds(): Rectangle {
|
public get bounds(): Rectangle {
|
||||||
if (this._isPositionDirty || this._isRotationDirty){
|
if (this._isPositionDirty || this._isRotationDirty){
|
||||||
@@ -42,17 +42,17 @@ abstract class Collider extends Component{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public registerColliderWithPhysicsSystem(){
|
public registerColliderWithPhysicsSystem(){
|
||||||
if (this._isParentEntityAddedToScene && !this._isColliderRegisterd){
|
if (this._isParentEntityAddedToScene && !this._isColliderRegistered){
|
||||||
Physics.addCollider(this);
|
Physics.addCollider(this);
|
||||||
this._isColliderRegisterd = true;
|
this._isColliderRegistered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregisterColliderWithPhysicsSystem(){
|
public unregisterColliderWithPhysicsSystem(){
|
||||||
if (this._isParentEntityAddedToScene && this._isColliderRegisterd){
|
if (this._isParentEntityAddedToScene && this._isColliderRegistered){
|
||||||
Physics.removeCollider(this);
|
Physics.removeCollider(this);
|
||||||
}
|
}
|
||||||
this._isColliderRegisterd = false;
|
this._isColliderRegistered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public overlaps(other: Collider){
|
public overlaps(other: Collider){
|
||||||
@@ -112,7 +112,7 @@ abstract class Collider extends Component{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._isColliderRegisterd)
|
if (this._isColliderRegistered)
|
||||||
Physics.updateCollider(this);
|
Physics.updateCollider(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class Transform {
|
|||||||
|
|
||||||
constructor(entity: Entity){
|
constructor(entity: Entity){
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
this._scale = this._localScale = new Vector2(0, 0);
|
this._scale = this._localScale = Vector2.one;
|
||||||
this._children = [];
|
this._children = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -126,21 +126,29 @@ class ComponentList {
|
|||||||
|
|
||||||
for (let i = 0; i < this._components.length; i ++){
|
for (let i = 0; i < this._components.length; i ++){
|
||||||
let component = this._components[i];
|
let component = this._components[i];
|
||||||
if (typeof(typeName) == "string" && egret.is(component, typeName))
|
if (typeof(typeName) == "string"){
|
||||||
|
if (egret.is(component, typeName)){
|
||||||
components.push(component);
|
components.push(component);
|
||||||
else if (component instanceof typeName) {
|
}
|
||||||
|
}else{
|
||||||
|
if (component instanceof typeName){
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._componentsToAdd.length; i ++){
|
for (let i = 0; i < this._componentsToAdd.length; i ++){
|
||||||
let component = this._componentsToAdd[i];
|
let component = this._componentsToAdd[i];
|
||||||
if (typeof(typeName) == "string" && egret.is(component, typeName))
|
if (typeof(typeName) == "string"){
|
||||||
|
if (egret.is(component, typeName)){
|
||||||
components.push(component);
|
components.push(component);
|
||||||
else if (component instanceof typeName){
|
}
|
||||||
|
}else{
|
||||||
|
if (component instanceof typeName){
|
||||||
components.push(component);
|
components.push(component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,9 +55,13 @@ class ColliderTriggerHelper {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
this._previousTriggerIntersections.forEach(pair => this.notifyTriggerListeners(pair, false));
|
for (let i = 0; i < this._previousTriggerIntersections.length; i ++){
|
||||||
|
this.notifyTriggerListeners(this._previousTriggerIntersections[i], false)
|
||||||
|
}
|
||||||
this._previousTriggerIntersections.length = 0;
|
this._previousTriggerIntersections.length = 0;
|
||||||
tempIntersections.forEach(value => this._previousTriggerIntersections.push(value));
|
for (let i = 0; i < tempIntersections.length; i ++){
|
||||||
|
this._previousTriggerIntersections.push(tempIntersections[i]);
|
||||||
|
}
|
||||||
this._activeTriggerIntersections.length = 0;
|
this._activeTriggerIntersections.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,24 @@ class Box extends Polygon {
|
|||||||
public width: number;
|
public width: number;
|
||||||
public height: number;
|
public height: number;
|
||||||
|
|
||||||
|
constructor(width: number, height: number){
|
||||||
|
super(Box.buildBox(width, height), true);
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static buildBox(width: number, height: number): Vector2[]{
|
||||||
|
let halfWidth = width / 2;
|
||||||
|
let halfHeight = height / 2;
|
||||||
|
let verts = new Array(4);
|
||||||
|
verts[0] = new Vector2(-halfWidth, -halfHeight);
|
||||||
|
verts[1] = new Vector2(halfWidth, -halfHeight);
|
||||||
|
verts[2] = new Vector2(halfWidth, halfHeight);
|
||||||
|
verts[3] = new Vector2(-halfWidth, halfHeight);
|
||||||
|
|
||||||
|
return verts;
|
||||||
|
}
|
||||||
|
|
||||||
public updateBox(width: number, height: number){
|
public updateBox(width: number, height: number){
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|||||||
@@ -14,9 +14,11 @@ class Polygon extends Shape {
|
|||||||
}
|
}
|
||||||
public isBox: boolean;
|
public isBox: boolean;
|
||||||
|
|
||||||
constructor(vertCount: number, radius: number) {
|
constructor(points: Vector2[], isBox?: boolean){
|
||||||
super();
|
super();
|
||||||
this.setPoints(Polygon.buildSymmertricalPolygon(vertCount, radius));
|
|
||||||
|
this.setPoints(points);
|
||||||
|
this.isBox = isBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildEdgeNormals(){
|
private buildEdgeNormals(){
|
||||||
@@ -42,8 +44,10 @@ class Polygon extends Shape {
|
|||||||
this.points = points;
|
this.points = points;
|
||||||
this.recalculateCenterAndEdgeNormals();
|
this.recalculateCenterAndEdgeNormals();
|
||||||
|
|
||||||
this._originalPoints = new Array(this.points.length);
|
this._originalPoints = [];
|
||||||
this.points.forEach(point => this._originalPoints.push(point));
|
for (let i = 0; i < this.points.length; i ++){
|
||||||
|
this._originalPoints.push(this.points[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public collidesWithShape(other: Shape){
|
public collidesWithShape(other: Shape){
|
||||||
|
|||||||
@@ -60,10 +60,18 @@ class SpatialHash {
|
|||||||
|
|
||||||
let resultCounter = 0;
|
let resultCounter = 0;
|
||||||
let potentials = this.aabbBroadphase(bounds, null, layerMask);
|
let potentials = this.aabbBroadphase(bounds, null, layerMask);
|
||||||
potentials.forEach(collider => {
|
for (let i = 0; i < potentials.length; i ++){
|
||||||
|
let collider = potentials[i];
|
||||||
|
if (collider instanceof BoxCollider){
|
||||||
|
results[resultCounter] = collider;
|
||||||
|
resultCounter ++;
|
||||||
|
}else{
|
||||||
|
throw new Error("overlapCircle against this collider type is not implemented!");
|
||||||
|
}
|
||||||
|
|
||||||
if (resultCounter == results.length)
|
if (resultCounter == results.length)
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
});
|
}
|
||||||
|
|
||||||
return resultCounter;
|
return resultCounter;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Vector2Ext {
|
|||||||
destinationArray: Vector2[], destinationIndex: number, length: number) {
|
destinationArray: Vector2[], destinationIndex: number, length: number) {
|
||||||
for (let i = 0; i < length; i ++){
|
for (let i = 0; i < length; i ++){
|
||||||
let position = sourceArray[sourceIndex + i];
|
let position = sourceArray[sourceIndex + i];
|
||||||
let destination = destinationArray[destinationIndex + 1];
|
let destination = destinationArray[destinationIndex + i];
|
||||||
destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
destination.x = (position.x * matrix.m11) + (position.y * matrix.m21) + matrix.m31;
|
||||||
destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
destination.y = (position.x * matrix.m12) + (position.y * matrix.m22) + matrix.m32;
|
||||||
destinationArray[destinationIndex + i] = destination;
|
destinationArray[destinationIndex + i] = destination;
|
||||||
|
|||||||
Reference in New Issue
Block a user