新增Sprite用于控制纹理

This commit is contained in:
yhh
2020-06-19 18:16:42 +08:00
parent 981e149ca5
commit d22c5775c2
18 changed files with 348 additions and 191 deletions

View File

@@ -28,7 +28,7 @@
- [ ] 网格弹簧组件 - [ ] 网格弹簧组件
- [ ] 相机震动组件 - [ ] 相机震动组件
- [ ] 霓虹灯组件 - [ ] 霓虹灯组件
- [ ] 跟随相机组件 - [x] 跟随相机组件
- [ ] 系统列表 - [ ] 系统列表
- [ ] 被动系统 - [ ] 被动系统
- [ ] 协调系统 - [ ] 协调系统

View File

@@ -146,6 +146,7 @@ declare abstract class Component {
readonly transform: Transform; readonly transform: Transform;
enabled: boolean; enabled: boolean;
setEnabled(isEnabled: boolean): this; setEnabled(isEnabled: boolean): this;
readonly stage: egret.Stage;
initialize(): void; initialize(): void;
onAddedToEntity(): void; onAddedToEntity(): void;
onRemovedFromEntity(): void; onRemovedFromEntity(): void;
@@ -185,6 +186,7 @@ declare class Entity {
enabled: boolean; enabled: boolean;
setEnabled(isEnabled: boolean): this; setEnabled(isEnabled: boolean): this;
tag: number; tag: number;
readonly stage: egret.Stage;
constructor(name: string); constructor(name: string);
updateOrder: number; updateOrder: number;
setUpdateOrder(updateOrder: number): this; setUpdateOrder(updateOrder: number): this;
@@ -334,17 +336,17 @@ declare class Camera extends Component {
setZoom(zoom: number): this; setZoom(zoom: number): this;
setPosition(position: Vector2): this; setPosition(position: Vector2): this;
forceMatrixUpdate(): void; forceMatrixUpdate(): void;
updateMatrixes(): void; protected updateMatrixes(): void;
screenToWorldPoint(screenPosition: Vector2): Vector2; screenToWorldPoint(screenPosition: Vector2): Vector2;
worldToScreenPoint(worldPosition: Vector2): Vector2; worldToScreenPoint(worldPosition: Vector2): Vector2;
onEntityTransformChanged(comp: ComponentTransform): void; onEntityTransformChanged(comp: ComponentTransform): void;
destory(): void; destory(): void;
} }
declare class CameraInset { declare class CameraInset {
left: any; left: number;
right: any; right: number;
top: any; top: number;
bottom: any; bottom: number;
} }
declare class FollowCamera extends Component { declare class FollowCamera extends Component {
camera: Camera; camera: Camera;
@@ -400,26 +402,30 @@ declare abstract class RenderableComponent extends Component implements IRendera
readonly bounds: Rectangle; readonly bounds: Rectangle;
protected getWidth(): number; protected getWidth(): number;
protected getHeight(): number; protected getHeight(): number;
protected getBounds(): Rectangle;
protected onBecameVisible(): void; protected onBecameVisible(): void;
protected onBecameInvisible(): void; protected onBecameInvisible(): void;
abstract render(camera: Camera): any; abstract render(camera: Camera): any;
isVisibleFromCamera(camera: Camera): boolean; isVisibleFromCamera(camera: Camera): boolean;
onEntityTransformChanged(comp: ComponentTransform): void; onEntityTransformChanged(comp: ComponentTransform): void;
} }
declare enum SpriteEffects { declare class Sprite {
none = 0, texture2D: egret.Texture;
flipHorizontally = 1, readonly sourceRect: Rectangle;
flipVertically = 2 readonly center: Vector2;
origin: Vector2;
readonly uvs: Rectangle;
constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
} }
declare class SpriteRenderer extends RenderableComponent { declare class SpriteRenderer extends RenderableComponent {
private _sprite; private _sprite;
private _origin; private _origin;
protected getBounds(): Rectangle; private _bitmap;
sprite: egret.DisplayObject; readonly bounds: Rectangle;
setSprite(sprite: egret.DisplayObject): SpriteRenderer; sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer;
origin: Vector2; origin: Vector2;
setOrigin(origin: Vector2): this; setOrigin(origin: Vector2): this;
isVisibleFromCamera(camera: Camera): boolean;
render(camera: Camera): void; render(camera: Camera): void;
} }
interface ITriggerListener { interface ITriggerListener {
@@ -677,6 +683,7 @@ declare class Rectangle {
intersects(value: Rectangle): boolean; intersects(value: Rectangle): boolean;
contains(value: Vector2): boolean; contains(value: Vector2): boolean;
containsRect(value: Rectangle): boolean; containsRect(value: Rectangle): boolean;
getHalfSize(): Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
getClosestPointOnRectangleBorderToPoint(point: Point): { getClosestPointOnRectangleBorderToPoint(point: Point): {
res: Vector2; res: Vector2;

View File

@@ -771,6 +771,15 @@ var Component = (function () {
} }
return this; return this;
}; };
Object.defineProperty(Component.prototype, "stage", {
get: function () {
if (!this.entity)
return null;
return this.entity.stage;
},
enumerable: true,
configurable: true
});
Component.prototype.initialize = function () { Component.prototype.initialize = function () {
}; };
Component.prototype.onAddedToEntity = function () { Component.prototype.onAddedToEntity = function () {
@@ -952,6 +961,15 @@ var Entity = (function () {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(Entity.prototype, "stage", {
get: function () {
if (!this.scene)
return null;
return this.scene.stage;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Entity.prototype, "updateOrder", { Object.defineProperty(Entity.prototype, "updateOrder", {
get: function () { get: function () {
return this._updateOrder; return this._updateOrder;
@@ -1217,9 +1235,9 @@ var ComponentTransform;
var Transform = (function () { var Transform = (function () {
function Transform(entity) { function Transform(entity) {
this._localRotation = 0; this._localRotation = 0;
this._worldTransform = new Matrix2D(); this._worldTransform = Matrix2D.identity;
this._worldToLocalTransform = new Matrix2D(); this._worldToLocalTransform = Matrix2D.identity;
this._worldInverseTransform = new Matrix2D(); this._worldInverseTransform = Matrix2D.identity;
this._rotation = 0; this._rotation = 0;
this.entity = entity; this.entity = entity;
this._scale = this._localScale = Vector2.one; this._scale = this._localScale = Vector2.one;
@@ -1317,12 +1335,15 @@ var Transform = (function () {
Object.defineProperty(Transform.prototype, "position", { Object.defineProperty(Transform.prototype, "position", {
get: function () { get: function () {
this.updateTransform(); this.updateTransform();
if (!this.parent) { if (this._positionDirty) {
this._position = this._localPosition; if (!this.parent) {
} this._position = this._localPosition;
else { }
this.parent.updateTransform(); else {
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); this.parent.updateTransform();
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
}
this._positionDirty = false;
} }
return this._position; return this._position;
}, },
@@ -1441,6 +1462,7 @@ var Transform = (function () {
else { else {
this.localPosition = position; this.localPosition = position;
} }
this._positionDirty = false;
return this; return this;
}; };
Transform.prototype.setDirty = function (dirtyFlagType) { Transform.prototype.setDirty = function (dirtyFlagType) {
@@ -1530,9 +1552,9 @@ var Camera = (function (_super) {
if (this._areMatrixesDirty) if (this._areMatrixesDirty)
this.updateMatrixes(); this.updateMatrixes();
if (this._areBoundsDirty) { if (this._areBoundsDirty) {
var stage = this.entity.scene.stage; var stage = this.stage;
var topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); var topLeft = this.screenToWorldPoint(new Vector2(stage.x + this._inset.left, stage.y + this._inset.top));
var bottomRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, stage.stageHeight - this._inset.bottom)); var bottomRight = this.screenToWorldPoint(new Vector2(stage.x + stage.stageWidth - this._inset.right, stage.y + stage.stageHeight - this._inset.bottom));
if (this.entity.transform.rotation != 0) { if (this.entity.transform.rotation != 0) {
var topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top)); var topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top));
var bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, stage.stageHeight - this._inset.bottom)); var bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, stage.stageHeight - this._inset.bottom));
@@ -1706,6 +1728,10 @@ var Camera = (function (_super) {
}(Component)); }(Component));
var CameraInset = (function () { var CameraInset = (function () {
function CameraInset() { function CameraInset() {
this.left = 0;
this.right = 0;
this.top = 0;
this.bottom = 0;
} }
return CameraInset; return CameraInset;
}()); }());
@@ -1903,7 +1929,11 @@ var RenderableComponent = (function (_super) {
}); });
Object.defineProperty(RenderableComponent.prototype, "bounds", { Object.defineProperty(RenderableComponent.prototype, "bounds", {
get: function () { get: function () {
return this.getBounds(); if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
@@ -1914,43 +1944,53 @@ var RenderableComponent = (function (_super) {
RenderableComponent.prototype.getHeight = function () { RenderableComponent.prototype.getHeight = function () {
return this.bounds.height; return this.bounds.height;
}; };
RenderableComponent.prototype.getBounds = function () {
if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
};
RenderableComponent.prototype.onBecameVisible = function () { }; RenderableComponent.prototype.onBecameVisible = function () { };
RenderableComponent.prototype.onBecameInvisible = function () { }; RenderableComponent.prototype.onBecameInvisible = function () { };
RenderableComponent.prototype.isVisibleFromCamera = function (camera) { RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
return true; this.isVisible = camera.bounds.intersects(this.bounds);
return this.isVisible;
}; };
RenderableComponent.prototype.onEntityTransformChanged = function (comp) { RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
this._areBoundsDirty = true; this._areBoundsDirty = true;
}; };
return RenderableComponent; return RenderableComponent;
}(Component)); }(Component));
var SpriteEffects; var Sprite = (function () {
(function (SpriteEffects) { function Sprite(texture, sourceRect, origin) {
SpriteEffects[SpriteEffects["none"] = 0] = "none"; if (sourceRect === void 0) { sourceRect = new Rectangle(texture.textureWidth, texture.textureHeight); }
SpriteEffects[SpriteEffects["flipHorizontally"] = 1] = "flipHorizontally"; if (origin === void 0) { origin = sourceRect.getHalfSize(); }
SpriteEffects[SpriteEffects["flipVertically"] = 2] = "flipVertically"; this.uvs = new Rectangle();
})(SpriteEffects || (SpriteEffects = {})); this.texture2D = texture;
this.sourceRect = sourceRect;
this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5);
this.origin = origin;
var inverseTexW = 1 / texture.textureWidth;
var inverseTexH = 1 / texture.textureHeight;
this.uvs.x = sourceRect.x * inverseTexW;
this.uvs.y = sourceRect.y * inverseTexH;
this.uvs.width = sourceRect.width * inverseTexW;
this.uvs.height = sourceRect.height * inverseTexH;
}
return Sprite;
}());
var SpriteRenderer = (function (_super) { var SpriteRenderer = (function (_super) {
__extends(SpriteRenderer, _super); __extends(SpriteRenderer, _super);
function SpriteRenderer() { function SpriteRenderer() {
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
SpriteRenderer.prototype.getBounds = function () { Object.defineProperty(SpriteRenderer.prototype, "bounds", {
if (this._areBoundsDirty) { get: function () {
if (this._sprite) { if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.width, this._sprite.height); if (this._sprite) {
this._areBoundsDirty = false; this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.texture2D.textureWidth, this._sprite.texture2D.textureHeight);
this._areBoundsDirty = false;
}
} }
return this.bounds; return this._bounds;
} },
}; enumerable: true,
configurable: true
});
Object.defineProperty(SpriteRenderer.prototype, "sprite", { Object.defineProperty(SpriteRenderer.prototype, "sprite", {
get: function () { get: function () {
return this._sprite; return this._sprite;
@@ -1964,7 +2004,9 @@ var SpriteRenderer = (function (_super) {
SpriteRenderer.prototype.setSprite = function (sprite) { SpriteRenderer.prototype.setSprite = function (sprite) {
this._sprite = sprite; this._sprite = sprite;
if (this._sprite) if (this._sprite)
this._origin = new Vector2(this._sprite.anchorOffsetX, this._sprite.anchorOffsetY); this._origin = sprite.origin;
this._bitmap = new egret.Bitmap(sprite.texture2D);
this.stage.addChild(this._bitmap);
return this; return this;
}; };
Object.defineProperty(SpriteRenderer.prototype, "origin", { Object.defineProperty(SpriteRenderer.prototype, "origin", {
@@ -1984,16 +2026,21 @@ var SpriteRenderer = (function (_super) {
} }
return this; return this;
}; };
SpriteRenderer.prototype.isVisibleFromCamera = function (camera) {
this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds);
this._bitmap.visible = this.isVisible;
return this.isVisible;
};
SpriteRenderer.prototype.render = function (camera) { SpriteRenderer.prototype.render = function (camera) {
if (!this.sprite) if (!this.sprite)
return; return;
this.sprite.x = this.entity.transform.position.x - camera.transform.position.x; this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x;
this.sprite.y = this.entity.transform.position.y - camera.transform.position.y; this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y;
this.sprite.rotation = this.entity.transform.rotation; this._bitmap.rotation = this.entity.transform.rotation;
this.sprite.anchorOffsetX = this._origin.x; this._bitmap.anchorOffsetX = this._origin.x;
this.sprite.anchorOffsetY = this._origin.y; this._bitmap.anchorOffsetY = this._origin.y;
this.sprite.scaleX = this.entity.transform.scale.x; this._bitmap.scaleX = this.entity.transform.scale.x;
this.sprite.scaleY = this.entity.transform.scale.y; this._bitmap.scaleY = this.entity.transform.scale.y;
}; };
return SpriteRenderer; return SpriteRenderer;
}(RenderableComponent)); }(RenderableComponent));
@@ -3162,6 +3209,9 @@ var Rectangle = (function () {
(this.y <= value.y)) && (this.y <= value.y)) &&
(value.y < (this.y + this.height))); (value.y < (this.y + this.height)));
}; };
Rectangle.prototype.getHalfSize = function () {
return new Vector2(this.width * 0.5, this.height * 0.5);
};
Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { Rectangle.fromMinMax = function (minX, minY, maxX, maxY) {
return new Rectangle(minX, minY, maxX - minX, maxY - minY); return new Rectangle(minX, minY, maxX - minX, maxY - minY);
}; };
@@ -3230,10 +3280,10 @@ var Rectangle = (function () {
var topRight = new Vector2(worldPosX + width, worldPosY); var topRight = new Vector2(worldPosX + width, worldPosY);
var bottomLeft = new Vector2(worldPosX, worldPosY + height); var bottomLeft = new Vector2(worldPosX, worldPosY + height);
var bottomRight = new Vector2(worldPosX + width, worldPosY + height); var bottomRight = new Vector2(worldPosX + width, worldPosY + height);
topLeft = Vector2.transform(topLeft, this._transformMat); topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
topRight = Vector2.transform(topRight, this._transformMat); topRight = Vector2Ext.transformR(topRight, this._transformMat);
bottomLeft = Vector2.transform(bottomLeft, this._transformMat); bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
bottomRight = Vector2.transform(bottomRight, this._transformMat); bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);

File diff suppressed because one or more lines are too long

View File

@@ -97,20 +97,18 @@ class Main extends eui.UILayer {
* Create scene interface * Create scene interface
*/ */
protected createGameScene(): void { protected createGameScene(): void {
let image = new eui.Image(RES.getRes("checkbox_select_disabled_png")); let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
this.addChild(image);
let scene = SceneManager.createScene("main", new MainScene(this)).setActive(); let scene = SceneManager.createScene("main", new MainScene(this)).setActive();
let player = scene.createEntity("player"); let player = scene.createEntity("player");
player.addComponent(new SpriteRenderer()).setSprite(image); player.addComponent(new SpriteRenderer()).setSprite(sprite);
player.addComponent(new SpawnComponent(EnemyType.worm)); player.addComponent(new SpawnComponent(EnemyType.worm));
player.addComponent(new PlayerController()); player.addComponent(new PlayerController());
player.addComponent(new FollowCamera(player)).focusOffset = new Vector2(this.stage.stageWidth / 2, this.stage.stageHeight / 2); player.addComponent(new FollowCamera(player));
for (let i = 0; i < 20; i ++){ for (let i = 0; i < 20; i ++){
let image = new eui.Image(RES.getRes("checkbox_select_disabled_png")); let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
let player2 = scene.createEntity("player2"); let player2 = scene.createEntity("player2");
player2.addComponent(new SpriteRenderer()).setSprite(image); player2.addComponent(new SpriteRenderer()).setSprite(sprite);
this.addChild(image);
player2.transform.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i); player2.transform.position = new Vector2(Math.random() * 100 * i, Math.random() * 100 * i);
} }

View File

@@ -22,8 +22,7 @@ class PlayerController extends Component {
if (this.down){ if (this.down){
let camera = SceneManager.getActiveScene().camera; let camera = SceneManager.getActiveScene().camera;
let worldVec = camera.screenToWorldPoint(this.touchPoint); let worldVec = camera.screenToWorldPoint(this.touchPoint);
this.entity.position = Vector2.lerp(this.entity.position, Vector2.add(worldVec, this.entity.position = Vector2.lerp(this.entity.position, worldVec, Time.deltaTime);
new Vector2(this.entity.scene.stage.stageWidth / 2, this.entity.scene.stage.stageHeight / 2)), Time.deltaTime);
} }
} }
} }

View File

@@ -146,6 +146,7 @@ declare abstract class Component {
readonly transform: Transform; readonly transform: Transform;
enabled: boolean; enabled: boolean;
setEnabled(isEnabled: boolean): this; setEnabled(isEnabled: boolean): this;
readonly stage: egret.Stage;
initialize(): void; initialize(): void;
onAddedToEntity(): void; onAddedToEntity(): void;
onRemovedFromEntity(): void; onRemovedFromEntity(): void;
@@ -185,6 +186,7 @@ declare class Entity {
enabled: boolean; enabled: boolean;
setEnabled(isEnabled: boolean): this; setEnabled(isEnabled: boolean): this;
tag: number; tag: number;
readonly stage: egret.Stage;
constructor(name: string); constructor(name: string);
updateOrder: number; updateOrder: number;
setUpdateOrder(updateOrder: number): this; setUpdateOrder(updateOrder: number): this;
@@ -334,17 +336,17 @@ declare class Camera extends Component {
setZoom(zoom: number): this; setZoom(zoom: number): this;
setPosition(position: Vector2): this; setPosition(position: Vector2): this;
forceMatrixUpdate(): void; forceMatrixUpdate(): void;
updateMatrixes(): void; protected updateMatrixes(): void;
screenToWorldPoint(screenPosition: Vector2): Vector2; screenToWorldPoint(screenPosition: Vector2): Vector2;
worldToScreenPoint(worldPosition: Vector2): Vector2; worldToScreenPoint(worldPosition: Vector2): Vector2;
onEntityTransformChanged(comp: ComponentTransform): void; onEntityTransformChanged(comp: ComponentTransform): void;
destory(): void; destory(): void;
} }
declare class CameraInset { declare class CameraInset {
left: any; left: number;
right: any; right: number;
top: any; top: number;
bottom: any; bottom: number;
} }
declare class FollowCamera extends Component { declare class FollowCamera extends Component {
camera: Camera; camera: Camera;
@@ -400,26 +402,30 @@ declare abstract class RenderableComponent extends Component implements IRendera
readonly bounds: Rectangle; readonly bounds: Rectangle;
protected getWidth(): number; protected getWidth(): number;
protected getHeight(): number; protected getHeight(): number;
protected getBounds(): Rectangle;
protected onBecameVisible(): void; protected onBecameVisible(): void;
protected onBecameInvisible(): void; protected onBecameInvisible(): void;
abstract render(camera: Camera): any; abstract render(camera: Camera): any;
isVisibleFromCamera(camera: Camera): boolean; isVisibleFromCamera(camera: Camera): boolean;
onEntityTransformChanged(comp: ComponentTransform): void; onEntityTransformChanged(comp: ComponentTransform): void;
} }
declare enum SpriteEffects { declare class Sprite {
none = 0, texture2D: egret.Texture;
flipHorizontally = 1, readonly sourceRect: Rectangle;
flipVertically = 2 readonly center: Vector2;
origin: Vector2;
readonly uvs: Rectangle;
constructor(texture: egret.Texture, sourceRect?: Rectangle, origin?: Vector2);
} }
declare class SpriteRenderer extends RenderableComponent { declare class SpriteRenderer extends RenderableComponent {
private _sprite; private _sprite;
private _origin; private _origin;
protected getBounds(): Rectangle; private _bitmap;
sprite: egret.DisplayObject; readonly bounds: Rectangle;
setSprite(sprite: egret.DisplayObject): SpriteRenderer; sprite: Sprite;
setSprite(sprite: Sprite): SpriteRenderer;
origin: Vector2; origin: Vector2;
setOrigin(origin: Vector2): this; setOrigin(origin: Vector2): this;
isVisibleFromCamera(camera: Camera): boolean;
render(camera: Camera): void; render(camera: Camera): void;
} }
interface ITriggerListener { interface ITriggerListener {
@@ -677,6 +683,7 @@ declare class Rectangle {
intersects(value: Rectangle): boolean; intersects(value: Rectangle): boolean;
contains(value: Vector2): boolean; contains(value: Vector2): boolean;
containsRect(value: Rectangle): boolean; containsRect(value: Rectangle): boolean;
getHalfSize(): Vector2;
static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle; static fromMinMax(minX: number, minY: number, maxX: number, maxY: number): Rectangle;
getClosestPointOnRectangleBorderToPoint(point: Point): { getClosestPointOnRectangleBorderToPoint(point: Point): {
res: Vector2; res: Vector2;

View File

@@ -771,6 +771,15 @@ var Component = (function () {
} }
return this; return this;
}; };
Object.defineProperty(Component.prototype, "stage", {
get: function () {
if (!this.entity)
return null;
return this.entity.stage;
},
enumerable: true,
configurable: true
});
Component.prototype.initialize = function () { Component.prototype.initialize = function () {
}; };
Component.prototype.onAddedToEntity = function () { Component.prototype.onAddedToEntity = function () {
@@ -952,6 +961,15 @@ var Entity = (function () {
enumerable: true, enumerable: true,
configurable: true configurable: true
}); });
Object.defineProperty(Entity.prototype, "stage", {
get: function () {
if (!this.scene)
return null;
return this.scene.stage;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Entity.prototype, "updateOrder", { Object.defineProperty(Entity.prototype, "updateOrder", {
get: function () { get: function () {
return this._updateOrder; return this._updateOrder;
@@ -1217,9 +1235,9 @@ var ComponentTransform;
var Transform = (function () { var Transform = (function () {
function Transform(entity) { function Transform(entity) {
this._localRotation = 0; this._localRotation = 0;
this._worldTransform = new Matrix2D(); this._worldTransform = Matrix2D.identity;
this._worldToLocalTransform = new Matrix2D(); this._worldToLocalTransform = Matrix2D.identity;
this._worldInverseTransform = new Matrix2D(); this._worldInverseTransform = Matrix2D.identity;
this._rotation = 0; this._rotation = 0;
this.entity = entity; this.entity = entity;
this._scale = this._localScale = Vector2.one; this._scale = this._localScale = Vector2.one;
@@ -1317,12 +1335,15 @@ var Transform = (function () {
Object.defineProperty(Transform.prototype, "position", { Object.defineProperty(Transform.prototype, "position", {
get: function () { get: function () {
this.updateTransform(); this.updateTransform();
if (!this.parent) { if (this._positionDirty) {
this._position = this._localPosition; if (!this.parent) {
} this._position = this._localPosition;
else { }
this.parent.updateTransform(); else {
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); this.parent.updateTransform();
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
}
this._positionDirty = false;
} }
return this._position; return this._position;
}, },
@@ -1441,6 +1462,7 @@ var Transform = (function () {
else { else {
this.localPosition = position; this.localPosition = position;
} }
this._positionDirty = false;
return this; return this;
}; };
Transform.prototype.setDirty = function (dirtyFlagType) { Transform.prototype.setDirty = function (dirtyFlagType) {
@@ -1530,9 +1552,9 @@ var Camera = (function (_super) {
if (this._areMatrixesDirty) if (this._areMatrixesDirty)
this.updateMatrixes(); this.updateMatrixes();
if (this._areBoundsDirty) { if (this._areBoundsDirty) {
var stage = this.entity.scene.stage; var stage = this.stage;
var topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); var topLeft = this.screenToWorldPoint(new Vector2(stage.x + this._inset.left, stage.y + this._inset.top));
var bottomRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, stage.stageHeight - this._inset.bottom)); var bottomRight = this.screenToWorldPoint(new Vector2(stage.x + stage.stageWidth - this._inset.right, stage.y + stage.stageHeight - this._inset.bottom));
if (this.entity.transform.rotation != 0) { if (this.entity.transform.rotation != 0) {
var topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top)); var topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top));
var bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, stage.stageHeight - this._inset.bottom)); var bottomLeft = this.screenToWorldPoint(new Vector2(this._inset.left, stage.stageHeight - this._inset.bottom));
@@ -1706,6 +1728,10 @@ var Camera = (function (_super) {
}(Component)); }(Component));
var CameraInset = (function () { var CameraInset = (function () {
function CameraInset() { function CameraInset() {
this.left = 0;
this.right = 0;
this.top = 0;
this.bottom = 0;
} }
return CameraInset; return CameraInset;
}()); }());
@@ -1903,7 +1929,11 @@ var RenderableComponent = (function (_super) {
}); });
Object.defineProperty(RenderableComponent.prototype, "bounds", { Object.defineProperty(RenderableComponent.prototype, "bounds", {
get: function () { get: function () {
return this.getBounds(); if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
}, },
enumerable: true, enumerable: true,
configurable: true configurable: true
@@ -1914,43 +1944,53 @@ var RenderableComponent = (function (_super) {
RenderableComponent.prototype.getHeight = function () { RenderableComponent.prototype.getHeight = function () {
return this.bounds.height; return this.bounds.height;
}; };
RenderableComponent.prototype.getBounds = function () {
if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0), this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
};
RenderableComponent.prototype.onBecameVisible = function () { }; RenderableComponent.prototype.onBecameVisible = function () { };
RenderableComponent.prototype.onBecameInvisible = function () { }; RenderableComponent.prototype.onBecameInvisible = function () { };
RenderableComponent.prototype.isVisibleFromCamera = function (camera) { RenderableComponent.prototype.isVisibleFromCamera = function (camera) {
return true; this.isVisible = camera.bounds.intersects(this.bounds);
return this.isVisible;
}; };
RenderableComponent.prototype.onEntityTransformChanged = function (comp) { RenderableComponent.prototype.onEntityTransformChanged = function (comp) {
this._areBoundsDirty = true; this._areBoundsDirty = true;
}; };
return RenderableComponent; return RenderableComponent;
}(Component)); }(Component));
var SpriteEffects; var Sprite = (function () {
(function (SpriteEffects) { function Sprite(texture, sourceRect, origin) {
SpriteEffects[SpriteEffects["none"] = 0] = "none"; if (sourceRect === void 0) { sourceRect = new Rectangle(texture.textureWidth, texture.textureHeight); }
SpriteEffects[SpriteEffects["flipHorizontally"] = 1] = "flipHorizontally"; if (origin === void 0) { origin = sourceRect.getHalfSize(); }
SpriteEffects[SpriteEffects["flipVertically"] = 2] = "flipVertically"; this.uvs = new Rectangle();
})(SpriteEffects || (SpriteEffects = {})); this.texture2D = texture;
this.sourceRect = sourceRect;
this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5);
this.origin = origin;
var inverseTexW = 1 / texture.textureWidth;
var inverseTexH = 1 / texture.textureHeight;
this.uvs.x = sourceRect.x * inverseTexW;
this.uvs.y = sourceRect.y * inverseTexH;
this.uvs.width = sourceRect.width * inverseTexW;
this.uvs.height = sourceRect.height * inverseTexH;
}
return Sprite;
}());
var SpriteRenderer = (function (_super) { var SpriteRenderer = (function (_super) {
__extends(SpriteRenderer, _super); __extends(SpriteRenderer, _super);
function SpriteRenderer() { function SpriteRenderer() {
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
SpriteRenderer.prototype.getBounds = function () { Object.defineProperty(SpriteRenderer.prototype, "bounds", {
if (this._areBoundsDirty) { get: function () {
if (this._sprite) { if (this._areBoundsDirty) {
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.width, this._sprite.height); if (this._sprite) {
this._areBoundsDirty = false; this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.texture2D.textureWidth, this._sprite.texture2D.textureHeight);
this._areBoundsDirty = false;
}
} }
return this.bounds; return this._bounds;
} },
}; enumerable: true,
configurable: true
});
Object.defineProperty(SpriteRenderer.prototype, "sprite", { Object.defineProperty(SpriteRenderer.prototype, "sprite", {
get: function () { get: function () {
return this._sprite; return this._sprite;
@@ -1964,7 +2004,9 @@ var SpriteRenderer = (function (_super) {
SpriteRenderer.prototype.setSprite = function (sprite) { SpriteRenderer.prototype.setSprite = function (sprite) {
this._sprite = sprite; this._sprite = sprite;
if (this._sprite) if (this._sprite)
this._origin = new Vector2(this._sprite.anchorOffsetX, this._sprite.anchorOffsetY); this._origin = sprite.origin;
this._bitmap = new egret.Bitmap(sprite.texture2D);
this.stage.addChild(this._bitmap);
return this; return this;
}; };
Object.defineProperty(SpriteRenderer.prototype, "origin", { Object.defineProperty(SpriteRenderer.prototype, "origin", {
@@ -1984,16 +2026,21 @@ var SpriteRenderer = (function (_super) {
} }
return this; return this;
}; };
SpriteRenderer.prototype.isVisibleFromCamera = function (camera) {
this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds);
this._bitmap.visible = this.isVisible;
return this.isVisible;
};
SpriteRenderer.prototype.render = function (camera) { SpriteRenderer.prototype.render = function (camera) {
if (!this.sprite) if (!this.sprite)
return; return;
this.sprite.x = this.entity.transform.position.x - camera.transform.position.x; this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x;
this.sprite.y = this.entity.transform.position.y - camera.transform.position.y; this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y;
this.sprite.rotation = this.entity.transform.rotation; this._bitmap.rotation = this.entity.transform.rotation;
this.sprite.anchorOffsetX = this._origin.x; this._bitmap.anchorOffsetX = this._origin.x;
this.sprite.anchorOffsetY = this._origin.y; this._bitmap.anchorOffsetY = this._origin.y;
this.sprite.scaleX = this.entity.transform.scale.x; this._bitmap.scaleX = this.entity.transform.scale.x;
this.sprite.scaleY = this.entity.transform.scale.y; this._bitmap.scaleY = this.entity.transform.scale.y;
}; };
return SpriteRenderer; return SpriteRenderer;
}(RenderableComponent)); }(RenderableComponent));
@@ -3162,6 +3209,9 @@ var Rectangle = (function () {
(this.y <= value.y)) && (this.y <= value.y)) &&
(value.y < (this.y + this.height))); (value.y < (this.y + this.height)));
}; };
Rectangle.prototype.getHalfSize = function () {
return new Vector2(this.width * 0.5, this.height * 0.5);
};
Rectangle.fromMinMax = function (minX, minY, maxX, maxY) { Rectangle.fromMinMax = function (minX, minY, maxX, maxY) {
return new Rectangle(minX, minY, maxX - minX, maxY - minY); return new Rectangle(minX, minY, maxX - minX, maxY - minY);
}; };
@@ -3230,10 +3280,10 @@ var Rectangle = (function () {
var topRight = new Vector2(worldPosX + width, worldPosY); var topRight = new Vector2(worldPosX + width, worldPosY);
var bottomLeft = new Vector2(worldPosX, worldPosY + height); var bottomLeft = new Vector2(worldPosX, worldPosY + height);
var bottomRight = new Vector2(worldPosX + width, worldPosY + height); var bottomRight = new Vector2(worldPosX + width, worldPosY + height);
topLeft = Vector2.transform(topLeft, this._transformMat); topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
topRight = Vector2.transform(topRight, this._transformMat); topRight = Vector2Ext.transformR(topRight, this._transformMat);
bottomLeft = Vector2.transform(bottomLeft, this._transformMat); bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
bottomRight = Vector2.transform(bottomRight, this._transformMat); bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); var maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y); var minY = Math.min(topLeft.y, bottomRight.y, topRight.y, bottomLeft.y);

File diff suppressed because one or more lines are too long

View File

@@ -29,6 +29,13 @@ abstract class Component {
return this; return this;
} }
public get stage(){
if (!this.entity)
return null;
return this.entity.stage;
}
public initialize(){ public initialize(){
} }

View File

@@ -19,9 +19,9 @@ class Camera extends Component {
this.updateMatrixes(); this.updateMatrixes();
if (this._areBoundsDirty){ if (this._areBoundsDirty){
let stage = this.entity.scene.stage; let stage = this.stage;
let topLeft = this.screenToWorldPoint(new Vector2(this._inset.left, this._inset.top)); let topLeft = this.screenToWorldPoint(new Vector2(stage.x + this._inset.left, stage.y + this._inset.top));
let bottomRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, stage.stageHeight - this._inset.bottom)); let bottomRight = this.screenToWorldPoint(new Vector2(stage.x + stage.stageWidth - this._inset.right, stage.y + stage.stageHeight - this._inset.bottom));
if (this.entity.transform.rotation != 0){ if (this.entity.transform.rotation != 0){
let topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top)); let topRight = this.screenToWorldPoint(new Vector2(stage.stageWidth - this._inset.right, this._inset.top));
@@ -163,7 +163,7 @@ class Camera extends Component {
this._areMatrixesDirty = true; this._areMatrixesDirty = true;
} }
public updateMatrixes(){ protected updateMatrixes(){
if (!this._areMatrixesDirty) if (!this._areMatrixesDirty)
return; return;
@@ -208,8 +208,8 @@ class Camera extends Component {
} }
class CameraInset { class CameraInset {
public left; public left = 0;
public right; public right = 0;
public top; public top = 0;
public bottom; public bottom = 0;
} }

View File

@@ -29,7 +29,13 @@ abstract class RenderableComponent extends Component implements IRenderable {
} }
public get bounds(): Rectangle{ public get bounds(): Rectangle{
return this.getBounds(); if (this._areBoundsDirty){
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0),
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
} }
protected getWidth(){ protected getWidth(){
@@ -40,16 +46,6 @@ abstract class RenderableComponent extends Component implements IRenderable {
return this.bounds.height; return this.bounds.height;
} }
protected getBounds(){
if (this._areBoundsDirty){
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, new Vector2(0, 0),
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
this._areBoundsDirty = false;
}
return this._bounds;
}
protected onBecameVisible(){} protected onBecameVisible(){}
protected onBecameInvisible(){} protected onBecameInvisible(){}
@@ -57,10 +53,8 @@ abstract class RenderableComponent extends Component implements IRenderable {
public abstract render(camera: Camera); public abstract render(camera: Camera);
public isVisibleFromCamera(camera: Camera): boolean{ public isVisibleFromCamera(camera: Camera): boolean{
// this.isVisible = camera.bounds.intersects(this.bounds); this.isVisible = camera.bounds.intersects(this.bounds);
// return this.isVisible; return this.isVisible;
return true;
} }
public onEntityTransformChanged(comp: ComponentTransform){ public onEntityTransformChanged(comp: ComponentTransform){

View File

@@ -0,0 +1,24 @@
class Sprite {
public texture2D: egret.Texture;
public readonly sourceRect: Rectangle;
public readonly center: Vector2;
public origin: Vector2;
public readonly uvs: Rectangle = new Rectangle();
constructor(texture: egret.Texture,
sourceRect: Rectangle = new Rectangle(texture.textureWidth, texture.textureHeight),
origin: Vector2 = sourceRect.getHalfSize()){
this.texture2D = texture;
this.sourceRect = sourceRect;
this.center = new Vector2(sourceRect.width * 0.5, sourceRect.height * 0.5);
this.origin = origin;
let inverseTexW = 1 / texture.textureWidth;
let inverseTexH = 1 / texture.textureHeight
this.uvs.x = sourceRect.x * inverseTexW;
this.uvs.y = sourceRect.y * inverseTexH;
this.uvs.width = sourceRect.width * inverseTexW;
this.uvs.height = sourceRect.height * inverseTexH;
}
}

View File

@@ -1,5 +0,0 @@
enum SpriteEffects {
none = 0,
flipHorizontally = 1,
flipVertically = 2
}

View File

@@ -1,32 +1,36 @@
class SpriteRenderer extends RenderableComponent { class SpriteRenderer extends RenderableComponent {
private _sprite: egret.DisplayObject; private _sprite: Sprite;
private _origin: Vector2; private _origin: Vector2;
private _bitmap: egret.Bitmap;
protected getBounds(){ public get bounds(){
if (this._areBoundsDirty){ if (this._areBoundsDirty){
if (this._sprite){ if (this._sprite){
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin, this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, this._origin,
this.entity.transform.scale, this.entity.transform.rotation, this._sprite.width, this.entity.transform.scale, this.entity.transform.rotation, this._sprite.texture2D.textureWidth,
this._sprite.height); this._sprite.texture2D.textureHeight);
this._areBoundsDirty = false; this._areBoundsDirty = false;
} }
return this.bounds;
} }
return this._bounds;
} }
public get sprite(){ public get sprite(){
return this._sprite; return this._sprite;
} }
public set sprite(value: egret.DisplayObject){ public set sprite(value: Sprite){
this.setSprite(value); this.setSprite(value);
} }
public setSprite(sprite: egret.DisplayObject): SpriteRenderer{ public setSprite(sprite: Sprite): SpriteRenderer{
this._sprite = sprite; this._sprite = sprite;
if (this._sprite) if (this._sprite)
this._origin = new Vector2(this._sprite.anchorOffsetX, this._sprite.anchorOffsetY); this._origin = sprite.origin;
this._bitmap = new egret.Bitmap(sprite.texture2D);
this.stage.addChild(this._bitmap);
return this; return this;
} }
@@ -45,16 +49,22 @@ class SpriteRenderer extends RenderableComponent {
return this; return this;
} }
public render(camera: Camera) { public isVisibleFromCamera(camera: Camera): boolean{
this.isVisible = new Rectangle(0, 0, this.stage.stageWidth, this.stage.stageHeight).intersects(this.bounds);
this._bitmap.visible = this.isVisible;
return this.isVisible;
}
public render(camera: Camera){
if (!this.sprite) if (!this.sprite)
return; return;
this.sprite.x = this.entity.transform.position.x - camera.transform.position.x; this._bitmap.x = this.entity.transform.position.x - camera.transform.position.x + camera.origin.x;
this.sprite.y = this.entity.transform.position.y - camera.transform.position.y; this._bitmap.y = this.entity.transform.position.y - camera.transform.position.y + camera.origin.y;
this.sprite.rotation = this.entity.transform.rotation; this._bitmap.rotation = this.entity.transform.rotation;
this.sprite.anchorOffsetX = this._origin.x; this._bitmap.anchorOffsetX = this._origin.x;
this.sprite.anchorOffsetY = this._origin.y; this._bitmap.anchorOffsetY = this._origin.y;
this.sprite.scaleX = this.entity.transform.scale.x; this._bitmap.scaleX = this.entity.transform.scale.x;
this.sprite.scaleY = this.entity.transform.scale.y; this._bitmap.scaleY = this.entity.transform.scale.y;
} }
} }

View File

@@ -128,6 +128,13 @@ class Entity {
this.setTag(value); this.setTag(value);
} }
public get stage(){
if (!this.scene)
return null;
return this.scene.stage;
}
constructor(name: string){ constructor(name: string){
this.name = name; this.name = name;
this.transform = new Transform(this); this.transform = new Transform(this);

View File

@@ -25,9 +25,9 @@ class Transform {
private _rotationMatrix: Matrix2D; private _rotationMatrix: Matrix2D;
private _scaleMatrix: Matrix2D; private _scaleMatrix: Matrix2D;
private _worldTransform = new Matrix2D(); private _worldTransform = Matrix2D.identity;
private _worldToLocalTransform = new Matrix2D(); private _worldToLocalTransform = Matrix2D.identity;
private _worldInverseTransform = new Matrix2D(); private _worldInverseTransform = Matrix2D.identity;
private _rotation: number = 0; private _rotation: number = 0;
private _position: Vector2; private _position: Vector2;
@@ -130,13 +130,18 @@ class Transform {
public get position(){ public get position(){
this.updateTransform(); this.updateTransform();
if (!this.parent){ if (this._positionDirty){
this._position = this._localPosition; if (!this.parent){
}else{ this._position = this._localPosition;
this.parent.updateTransform(); }else{
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform); this.parent.updateTransform();
this._position = Vector2Ext.transformR(this._localPosition, this.parent._worldTransform);
}
this._positionDirty = false;
} }
return this._position; return this._position;
} }
@@ -255,6 +260,8 @@ class Transform {
this.localPosition = position; this.localPosition = position;
} }
this._positionDirty = false;
return this; return this;
} }
@@ -303,13 +310,11 @@ class Transform {
this._localRotationDirty = false; this._localRotationDirty = false;
} }
if (this._localScaleDirty){ if (this._localScaleDirty){
this._scaleMatrix = Matrix2D.createScale(this._localScale.x, this._localScale.y); this._scaleMatrix = Matrix2D.createScale(this._localScale.x, this._localScale.y);
this._localScaleDirty = false; this._localScaleDirty = false;
} }
this._localTransform = Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix); this._localTransform = Matrix2D.multiply(this._scaleMatrix, this._rotationMatrix);
this._localTransform = Matrix2D.multiply(this._localTransform, this._translationMatrix); this._localTransform = Matrix2D.multiply(this._localTransform, this._translationMatrix);

View File

@@ -71,6 +71,10 @@ class Rectangle {
(value.y < (this.y + this.height))); (value.y < (this.y + this.height)));
} }
public getHalfSize(){
return new Vector2(this.width * 0.5, this.height * 0.5);
}
public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) { public static fromMinMax(minX: number, minY: number, maxX: number, maxY: number) {
return new Rectangle(minX, minY, maxX - minX, maxY - minY); return new Rectangle(minX, minY, maxX - minX, maxY - minY);
} }
@@ -144,10 +148,10 @@ class Rectangle {
let bottomLeft = new Vector2(worldPosX, worldPosY + height); let bottomLeft = new Vector2(worldPosX, worldPosY + height);
let bottomRight = new Vector2(worldPosX + width, worldPosY + height); let bottomRight = new Vector2(worldPosX + width, worldPosY + height);
topLeft = Vector2.transform(topLeft, this._transformMat); topLeft = Vector2Ext.transformR(topLeft, this._transformMat);
topRight = Vector2.transform(topRight, this._transformMat); topRight = Vector2Ext.transformR(topRight, this._transformMat);
bottomLeft = Vector2.transform(bottomLeft, this._transformMat); bottomLeft = Vector2Ext.transformR(bottomLeft, this._transformMat);
bottomRight = Vector2.transform(bottomRight, this._transformMat); bottomRight = Vector2Ext.transformR(bottomRight, this._transformMat);
let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); let minX = Math.min(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);
let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x); let maxX = Math.max(topLeft.x, bottomRight.x, topRight.x, bottomLeft.x);