Compare commits

..

20 Commits

Author SHA1 Message Date
YHH 14b70b307c camera.mapSize 支持左上顶点更改 2020-08-08 15:09:10 +08:00
YHH a39b98b5d9 #23 修复绘制层级问题 2020-08-08 14:43:43 +08:00
YHH 3492bbdf5e 修复scrollingSprite无法向左移动问题 2020-08-08 14:11:25 +08:00
YHH 7d0bcbcb32 demo fix 2020-08-08 10:18:56 +08:00
YHH c02a3aa071 Merge branch 'master' of https://github.com/esengine/egret-framework 2020-08-08 10:12:43 +08:00
YHH a105bb11ca 修复origin导致显示位置错误问题 2020-08-08 10:12:08 +08:00
YHH 3fbbba7ac2 Merge pull request #25 from esengine/develop
#16 新增createEntityAsync方法
2020-08-08 09:51:24 +08:00
YHH 7cd38ea54e #16 新增createEntityAsync方法
修复entity.id为null
2020-08-08 09:50:40 +08:00
YHH 42852c5dba Merge pull request #24 from esengine/develop
#23 组件绘制层支持
2020-08-08 09:44:05 +08:00
YHH 6a3622a5ef #23 组件绘制层支持 2020-08-08 09:43:03 +08:00
YHH 03b568e28d Merge pull request #22 from esengine/develop
#21 新增gapXY用于平铺/滚动间距
2020-08-08 09:07:35 +08:00
YHH e7fb9e0d6b #21 完善 gapxy 2020-08-08 09:06:32 +08:00
yhh 463c64c628 #21 新增gapXY用于平铺/滚动间距 2020-08-07 15:34:42 +08:00
YHH 4025bc8554 Merge pull request #20 from esengine/develop
实现精灵平铺效果
2020-08-07 11:03:05 +08:00
yhh 1bf822725a #19 滚动精灵支持 2020-08-07 11:02:04 +08:00
YHH 359d7ae223 实现 scrollingSprite 2020-08-07 09:21:55 +08:00
YHH c611e31f7e Merge branch 'master' into develop
# Conflicts:
#	demo/libs/framework/framework.min.js
#	demo/src/game/MainScene.ts
#	source/bin/framework.min.js
2020-08-07 08:51:19 +08:00
YHH 834ad565e1 #19 实现精灵平铺效果 2020-08-07 08:50:26 +08:00
YHH 1e3b2763e8 Merge branch 'develop' of https://github.com/esengine/egret-framework into develop 2020-07-08 22:00:39 +08:00
YHH a3dacd04f0 Merge branch 'master' into develop
# Conflicts:
#	demo/libs/framework/framework.min.js
#	demo/src/game/MainScene.ts
#	source/bin/framework.min.js
2020-07-08 21:56:07 +08:00
18 changed files with 686 additions and 245 deletions
+22 -6
View File
@@ -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
View File
@@ -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);
}
}
}
File diff suppressed because one or more lines are too long
+16 -12
View File
@@ -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();
+22 -6
View File
@@ -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
View File
@@ -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);
}
}
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -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);
}
+1
View File
@@ -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);
}
}
}
+2 -2
View File
@@ -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;
}
}
}
+128 -40
View File
@@ -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 -1
View File
@@ -1,6 +1,6 @@
module es {
export class Entity {
public static _idGenerator: number;
public static _idGenerator: number = 0;
/**
*
+12 -2
View File
@@ -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);
}
}
}
+11
View File
@@ -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
+1 -1
View File
@@ -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);
}