Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 14b70b307c | |||
| a39b98b5d9 | |||
| 3492bbdf5e | |||
| 7d0bcbcb32 | |||
| c02a3aa071 | |||
| a105bb11ca | |||
| 3fbbba7ac2 | |||
| 7cd38ea54e | |||
| 42852c5dba | |||
| 6a3622a5ef | |||
| 03b568e28d | |||
| e7fb9e0d6b | |||
| 463c64c628 | |||
| 4025bc8554 | |||
| 1bf822725a | |||
| 359d7ae223 | |||
| c611e31f7e | |||
| 834ad565e1 | |||
| 1e3b2763e8 | |||
| a3dacd04f0 |
Vendored
+22
-6
@@ -125,6 +125,7 @@ declare module es {
|
||||
static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
|
||||
static transform(position: Vector2, matrix: Matrix2D): Vector2;
|
||||
static distance(value1: Vector2, value2: Vector2): number;
|
||||
static angle(from: Vector2, to: Vector2): number;
|
||||
static negate(value: Vector2): Vector2;
|
||||
add(value: Vector2): Vector2;
|
||||
divide(value: Vector2): Vector2;
|
||||
@@ -369,6 +370,7 @@ declare module es {
|
||||
getPostProcessor<T extends PostProcessor>(type: any): T;
|
||||
removePostProcessor(postProcessor: PostProcessor): void;
|
||||
createEntity(name: string): Entity;
|
||||
createEntityAsync(name: string): Promise<Entity>;
|
||||
addEntity(entity: Entity): Entity;
|
||||
destroyAllEntities(): void;
|
||||
findEntity(name: string): Entity;
|
||||
@@ -474,7 +476,7 @@ declare module es {
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
mapLockEnabled: boolean;
|
||||
mapSize: Vector2;
|
||||
mapSize: Rectangle;
|
||||
_targetEntity: Entity;
|
||||
_targetCollider: Collider;
|
||||
_desiredPositionDelta: Vector2;
|
||||
@@ -591,12 +593,20 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class TiledSpriteRenderer extends SpriteRenderer {
|
||||
protected sourceRect: Rectangle;
|
||||
protected leftTexture: egret.Bitmap;
|
||||
protected rightTexture: egret.Bitmap;
|
||||
constructor(sprite: Sprite);
|
||||
readonly bounds: Rectangle;
|
||||
scrollX: number;
|
||||
scrollY: number;
|
||||
textureScale: Vector2;
|
||||
width: number;
|
||||
height: number;
|
||||
gapXY: Vector2;
|
||||
protected _sourceRect: Rectangle;
|
||||
protected _textureScale: Vector2;
|
||||
protected _inverseTexScale: Vector2;
|
||||
private _gapX;
|
||||
private _gapY;
|
||||
constructor(sprite: Sprite);
|
||||
setGapXY(value: Vector2): TiledSpriteRenderer;
|
||||
render(camera: es.Camera): void;
|
||||
}
|
||||
}
|
||||
@@ -604,10 +614,15 @@ declare module es {
|
||||
class ScrollingSpriteRenderer extends TiledSpriteRenderer {
|
||||
scrollSpeedX: number;
|
||||
scroolSpeedY: number;
|
||||
textureScale: Vector2;
|
||||
scrollWidth: number;
|
||||
scrollHeight: number;
|
||||
private _scrollX;
|
||||
private _scrollY;
|
||||
private _scrollWidth;
|
||||
private _scrollHeight;
|
||||
constructor(sprite: Sprite);
|
||||
update(): void;
|
||||
render(camera: Camera): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
@@ -937,6 +952,7 @@ declare module es {
|
||||
addToRenderLayerList(component: IRenderable, renderLayer: number): void;
|
||||
componentsWithRenderLayer(renderLayer: number): IRenderable[];
|
||||
updateList(): void;
|
||||
private updateEgretList;
|
||||
}
|
||||
}
|
||||
declare class StringUtils {
|
||||
|
||||
@@ -718,6 +718,11 @@ var es;
|
||||
var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
|
||||
return Math.sqrt((v1 * v1) + (v2 * v2));
|
||||
};
|
||||
Vector2.angle = function (from, to) {
|
||||
from = Vector2.normalize(from);
|
||||
to = Vector2.normalize(to);
|
||||
return Math.acos(es.MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * es.MathHelper.Rad2Deg;
|
||||
};
|
||||
Vector2.negate = function (value) {
|
||||
var result = new Vector2();
|
||||
result.x = -value.x;
|
||||
@@ -1598,6 +1603,7 @@ var es;
|
||||
childClone.transform.parent = this.transform;
|
||||
}
|
||||
};
|
||||
Entity._idGenerator = 0;
|
||||
return Entity;
|
||||
}());
|
||||
es.Entity = Entity;
|
||||
@@ -1689,7 +1695,7 @@ var es;
|
||||
};
|
||||
Scene.prototype.render = function () {
|
||||
if (this._renderers.length == 0) {
|
||||
console.error("there are no renderers in the scene!");
|
||||
console.error("场景中没有渲染器!");
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < this._renderers.length; i++) {
|
||||
@@ -1750,9 +1756,15 @@ var es;
|
||||
var entity = new es.Entity(name);
|
||||
return this.addEntity(entity);
|
||||
};
|
||||
Scene.prototype.createEntityAsync = function (name) {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) {
|
||||
resolve(_this.createEntity(name));
|
||||
});
|
||||
};
|
||||
Scene.prototype.addEntity = function (entity) {
|
||||
if (this.entities.buffer.contains(entity))
|
||||
console.warn("You are attempting to add the same entity to a scene twice: " + entity);
|
||||
console.warn("\u60A8\u8BD5\u56FE\u5C06\u540C\u4E00\u5B9E\u4F53\u6DFB\u52A0\u5230\u573A\u666F\u4E24\u6B21: " + entity);
|
||||
this.entities.add(entity);
|
||||
entity.scene = this;
|
||||
for (var i = 0; i < entity.transform.childCount; i++)
|
||||
@@ -2177,7 +2189,7 @@ var es;
|
||||
_this.deadzone = new es.Rectangle();
|
||||
_this.focusOffset = es.Vector2.zero;
|
||||
_this.mapLockEnabled = false;
|
||||
_this.mapSize = es.Vector2.zero;
|
||||
_this.mapSize = new es.Rectangle();
|
||||
_this._desiredPositionDelta = new es.Vector2();
|
||||
_this._worldSpaceDeadZone = new es.Rectangle();
|
||||
_this._minimumZoom = 0.3;
|
||||
@@ -2403,8 +2415,8 @@ var es;
|
||||
}
|
||||
};
|
||||
Camera.prototype.clampToMapSize = function (position) {
|
||||
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
|
||||
var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
|
||||
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 cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||
};
|
||||
Camera.prototype.updateFollow = function () {
|
||||
@@ -2570,6 +2582,7 @@ var es;
|
||||
return this._renderLayer;
|
||||
},
|
||||
set: function (value) {
|
||||
this.setRenderLayer(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -2658,6 +2671,7 @@ var es;
|
||||
}
|
||||
Mesh.prototype.setTexture = function (texture) {
|
||||
this._mesh.texture = texture;
|
||||
this._mesh.$renderNode = new egret.sys.RenderNode();
|
||||
return this;
|
||||
};
|
||||
Mesh.prototype.reset = function () {
|
||||
@@ -2750,8 +2764,8 @@ var es;
|
||||
};
|
||||
SpriteRenderer.prototype.render = function (camera) {
|
||||
this.sync(camera);
|
||||
this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x;
|
||||
this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y;
|
||||
this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x;
|
||||
this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y;
|
||||
};
|
||||
return SpriteRenderer;
|
||||
}(es.RenderableComponent));
|
||||
@@ -2759,53 +2773,123 @@ var es;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Bitmap = egret.Bitmap;
|
||||
var RenderTexture = egret.RenderTexture;
|
||||
var TiledSpriteRenderer = (function (_super) {
|
||||
__extends(TiledSpriteRenderer, _super);
|
||||
function TiledSpriteRenderer(sprite) {
|
||||
var _this = _super.call(this, sprite) || this;
|
||||
_this.leftTexture = new egret.Bitmap();
|
||||
_this.rightTexture = new egret.Bitmap();
|
||||
_this.leftTexture.texture = sprite.texture2D;
|
||||
_this.rightTexture.texture = sprite.texture2D;
|
||||
_this.setSprite(sprite);
|
||||
_this.sourceRect = sprite.sourceRect;
|
||||
_this._textureScale = es.Vector2.one;
|
||||
_this._inverseTexScale = es.Vector2.one;
|
||||
_this._gapX = 0;
|
||||
_this._gapY = 0;
|
||||
_this._sourceRect = sprite.sourceRect;
|
||||
var bitmap = _this.displayObject;
|
||||
bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "bounds", {
|
||||
get: function () {
|
||||
if (this._areBoundsDirty) {
|
||||
if (this._sprite) {
|
||||
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
|
||||
this._areBoundsDirty = false;
|
||||
}
|
||||
}
|
||||
return this._bounds;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", {
|
||||
get: function () {
|
||||
return this.sourceRect.x;
|
||||
return this._sourceRect.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this.sourceRect.x = value;
|
||||
this._sourceRect.x = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", {
|
||||
get: function () {
|
||||
return this.sourceRect.y;
|
||||
return this._sourceRect.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this.sourceRect.y = value;
|
||||
this._sourceRect.y = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "textureScale", {
|
||||
get: function () {
|
||||
return this._textureScale;
|
||||
},
|
||||
set: function (value) {
|
||||
this._textureScale = value;
|
||||
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
||||
this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
|
||||
this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "width", {
|
||||
get: function () {
|
||||
return this._sourceRect.width;
|
||||
},
|
||||
set: function (value) {
|
||||
this._areBoundsDirty = true;
|
||||
this._sourceRect.width = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "height", {
|
||||
get: function () {
|
||||
return this._sourceRect.height;
|
||||
},
|
||||
set: function (value) {
|
||||
this._areBoundsDirty = true;
|
||||
this._sourceRect.height = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "gapXY", {
|
||||
get: function () {
|
||||
return new es.Vector2(this._gapX, this._gapY);
|
||||
},
|
||||
set: function (value) {
|
||||
this._gapX = value.x;
|
||||
this._gapY = value.y;
|
||||
var renderTexture = new RenderTexture();
|
||||
var newRectangle = this.sprite.sourceRect;
|
||||
newRectangle.x = 0;
|
||||
newRectangle.y = 0;
|
||||
newRectangle.width += this._gapX;
|
||||
newRectangle.height += this._gapY;
|
||||
renderTexture.drawToTexture(this.displayObject, newRectangle);
|
||||
if (!this.displayObject) {
|
||||
this.displayObject = new Bitmap(renderTexture);
|
||||
}
|
||||
else {
|
||||
this.displayObject.texture = renderTexture;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
TiledSpriteRenderer.prototype.setGapXY = function (value) {
|
||||
this.gapXY = value;
|
||||
return this;
|
||||
};
|
||||
TiledSpriteRenderer.prototype.render = function (camera) {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
_super.prototype.render.call(this, camera);
|
||||
var renderTexture = new egret.RenderTexture();
|
||||
var cacheBitmap = new egret.DisplayObjectContainer();
|
||||
cacheBitmap.removeChildren();
|
||||
cacheBitmap.addChild(this.leftTexture);
|
||||
cacheBitmap.addChild(this.rightTexture);
|
||||
this.leftTexture.x = this.sourceRect.x;
|
||||
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
||||
this.leftTexture.y = this.sourceRect.y;
|
||||
this.rightTexture.y = this.sourceRect.y;
|
||||
cacheBitmap.cacheAsBitmap = true;
|
||||
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
||||
var bitmap = this.displayObject;
|
||||
bitmap.width = this.width;
|
||||
bitmap.height = this.height;
|
||||
bitmap.scrollRect = this._sourceRect;
|
||||
};
|
||||
return TiledSpriteRenderer;
|
||||
}(es.SpriteRenderer));
|
||||
@@ -2815,35 +2899,58 @@ var es;
|
||||
(function (es) {
|
||||
var ScrollingSpriteRenderer = (function (_super) {
|
||||
__extends(ScrollingSpriteRenderer, _super);
|
||||
function ScrollingSpriteRenderer() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
function ScrollingSpriteRenderer(sprite) {
|
||||
var _this = _super.call(this, sprite) || this;
|
||||
_this.scrollSpeedX = 15;
|
||||
_this.scroolSpeedY = 0;
|
||||
_this._scrollX = 0;
|
||||
_this._scrollY = 0;
|
||||
_this._scrollWidth = 0;
|
||||
_this._scrollHeight = 0;
|
||||
_this._scrollWidth = _this.width;
|
||||
_this._scrollHeight = _this.height;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(ScrollingSpriteRenderer.prototype, "textureScale", {
|
||||
get: function () {
|
||||
return this._textureScale;
|
||||
},
|
||||
set: function (value) {
|
||||
this._textureScale = value;
|
||||
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollWidth", {
|
||||
get: function () {
|
||||
return this._scrollWidth;
|
||||
},
|
||||
set: function (value) {
|
||||
this._scrollWidth = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollHeight", {
|
||||
get: function () {
|
||||
return this._scrollHeight;
|
||||
},
|
||||
set: function (value) {
|
||||
this._scrollHeight = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
ScrollingSpriteRenderer.prototype.update = function () {
|
||||
this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
|
||||
this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
|
||||
this.sourceRect.x = this._scrollX;
|
||||
this.sourceRect.y = this._scrollY;
|
||||
};
|
||||
ScrollingSpriteRenderer.prototype.render = function (camera) {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
_super.prototype.render.call(this, camera);
|
||||
var renderTexture = new egret.RenderTexture();
|
||||
var cacheBitmap = new egret.DisplayObjectContainer();
|
||||
cacheBitmap.removeChildren();
|
||||
cacheBitmap.addChild(this.leftTexture);
|
||||
cacheBitmap.addChild(this.rightTexture);
|
||||
this.leftTexture.x = this.sourceRect.x;
|
||||
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
||||
this.leftTexture.y = this.sourceRect.y;
|
||||
this.rightTexture.y = this.sourceRect.y;
|
||||
cacheBitmap.cacheAsBitmap = true;
|
||||
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
||||
this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
|
||||
this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
|
||||
this._sourceRect.x = this._scrollX;
|
||||
this._sourceRect.y = this._scrollY;
|
||||
this._sourceRect.width = this._scrollWidth + Math.abs(this._scrollX);
|
||||
this._sourceRect.height = this._scrollHeight + Math.abs(this._scrollY);
|
||||
};
|
||||
return ScrollingSpriteRenderer;
|
||||
}(es.TiledSpriteRenderer));
|
||||
@@ -4217,8 +4324,8 @@ var es;
|
||||
};
|
||||
RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) {
|
||||
var list = this.componentsWithRenderLayer(renderLayer);
|
||||
if (!list.contains(component)) {
|
||||
console.warn("Component renderLayer list already contains this component");
|
||||
if (list.contains(component)) {
|
||||
console.warn("组件呈现层列表已经包含此组件");
|
||||
return;
|
||||
}
|
||||
list.push(component);
|
||||
@@ -4236,6 +4343,7 @@ var es;
|
||||
if (this._componentsNeedSort) {
|
||||
this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
||||
this._componentsNeedSort = false;
|
||||
this.updateEgretList();
|
||||
}
|
||||
if (this._unsortedRenderLayers.length > 0) {
|
||||
for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) {
|
||||
@@ -4245,6 +4353,23 @@ var es;
|
||||
}
|
||||
}
|
||||
this._unsortedRenderLayers.length = 0;
|
||||
this.updateEgretList();
|
||||
}
|
||||
};
|
||||
RenderableComponentList.prototype.updateEgretList = function () {
|
||||
var scene = es.Core._instance._scene;
|
||||
if (!scene)
|
||||
return;
|
||||
var _loop_5 = function (i) {
|
||||
var component = this_1._components[i];
|
||||
var egretDisplayObject = scene.$children.find(function (a) { return a.hashCode == component.displayObject.hashCode; });
|
||||
var displayIndex = scene.getChildIndex(egretDisplayObject);
|
||||
if (displayIndex != i)
|
||||
scene.swapChildrenAt(displayIndex, i);
|
||||
};
|
||||
var this_1 = this;
|
||||
for (var i = 0; i < this._components.length; i++) {
|
||||
_loop_5(i);
|
||||
}
|
||||
};
|
||||
RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer();
|
||||
@@ -5822,26 +5947,26 @@ var es;
|
||||
for (var i = 0; i < colliders.length; i++) {
|
||||
var collider = colliders[i];
|
||||
var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
|
||||
var _loop_5 = function (j) {
|
||||
var _loop_6 = function (j) {
|
||||
var neighbor = neighbors[j];
|
||||
if (!collider.isTrigger && !neighbor.isTrigger)
|
||||
return "continue";
|
||||
if (collider.overlaps(neighbor)) {
|
||||
var pair_1 = new es.Pair(collider, neighbor);
|
||||
var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) {
|
||||
var shouldReportTriggerEvent = this_2._activeTriggerIntersections.findIndex(function (value) {
|
||||
return value.first == pair_1.first && value.second == pair_1.second;
|
||||
}) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) {
|
||||
}) == -1 && this_2._previousTriggerIntersections.findIndex(function (value) {
|
||||
return value.first == pair_1.first && value.second == pair_1.second;
|
||||
}) == -1;
|
||||
if (shouldReportTriggerEvent)
|
||||
this_1.notifyTriggerListeners(pair_1, true);
|
||||
if (!this_1._activeTriggerIntersections.contains(pair_1))
|
||||
this_1._activeTriggerIntersections.push(pair_1);
|
||||
this_2.notifyTriggerListeners(pair_1, true);
|
||||
if (!this_2._activeTriggerIntersections.contains(pair_1))
|
||||
this_2._activeTriggerIntersections.push(pair_1);
|
||||
}
|
||||
};
|
||||
var this_1 = this;
|
||||
var this_2 = this;
|
||||
for (var j = 0; j < neighbors.length; j++) {
|
||||
_loop_5(j);
|
||||
_loop_6(j);
|
||||
}
|
||||
}
|
||||
es.ListPool.free(colliders);
|
||||
@@ -5849,18 +5974,18 @@ var es;
|
||||
};
|
||||
ColliderTriggerHelper.prototype.checkForExitedColliders = function () {
|
||||
var _this = this;
|
||||
var _loop_6 = function (i) {
|
||||
var index = this_2._previousTriggerIntersections.findIndex(function (value) {
|
||||
var _loop_7 = function (i) {
|
||||
var index = this_3._previousTriggerIntersections.findIndex(function (value) {
|
||||
if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
if (index != -1)
|
||||
this_2._previousTriggerIntersections.removeAt(index);
|
||||
this_3._previousTriggerIntersections.removeAt(index);
|
||||
};
|
||||
var this_2 = this;
|
||||
var this_3 = this;
|
||||
for (var i = 0; i < this._activeTriggerIntersections.length; i++) {
|
||||
_loop_6(i);
|
||||
_loop_7(i);
|
||||
}
|
||||
for (var i = 0; i < this._previousTriggerIntersections.length; i++) {
|
||||
this.notifyTriggerListeners(this._previousTriggerIntersections[i], false);
|
||||
@@ -6838,7 +6963,7 @@ var es;
|
||||
for (var y = p1.y; y <= p2.y; y++) {
|
||||
var cell = this.cellAtPosition(x, y);
|
||||
if (!cell)
|
||||
console.error("removing Collider [" + collider + "] from a cell that it is not present in");
|
||||
console.log("\u4ECE\u4E0D\u5B58\u5728\u78B0\u649E\u5668\u7684\u5355\u5143\u683C\u4E2D\u79FB\u9664\u78B0\u649E\u5668: [" + collider + "]");
|
||||
else
|
||||
cell.remove(collider);
|
||||
}
|
||||
@@ -6869,18 +6994,18 @@ var es;
|
||||
var cell = this.cellAtPosition(x, y);
|
||||
if (!cell)
|
||||
continue;
|
||||
var _loop_7 = function (i) {
|
||||
var _loop_8 = function (i) {
|
||||
var collider = cell[i];
|
||||
if (collider == excludeCollider || !es.Flags.isFlagSet(layerMask, collider.physicsLayer))
|
||||
return "continue";
|
||||
if (bounds.intersects(collider.bounds)) {
|
||||
if (!this_3._tempHashSet.firstOrDefault(function (c) { return c.hashCode == collider.hashCode; }))
|
||||
this_3._tempHashSet.push(collider);
|
||||
if (!this_4._tempHashSet.firstOrDefault(function (c) { return c.hashCode == collider.hashCode; }))
|
||||
this_4._tempHashSet.push(collider);
|
||||
}
|
||||
};
|
||||
var this_3 = this;
|
||||
var this_4 = this;
|
||||
for (var i = 0; i < cell.length; i++) {
|
||||
_loop_7(i);
|
||||
_loop_8(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+16
-12
@@ -11,23 +11,27 @@ module scene {
|
||||
|
||||
public async onStart() {
|
||||
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
|
||||
let bg = this.createEntity("bg");
|
||||
bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
|
||||
bg.addComponent(new component.PlayerController());
|
||||
bg.addComponent(new es.Mover());
|
||||
bg.addComponent(new es.ScrollingSpriteRenderer(sprite));
|
||||
bg.addComponent(new es.BoxCollider());
|
||||
bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
|
||||
this.createEntityAsync("bg").then(bg => {
|
||||
bg.addComponent(new component.PlayerController());
|
||||
bg.addComponent(new es.Mover());
|
||||
let spriteRenderer = bg.addComponent(new es.ScrollingSpriteRenderer(sprite));
|
||||
spriteRenderer.setRenderLayer(4);
|
||||
spriteRenderer.scrollX = -30;
|
||||
// bg.addComponent(new es.BoxCollider());
|
||||
|
||||
this.camera.follow(bg, es.CameraStyle.lockOn);
|
||||
});
|
||||
// // bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
|
||||
|
||||
|
||||
for (let i = 0; i < 20; i++) {
|
||||
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
|
||||
let player2 = this.createEntity("player2");
|
||||
player2.addComponent(new es.SpriteRenderer()).setSprite(sprite);
|
||||
player2.position = new es.Vector2(Math.random() * 1000, Math.random() * 1000);
|
||||
player2.addComponent(new es.BoxCollider());
|
||||
let player2 = this.createEntity("bg");
|
||||
player2.addComponent(new es.SpriteRenderer()).setSprite(sprite).setRenderLayer(i);
|
||||
player2.position = new es.Vector2(30 * i, 30 * i);
|
||||
// player2.addComponent(new es.BoxCollider());
|
||||
}
|
||||
|
||||
this.camera.follow(bg, es.CameraStyle.lockOn);
|
||||
|
||||
let pool = new es.ComponentPool<component.SimplePooled>(component.SimplePooled);
|
||||
let c1 = pool.obtain();
|
||||
|
||||
Vendored
+22
-6
@@ -125,6 +125,7 @@ declare module es {
|
||||
static lerp(value1: Vector2, value2: Vector2, amount: number): Vector2;
|
||||
static transform(position: Vector2, matrix: Matrix2D): Vector2;
|
||||
static distance(value1: Vector2, value2: Vector2): number;
|
||||
static angle(from: Vector2, to: Vector2): number;
|
||||
static negate(value: Vector2): Vector2;
|
||||
add(value: Vector2): Vector2;
|
||||
divide(value: Vector2): Vector2;
|
||||
@@ -369,6 +370,7 @@ declare module es {
|
||||
getPostProcessor<T extends PostProcessor>(type: any): T;
|
||||
removePostProcessor(postProcessor: PostProcessor): void;
|
||||
createEntity(name: string): Entity;
|
||||
createEntityAsync(name: string): Promise<Entity>;
|
||||
addEntity(entity: Entity): Entity;
|
||||
destroyAllEntities(): void;
|
||||
findEntity(name: string): Entity;
|
||||
@@ -474,7 +476,7 @@ declare module es {
|
||||
deadzone: Rectangle;
|
||||
focusOffset: Vector2;
|
||||
mapLockEnabled: boolean;
|
||||
mapSize: Vector2;
|
||||
mapSize: Rectangle;
|
||||
_targetEntity: Entity;
|
||||
_targetCollider: Collider;
|
||||
_desiredPositionDelta: Vector2;
|
||||
@@ -591,12 +593,20 @@ declare module es {
|
||||
}
|
||||
declare module es {
|
||||
class TiledSpriteRenderer extends SpriteRenderer {
|
||||
protected sourceRect: Rectangle;
|
||||
protected leftTexture: egret.Bitmap;
|
||||
protected rightTexture: egret.Bitmap;
|
||||
constructor(sprite: Sprite);
|
||||
readonly bounds: Rectangle;
|
||||
scrollX: number;
|
||||
scrollY: number;
|
||||
textureScale: Vector2;
|
||||
width: number;
|
||||
height: number;
|
||||
gapXY: Vector2;
|
||||
protected _sourceRect: Rectangle;
|
||||
protected _textureScale: Vector2;
|
||||
protected _inverseTexScale: Vector2;
|
||||
private _gapX;
|
||||
private _gapY;
|
||||
constructor(sprite: Sprite);
|
||||
setGapXY(value: Vector2): TiledSpriteRenderer;
|
||||
render(camera: es.Camera): void;
|
||||
}
|
||||
}
|
||||
@@ -604,10 +614,15 @@ declare module es {
|
||||
class ScrollingSpriteRenderer extends TiledSpriteRenderer {
|
||||
scrollSpeedX: number;
|
||||
scroolSpeedY: number;
|
||||
textureScale: Vector2;
|
||||
scrollWidth: number;
|
||||
scrollHeight: number;
|
||||
private _scrollX;
|
||||
private _scrollY;
|
||||
private _scrollWidth;
|
||||
private _scrollHeight;
|
||||
constructor(sprite: Sprite);
|
||||
update(): void;
|
||||
render(camera: Camera): void;
|
||||
}
|
||||
}
|
||||
declare module es {
|
||||
@@ -937,6 +952,7 @@ declare module es {
|
||||
addToRenderLayerList(component: IRenderable, renderLayer: number): void;
|
||||
componentsWithRenderLayer(renderLayer: number): IRenderable[];
|
||||
updateList(): void;
|
||||
private updateEgretList;
|
||||
}
|
||||
}
|
||||
declare class StringUtils {
|
||||
|
||||
+196
-71
@@ -718,6 +718,11 @@ var es;
|
||||
var v1 = value1.x - value2.x, v2 = value1.y - value2.y;
|
||||
return Math.sqrt((v1 * v1) + (v2 * v2));
|
||||
};
|
||||
Vector2.angle = function (from, to) {
|
||||
from = Vector2.normalize(from);
|
||||
to = Vector2.normalize(to);
|
||||
return Math.acos(es.MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * es.MathHelper.Rad2Deg;
|
||||
};
|
||||
Vector2.negate = function (value) {
|
||||
var result = new Vector2();
|
||||
result.x = -value.x;
|
||||
@@ -1598,6 +1603,7 @@ var es;
|
||||
childClone.transform.parent = this.transform;
|
||||
}
|
||||
};
|
||||
Entity._idGenerator = 0;
|
||||
return Entity;
|
||||
}());
|
||||
es.Entity = Entity;
|
||||
@@ -1689,7 +1695,7 @@ var es;
|
||||
};
|
||||
Scene.prototype.render = function () {
|
||||
if (this._renderers.length == 0) {
|
||||
console.error("there are no renderers in the scene!");
|
||||
console.error("场景中没有渲染器!");
|
||||
return;
|
||||
}
|
||||
for (var i = 0; i < this._renderers.length; i++) {
|
||||
@@ -1750,9 +1756,15 @@ var es;
|
||||
var entity = new es.Entity(name);
|
||||
return this.addEntity(entity);
|
||||
};
|
||||
Scene.prototype.createEntityAsync = function (name) {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) {
|
||||
resolve(_this.createEntity(name));
|
||||
});
|
||||
};
|
||||
Scene.prototype.addEntity = function (entity) {
|
||||
if (this.entities.buffer.contains(entity))
|
||||
console.warn("You are attempting to add the same entity to a scene twice: " + entity);
|
||||
console.warn("\u60A8\u8BD5\u56FE\u5C06\u540C\u4E00\u5B9E\u4F53\u6DFB\u52A0\u5230\u573A\u666F\u4E24\u6B21: " + entity);
|
||||
this.entities.add(entity);
|
||||
entity.scene = this;
|
||||
for (var i = 0; i < entity.transform.childCount; i++)
|
||||
@@ -2177,7 +2189,7 @@ var es;
|
||||
_this.deadzone = new es.Rectangle();
|
||||
_this.focusOffset = es.Vector2.zero;
|
||||
_this.mapLockEnabled = false;
|
||||
_this.mapSize = es.Vector2.zero;
|
||||
_this.mapSize = new es.Rectangle();
|
||||
_this._desiredPositionDelta = new es.Vector2();
|
||||
_this._worldSpaceDeadZone = new es.Rectangle();
|
||||
_this._minimumZoom = 0.3;
|
||||
@@ -2403,8 +2415,8 @@ var es;
|
||||
}
|
||||
};
|
||||
Camera.prototype.clampToMapSize = function (position) {
|
||||
var halfScreen = es.Vector2.multiply(new es.Vector2(this.bounds.width, this.bounds.height), new es.Vector2(0.5));
|
||||
var cameraMax = new es.Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
|
||||
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 cameraMax = new es.Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
return es.Vector2.clamp(position, halfScreen, cameraMax);
|
||||
};
|
||||
Camera.prototype.updateFollow = function () {
|
||||
@@ -2570,6 +2582,7 @@ var es;
|
||||
return this._renderLayer;
|
||||
},
|
||||
set: function (value) {
|
||||
this.setRenderLayer(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
@@ -2658,6 +2671,7 @@ var es;
|
||||
}
|
||||
Mesh.prototype.setTexture = function (texture) {
|
||||
this._mesh.texture = texture;
|
||||
this._mesh.$renderNode = new egret.sys.RenderNode();
|
||||
return this;
|
||||
};
|
||||
Mesh.prototype.reset = function () {
|
||||
@@ -2750,8 +2764,8 @@ var es;
|
||||
};
|
||||
SpriteRenderer.prototype.render = function (camera) {
|
||||
this.sync(camera);
|
||||
this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x;
|
||||
this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y;
|
||||
this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x;
|
||||
this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y;
|
||||
};
|
||||
return SpriteRenderer;
|
||||
}(es.RenderableComponent));
|
||||
@@ -2759,53 +2773,123 @@ var es;
|
||||
})(es || (es = {}));
|
||||
var es;
|
||||
(function (es) {
|
||||
var Bitmap = egret.Bitmap;
|
||||
var RenderTexture = egret.RenderTexture;
|
||||
var TiledSpriteRenderer = (function (_super) {
|
||||
__extends(TiledSpriteRenderer, _super);
|
||||
function TiledSpriteRenderer(sprite) {
|
||||
var _this = _super.call(this, sprite) || this;
|
||||
_this.leftTexture = new egret.Bitmap();
|
||||
_this.rightTexture = new egret.Bitmap();
|
||||
_this.leftTexture.texture = sprite.texture2D;
|
||||
_this.rightTexture.texture = sprite.texture2D;
|
||||
_this.setSprite(sprite);
|
||||
_this.sourceRect = sprite.sourceRect;
|
||||
_this._textureScale = es.Vector2.one;
|
||||
_this._inverseTexScale = es.Vector2.one;
|
||||
_this._gapX = 0;
|
||||
_this._gapY = 0;
|
||||
_this._sourceRect = sprite.sourceRect;
|
||||
var bitmap = _this.displayObject;
|
||||
bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "bounds", {
|
||||
get: function () {
|
||||
if (this._areBoundsDirty) {
|
||||
if (this._sprite) {
|
||||
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
|
||||
this._areBoundsDirty = false;
|
||||
}
|
||||
}
|
||||
return this._bounds;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollX", {
|
||||
get: function () {
|
||||
return this.sourceRect.x;
|
||||
return this._sourceRect.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this.sourceRect.x = value;
|
||||
this._sourceRect.x = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "scrollY", {
|
||||
get: function () {
|
||||
return this.sourceRect.y;
|
||||
return this._sourceRect.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this.sourceRect.y = value;
|
||||
this._sourceRect.y = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "textureScale", {
|
||||
get: function () {
|
||||
return this._textureScale;
|
||||
},
|
||||
set: function (value) {
|
||||
this._textureScale = value;
|
||||
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
||||
this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
|
||||
this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "width", {
|
||||
get: function () {
|
||||
return this._sourceRect.width;
|
||||
},
|
||||
set: function (value) {
|
||||
this._areBoundsDirty = true;
|
||||
this._sourceRect.width = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "height", {
|
||||
get: function () {
|
||||
return this._sourceRect.height;
|
||||
},
|
||||
set: function (value) {
|
||||
this._areBoundsDirty = true;
|
||||
this._sourceRect.height = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TiledSpriteRenderer.prototype, "gapXY", {
|
||||
get: function () {
|
||||
return new es.Vector2(this._gapX, this._gapY);
|
||||
},
|
||||
set: function (value) {
|
||||
this._gapX = value.x;
|
||||
this._gapY = value.y;
|
||||
var renderTexture = new RenderTexture();
|
||||
var newRectangle = this.sprite.sourceRect;
|
||||
newRectangle.x = 0;
|
||||
newRectangle.y = 0;
|
||||
newRectangle.width += this._gapX;
|
||||
newRectangle.height += this._gapY;
|
||||
renderTexture.drawToTexture(this.displayObject, newRectangle);
|
||||
if (!this.displayObject) {
|
||||
this.displayObject = new Bitmap(renderTexture);
|
||||
}
|
||||
else {
|
||||
this.displayObject.texture = renderTexture;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
TiledSpriteRenderer.prototype.setGapXY = function (value) {
|
||||
this.gapXY = value;
|
||||
return this;
|
||||
};
|
||||
TiledSpriteRenderer.prototype.render = function (camera) {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
_super.prototype.render.call(this, camera);
|
||||
var renderTexture = new egret.RenderTexture();
|
||||
var cacheBitmap = new egret.DisplayObjectContainer();
|
||||
cacheBitmap.removeChildren();
|
||||
cacheBitmap.addChild(this.leftTexture);
|
||||
cacheBitmap.addChild(this.rightTexture);
|
||||
this.leftTexture.x = this.sourceRect.x;
|
||||
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
||||
this.leftTexture.y = this.sourceRect.y;
|
||||
this.rightTexture.y = this.sourceRect.y;
|
||||
cacheBitmap.cacheAsBitmap = true;
|
||||
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
||||
var bitmap = this.displayObject;
|
||||
bitmap.width = this.width;
|
||||
bitmap.height = this.height;
|
||||
bitmap.scrollRect = this._sourceRect;
|
||||
};
|
||||
return TiledSpriteRenderer;
|
||||
}(es.SpriteRenderer));
|
||||
@@ -2815,35 +2899,58 @@ var es;
|
||||
(function (es) {
|
||||
var ScrollingSpriteRenderer = (function (_super) {
|
||||
__extends(ScrollingSpriteRenderer, _super);
|
||||
function ScrollingSpriteRenderer() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
function ScrollingSpriteRenderer(sprite) {
|
||||
var _this = _super.call(this, sprite) || this;
|
||||
_this.scrollSpeedX = 15;
|
||||
_this.scroolSpeedY = 0;
|
||||
_this._scrollX = 0;
|
||||
_this._scrollY = 0;
|
||||
_this._scrollWidth = 0;
|
||||
_this._scrollHeight = 0;
|
||||
_this._scrollWidth = _this.width;
|
||||
_this._scrollHeight = _this.height;
|
||||
return _this;
|
||||
}
|
||||
Object.defineProperty(ScrollingSpriteRenderer.prototype, "textureScale", {
|
||||
get: function () {
|
||||
return this._textureScale;
|
||||
},
|
||||
set: function (value) {
|
||||
this._textureScale = value;
|
||||
this._inverseTexScale = new es.Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollWidth", {
|
||||
get: function () {
|
||||
return this._scrollWidth;
|
||||
},
|
||||
set: function (value) {
|
||||
this._scrollWidth = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(ScrollingSpriteRenderer.prototype, "scrollHeight", {
|
||||
get: function () {
|
||||
return this._scrollHeight;
|
||||
},
|
||||
set: function (value) {
|
||||
this._scrollHeight = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
ScrollingSpriteRenderer.prototype.update = function () {
|
||||
this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
|
||||
this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
|
||||
this.sourceRect.x = this._scrollX;
|
||||
this.sourceRect.y = this._scrollY;
|
||||
};
|
||||
ScrollingSpriteRenderer.prototype.render = function (camera) {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
_super.prototype.render.call(this, camera);
|
||||
var renderTexture = new egret.RenderTexture();
|
||||
var cacheBitmap = new egret.DisplayObjectContainer();
|
||||
cacheBitmap.removeChildren();
|
||||
cacheBitmap.addChild(this.leftTexture);
|
||||
cacheBitmap.addChild(this.rightTexture);
|
||||
this.leftTexture.x = this.sourceRect.x;
|
||||
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
||||
this.leftTexture.y = this.sourceRect.y;
|
||||
this.rightTexture.y = this.sourceRect.y;
|
||||
cacheBitmap.cacheAsBitmap = true;
|
||||
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
||||
this._scrollX += this.scrollSpeedX * es.Time.deltaTime;
|
||||
this._scrollY += this.scroolSpeedY * es.Time.deltaTime;
|
||||
this._sourceRect.x = this._scrollX;
|
||||
this._sourceRect.y = this._scrollY;
|
||||
this._sourceRect.width = this._scrollWidth + Math.abs(this._scrollX);
|
||||
this._sourceRect.height = this._scrollHeight + Math.abs(this._scrollY);
|
||||
};
|
||||
return ScrollingSpriteRenderer;
|
||||
}(es.TiledSpriteRenderer));
|
||||
@@ -4217,8 +4324,8 @@ var es;
|
||||
};
|
||||
RenderableComponentList.prototype.addToRenderLayerList = function (component, renderLayer) {
|
||||
var list = this.componentsWithRenderLayer(renderLayer);
|
||||
if (!list.contains(component)) {
|
||||
console.warn("Component renderLayer list already contains this component");
|
||||
if (list.contains(component)) {
|
||||
console.warn("组件呈现层列表已经包含此组件");
|
||||
return;
|
||||
}
|
||||
list.push(component);
|
||||
@@ -4236,6 +4343,7 @@ var es;
|
||||
if (this._componentsNeedSort) {
|
||||
this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
||||
this._componentsNeedSort = false;
|
||||
this.updateEgretList();
|
||||
}
|
||||
if (this._unsortedRenderLayers.length > 0) {
|
||||
for (var i = 0, count = this._unsortedRenderLayers.length; i < count; i++) {
|
||||
@@ -4245,6 +4353,23 @@ var es;
|
||||
}
|
||||
}
|
||||
this._unsortedRenderLayers.length = 0;
|
||||
this.updateEgretList();
|
||||
}
|
||||
};
|
||||
RenderableComponentList.prototype.updateEgretList = function () {
|
||||
var scene = es.Core._instance._scene;
|
||||
if (!scene)
|
||||
return;
|
||||
var _loop_5 = function (i) {
|
||||
var component = this_1._components[i];
|
||||
var egretDisplayObject = scene.$children.find(function (a) { return a.hashCode == component.displayObject.hashCode; });
|
||||
var displayIndex = scene.getChildIndex(egretDisplayObject);
|
||||
if (displayIndex != i)
|
||||
scene.swapChildrenAt(displayIndex, i);
|
||||
};
|
||||
var this_1 = this;
|
||||
for (var i = 0; i < this._components.length; i++) {
|
||||
_loop_5(i);
|
||||
}
|
||||
};
|
||||
RenderableComponentList.compareUpdatableOrder = new es.RenderableComparer();
|
||||
@@ -5822,26 +5947,26 @@ var es;
|
||||
for (var i = 0; i < colliders.length; i++) {
|
||||
var collider = colliders[i];
|
||||
var neighbors = es.Physics.boxcastBroadphase(collider.bounds, collider.collidesWithLayers);
|
||||
var _loop_5 = function (j) {
|
||||
var _loop_6 = function (j) {
|
||||
var neighbor = neighbors[j];
|
||||
if (!collider.isTrigger && !neighbor.isTrigger)
|
||||
return "continue";
|
||||
if (collider.overlaps(neighbor)) {
|
||||
var pair_1 = new es.Pair(collider, neighbor);
|
||||
var shouldReportTriggerEvent = this_1._activeTriggerIntersections.findIndex(function (value) {
|
||||
var shouldReportTriggerEvent = this_2._activeTriggerIntersections.findIndex(function (value) {
|
||||
return value.first == pair_1.first && value.second == pair_1.second;
|
||||
}) == -1 && this_1._previousTriggerIntersections.findIndex(function (value) {
|
||||
}) == -1 && this_2._previousTriggerIntersections.findIndex(function (value) {
|
||||
return value.first == pair_1.first && value.second == pair_1.second;
|
||||
}) == -1;
|
||||
if (shouldReportTriggerEvent)
|
||||
this_1.notifyTriggerListeners(pair_1, true);
|
||||
if (!this_1._activeTriggerIntersections.contains(pair_1))
|
||||
this_1._activeTriggerIntersections.push(pair_1);
|
||||
this_2.notifyTriggerListeners(pair_1, true);
|
||||
if (!this_2._activeTriggerIntersections.contains(pair_1))
|
||||
this_2._activeTriggerIntersections.push(pair_1);
|
||||
}
|
||||
};
|
||||
var this_1 = this;
|
||||
var this_2 = this;
|
||||
for (var j = 0; j < neighbors.length; j++) {
|
||||
_loop_5(j);
|
||||
_loop_6(j);
|
||||
}
|
||||
}
|
||||
es.ListPool.free(colliders);
|
||||
@@ -5849,18 +5974,18 @@ var es;
|
||||
};
|
||||
ColliderTriggerHelper.prototype.checkForExitedColliders = function () {
|
||||
var _this = this;
|
||||
var _loop_6 = function (i) {
|
||||
var index = this_2._previousTriggerIntersections.findIndex(function (value) {
|
||||
var _loop_7 = function (i) {
|
||||
var index = this_3._previousTriggerIntersections.findIndex(function (value) {
|
||||
if (value.first == _this._activeTriggerIntersections[i].first && value.second == _this._activeTriggerIntersections[i].second)
|
||||
return true;
|
||||
return false;
|
||||
});
|
||||
if (index != -1)
|
||||
this_2._previousTriggerIntersections.removeAt(index);
|
||||
this_3._previousTriggerIntersections.removeAt(index);
|
||||
};
|
||||
var this_2 = this;
|
||||
var this_3 = this;
|
||||
for (var i = 0; i < this._activeTriggerIntersections.length; i++) {
|
||||
_loop_6(i);
|
||||
_loop_7(i);
|
||||
}
|
||||
for (var i = 0; i < this._previousTriggerIntersections.length; i++) {
|
||||
this.notifyTriggerListeners(this._previousTriggerIntersections[i], false);
|
||||
@@ -6838,7 +6963,7 @@ var es;
|
||||
for (var y = p1.y; y <= p2.y; y++) {
|
||||
var cell = this.cellAtPosition(x, y);
|
||||
if (!cell)
|
||||
console.error("removing Collider [" + collider + "] from a cell that it is not present in");
|
||||
console.log("\u4ECE\u4E0D\u5B58\u5728\u78B0\u649E\u5668\u7684\u5355\u5143\u683C\u4E2D\u79FB\u9664\u78B0\u649E\u5668: [" + collider + "]");
|
||||
else
|
||||
cell.remove(collider);
|
||||
}
|
||||
@@ -6869,18 +6994,18 @@ var es;
|
||||
var cell = this.cellAtPosition(x, y);
|
||||
if (!cell)
|
||||
continue;
|
||||
var _loop_7 = function (i) {
|
||||
var _loop_8 = function (i) {
|
||||
var collider = cell[i];
|
||||
if (collider == excludeCollider || !es.Flags.isFlagSet(layerMask, collider.physicsLayer))
|
||||
return "continue";
|
||||
if (bounds.intersects(collider.bounds)) {
|
||||
if (!this_3._tempHashSet.firstOrDefault(function (c) { return c.hashCode == collider.hashCode; }))
|
||||
this_3._tempHashSet.push(collider);
|
||||
if (!this_4._tempHashSet.firstOrDefault(function (c) { return c.hashCode == collider.hashCode; }))
|
||||
this_4._tempHashSet.push(collider);
|
||||
}
|
||||
};
|
||||
var this_3 = this;
|
||||
var this_4 = this;
|
||||
for (var i = 0; i < cell.length; i++) {
|
||||
_loop_7(i);
|
||||
_loop_8(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -37,7 +37,7 @@ module es {
|
||||
/**
|
||||
* 當前地圖映射的寬度和高度
|
||||
*/
|
||||
public mapSize: Vector2 = Vector2.zero;
|
||||
public mapSize: Rectangle = new Rectangle();
|
||||
public _targetEntity: Entity;
|
||||
public _targetCollider: Collider;
|
||||
public _desiredPositionDelta: Vector2 = new Vector2();
|
||||
@@ -385,8 +385,8 @@ module es {
|
||||
* @param position
|
||||
*/
|
||||
public clampToMapSize(position: Vector2) {
|
||||
let halfScreen = Vector2.multiply(new Vector2(this.bounds.width, this.bounds.height), new Vector2(0.5));
|
||||
let cameraMax = new Vector2(this.mapSize.x - halfScreen.x, this.mapSize.y - halfScreen.y);
|
||||
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 cameraMax = new Vector2(this.mapSize.width - halfScreen.x, this.mapSize.height - halfScreen.y);
|
||||
|
||||
return Vector2.clamp(position, halfScreen, cameraMax);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ module es {
|
||||
|
||||
public setTexture(texture: egret.Texture): Mesh {
|
||||
this._mesh.texture = texture;
|
||||
this._mesh.$renderNode = new egret.sys.RenderNode();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ module es {
|
||||
}
|
||||
|
||||
public set renderLayer(value: number) {
|
||||
|
||||
this.setRenderLayer(value);
|
||||
}
|
||||
|
||||
protected _bounds: Rectangle = new Rectangle();
|
||||
|
||||
@@ -1,37 +1,67 @@
|
||||
///<reference path="./TiledSpriteRenderer.ts"/>
|
||||
module es {
|
||||
export class ScrollingSpriteRenderer extends TiledSpriteRenderer {
|
||||
public scrollSpeedX = 15;
|
||||
public scroolSpeedY = 0;
|
||||
private _scrollX = 0;
|
||||
private _scrollY = 0;
|
||||
import Bitmap = egret.Bitmap;
|
||||
|
||||
public update() {
|
||||
this._scrollX += this.scrollSpeedX * Time.deltaTime;
|
||||
this._scrollY += this.scroolSpeedY * Time.deltaTime;
|
||||
this.sourceRect.x = this._scrollX;
|
||||
this.sourceRect.y = this._scrollY;
|
||||
export class ScrollingSpriteRenderer extends TiledSpriteRenderer {
|
||||
/**
|
||||
* x自动滚动速度(以像素/s为单位)
|
||||
*/
|
||||
public scrollSpeedX = 15;
|
||||
/**
|
||||
* 自动滚动的y速度(以像素/s为单位)
|
||||
*/
|
||||
public scroolSpeedY = 0;
|
||||
|
||||
public get textureScale(): Vector2 {
|
||||
return this._textureScale;
|
||||
}
|
||||
|
||||
public render(camera: Camera) {
|
||||
public set textureScale(value: Vector2){
|
||||
this._textureScale = value;
|
||||
|
||||
// 重新计算我们的inverseTextureScale和源矩形大小
|
||||
this._inverseTexScale = new Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
||||
}
|
||||
|
||||
public set scrollWidth(value: number){
|
||||
this._scrollWidth = value;
|
||||
}
|
||||
|
||||
public get scrollWidth(){
|
||||
return this._scrollWidth;
|
||||
}
|
||||
|
||||
public set scrollHeight(value: number){
|
||||
this._scrollHeight = value;
|
||||
}
|
||||
|
||||
public get scrollHeight(){
|
||||
return this._scrollHeight;
|
||||
}
|
||||
|
||||
private _scrollX = 0;
|
||||
private _scrollY = 0;
|
||||
private _scrollWidth = 0;
|
||||
private _scrollHeight = 0;
|
||||
|
||||
constructor(sprite: Sprite) {
|
||||
super(sprite);
|
||||
|
||||
this._scrollWidth = this.width;
|
||||
this._scrollHeight = this.height;
|
||||
}
|
||||
|
||||
public update() {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
|
||||
super.render(camera);
|
||||
this._scrollX += this.scrollSpeedX * Time.deltaTime;
|
||||
this._scrollY += this.scroolSpeedY * Time.deltaTime;
|
||||
|
||||
let renderTexture = new egret.RenderTexture();
|
||||
let cacheBitmap = new egret.DisplayObjectContainer();
|
||||
cacheBitmap.removeChildren();
|
||||
cacheBitmap.addChild(this.leftTexture);
|
||||
cacheBitmap.addChild(this.rightTexture);
|
||||
|
||||
this.leftTexture.x = this.sourceRect.x;
|
||||
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
||||
this.leftTexture.y = this.sourceRect.y;
|
||||
this.rightTexture.y = this.sourceRect.y;
|
||||
|
||||
cacheBitmap.cacheAsBitmap = true;
|
||||
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
||||
this._sourceRect.x = this._scrollX;
|
||||
this._sourceRect.y = this._scrollY;
|
||||
this._sourceRect.width = this._scrollWidth + Math.abs(this._scrollX);
|
||||
this._sourceRect.height = this._scrollHeight + Math.abs(this._scrollY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ module es {
|
||||
public render(camera: Camera) {
|
||||
this.sync(camera);
|
||||
|
||||
this.displayObject.x = this.entity.position.x - this.origin.x + this.localOffset.x - camera.position.x + camera.origin.x;
|
||||
this.displayObject.y = this.entity.position.y - this.origin.y + this.localOffset.y - camera.position.y + camera.origin.y;
|
||||
this.displayObject.x = this.entity.position.x + this.localOffset.x - camera.position.x + camera.origin.x;
|
||||
this.displayObject.y = this.entity.position.y + this.localOffset.y - camera.position.y + camera.origin.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,148 @@
|
||||
///<reference path="./SpriteRenderer.ts" />
|
||||
module es {
|
||||
import Bitmap = egret.Bitmap;
|
||||
import RenderTexture = egret.RenderTexture;
|
||||
|
||||
/**
|
||||
* 滚动由两张图片组合而成
|
||||
*/
|
||||
export class TiledSpriteRenderer extends SpriteRenderer {
|
||||
protected sourceRect: Rectangle;
|
||||
protected leftTexture: egret.Bitmap;
|
||||
protected rightTexture: egret.Bitmap;
|
||||
public get bounds(): Rectangle {
|
||||
if (this._areBoundsDirty){
|
||||
if (this._sprite){
|
||||
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin,
|
||||
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
|
||||
this._areBoundsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
return this._bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纹理滚动的x值
|
||||
*/
|
||||
public get scrollX() {
|
||||
return this._sourceRect.x;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纹理滚动的x值
|
||||
* @param value
|
||||
*/
|
||||
public set scrollX(value: number) {
|
||||
this._sourceRect.x = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纹理滚动的y值
|
||||
*/
|
||||
public get scrollY() {
|
||||
return this._sourceRect.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纹理滚动的y值
|
||||
* @param value
|
||||
*/
|
||||
public set scrollY(value: number) {
|
||||
this._sourceRect.y = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纹理比例尺
|
||||
*/
|
||||
public get textureScale(): Vector2 {
|
||||
return this._textureScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 纹理比例尺
|
||||
* @param value
|
||||
*/
|
||||
public set textureScale(value: Vector2) {
|
||||
this._textureScale = value;
|
||||
|
||||
// 重新计算我们的inverseTextureScale和源矩形大小
|
||||
this._inverseTexScale = new Vector2(1 / this._textureScale.x, 1 / this._textureScale.y);
|
||||
this._sourceRect.width = this._sprite.sourceRect.width * this._inverseTexScale.x;
|
||||
this._sourceRect.height = this._sprite.sourceRect.height * this._inverseTexScale.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 覆盖宽度值,这样TiledSprite可以有一个独立于其纹理的宽度
|
||||
*/
|
||||
public get width(): number{
|
||||
return this._sourceRect.width;
|
||||
}
|
||||
|
||||
public set width(value: number) {
|
||||
this._areBoundsDirty = true;
|
||||
this._sourceRect.width = value;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this._sourceRect.height;
|
||||
}
|
||||
|
||||
public set height(value: number) {
|
||||
this._areBoundsDirty = true;
|
||||
this._sourceRect.height = value;
|
||||
}
|
||||
|
||||
public get gapXY(): Vector2{
|
||||
return new Vector2(this._gapX, this._gapY);
|
||||
}
|
||||
|
||||
public set gapXY(value: Vector2){
|
||||
this._gapX = value.x;
|
||||
this._gapY = value.y;
|
||||
|
||||
let renderTexture = new RenderTexture();
|
||||
let newRectangle = this.sprite.sourceRect;
|
||||
newRectangle.x = 0;
|
||||
newRectangle.y = 0;
|
||||
newRectangle.width += this._gapX;
|
||||
newRectangle.height += this._gapY;
|
||||
renderTexture.drawToTexture(this.displayObject, newRectangle);
|
||||
|
||||
if (!this.displayObject){
|
||||
this.displayObject = new Bitmap(renderTexture);
|
||||
}else{
|
||||
(this.displayObject as Bitmap).texture = renderTexture;
|
||||
}
|
||||
}
|
||||
|
||||
protected _sourceRect: Rectangle;
|
||||
protected _textureScale = Vector2.one;
|
||||
protected _inverseTexScale = Vector2.one;
|
||||
private _gapX = 0;
|
||||
private _gapY = 0;
|
||||
|
||||
constructor(sprite: Sprite) {
|
||||
super(sprite);
|
||||
|
||||
this.leftTexture = new egret.Bitmap();
|
||||
this.rightTexture = new egret.Bitmap();
|
||||
this.leftTexture.texture = sprite.texture2D;
|
||||
this.rightTexture.texture = sprite.texture2D;
|
||||
|
||||
this.setSprite(sprite);
|
||||
this.sourceRect = sprite.sourceRect;
|
||||
this._sourceRect = sprite.sourceRect;
|
||||
let bitmap = this.displayObject as Bitmap;
|
||||
bitmap.$fillMode = egret.BitmapFillMode.REPEAT;
|
||||
}
|
||||
|
||||
public get scrollX() {
|
||||
return this.sourceRect.x;
|
||||
}
|
||||
|
||||
public set scrollX(value: number) {
|
||||
this.sourceRect.x = value;
|
||||
}
|
||||
|
||||
public get scrollY() {
|
||||
return this.sourceRect.y;
|
||||
}
|
||||
|
||||
public set scrollY(value: number) {
|
||||
this.sourceRect.y = value;
|
||||
/**
|
||||
* 设置间隔
|
||||
* @param value
|
||||
*/
|
||||
public setGapXY(value: Vector2): TiledSpriteRenderer {
|
||||
this.gapXY = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
public render(camera: es.Camera) {
|
||||
if (!this.sprite)
|
||||
return;
|
||||
|
||||
super.render(camera);
|
||||
|
||||
let renderTexture = new egret.RenderTexture();
|
||||
let cacheBitmap = new egret.DisplayObjectContainer();
|
||||
cacheBitmap.removeChildren();
|
||||
cacheBitmap.addChild(this.leftTexture);
|
||||
cacheBitmap.addChild(this.rightTexture);
|
||||
|
||||
this.leftTexture.x = this.sourceRect.x;
|
||||
this.rightTexture.x = this.sourceRect.x - this.sourceRect.width;
|
||||
this.leftTexture.y = this.sourceRect.y;
|
||||
this.rightTexture.y = this.sourceRect.y;
|
||||
|
||||
cacheBitmap.cacheAsBitmap = true;
|
||||
renderTexture.drawToTexture(cacheBitmap, new egret.Rectangle(0, 0, this.sourceRect.width, this.sourceRect.height));
|
||||
let bitmap = this.displayObject as Bitmap;
|
||||
bitmap.width = this.width;
|
||||
bitmap.height = this.height;
|
||||
bitmap.scrollRect = this._sourceRect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module es {
|
||||
export class Entity {
|
||||
public static _idGenerator: number;
|
||||
public static _idGenerator: number = 0;
|
||||
|
||||
/**
|
||||
* 当前实体所属的场景
|
||||
|
||||
+12
-2
@@ -152,7 +152,7 @@ module es {
|
||||
|
||||
public render() {
|
||||
if (this._renderers.length == 0) {
|
||||
console.error("there are no renderers in the scene!");
|
||||
console.error("场景中没有渲染器!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -262,13 +262,23 @@ module es {
|
||||
return this.addEntity(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将实体添加到此场景,并返回它
|
||||
* @param name
|
||||
*/
|
||||
public createEntityAsync(name: string): Promise<Entity> {
|
||||
return new Promise<Entity>(resolve => {
|
||||
resolve(this.createEntity(name));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 在场景的实体列表中添加一个实体
|
||||
* @param entity
|
||||
*/
|
||||
public addEntity(entity: Entity) {
|
||||
if (this.entities.buffer.contains(entity))
|
||||
console.warn(`You are attempting to add the same entity to a scene twice: ${entity}`);
|
||||
console.warn(`您试图将同一实体添加到场景两次: ${entity}`);
|
||||
this.entities.add(entity);
|
||||
entity.scene = this;
|
||||
|
||||
|
||||
@@ -58,8 +58,8 @@ module es {
|
||||
|
||||
public addToRenderLayerList(component: IRenderable, renderLayer: number) {
|
||||
let list = this.componentsWithRenderLayer(renderLayer);
|
||||
if (!list.contains(component)) {
|
||||
console.warn("Component renderLayer list already contains this component");
|
||||
if (list.contains(component)) {
|
||||
console.warn("组件呈现层列表已经包含此组件");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ module es {
|
||||
if (this._componentsNeedSort) {
|
||||
this._components.sort(RenderableComponentList.compareUpdatableOrder.compare);
|
||||
this._componentsNeedSort = false;
|
||||
this.updateEgretList();
|
||||
}
|
||||
|
||||
if (this._unsortedRenderLayers.length > 0) {
|
||||
@@ -95,6 +96,20 @@ module es {
|
||||
}
|
||||
|
||||
this._unsortedRenderLayers.length = 0;
|
||||
this.updateEgretList();
|
||||
}
|
||||
}
|
||||
|
||||
private updateEgretList(){
|
||||
let scene = Core._instance._scene;
|
||||
if (!scene)
|
||||
return;
|
||||
|
||||
for (let i = 0 ; i < this._components.length; i ++){
|
||||
let component = this._components[i] as RenderableComponent;
|
||||
let egretDisplayObject = scene.$children.find(a => {return a.hashCode == component.displayObject.hashCode});
|
||||
let displayIndex = scene.getChildIndex(egretDisplayObject);
|
||||
if (displayIndex != i) scene.swapChildrenAt(displayIndex, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +154,17 @@ module es {
|
||||
return Math.sqrt((v1 * v1) + (v2 * v2));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回两个向量之间的角度,单位是度数
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public static angle(from: Vector2, to: Vector2): number{
|
||||
from = Vector2.normalize(from);
|
||||
to = Vector2.normalize(to);
|
||||
return Math.acos(MathHelper.clamp(Vector2.dot(from, to), -1, 1)) * MathHelper.Rad2Deg;
|
||||
}
|
||||
|
||||
/**
|
||||
* 矢量反演的结果
|
||||
* @param value
|
||||
|
||||
@@ -73,7 +73,7 @@ module es {
|
||||
// 单元格应该始终存在,因为这个碰撞器应该在所有查询的单元格中
|
||||
let cell = this.cellAtPosition(x, y);
|
||||
if (!cell)
|
||||
console.error(`removing Collider [${collider}] from a cell that it is not present in`);
|
||||
console.log(`从不存在碰撞器的单元格中移除碰撞器: [${collider}]`);
|
||||
else
|
||||
cell.remove(collider);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user