From c9c745c730122bb18133d92dc36cb7df899ba16d Mon Sep 17 00:00:00 2001 From: yhh <359807859@qq.com> Date: Wed, 30 Sep 2020 18:31:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EprototypespriteRenderer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sprites/PrototypeSpriteRenderer.ts | 61 +++++++++++++++++++ source/src/ECS/Core.ts | 1 + source/src/Graphics/Graphics.ts | 20 ++++++ source/src/Utils/Vector2Ext.ts | 4 ++ 4 files changed, 86 insertions(+) create mode 100644 source/src/ECS/Components/Renderables/Sprites/PrototypeSpriteRenderer.ts create mode 100644 source/src/Graphics/Graphics.ts diff --git a/source/src/ECS/Components/Renderables/Sprites/PrototypeSpriteRenderer.ts b/source/src/ECS/Components/Renderables/Sprites/PrototypeSpriteRenderer.ts new file mode 100644 index 00000000..40a19894 --- /dev/null +++ b/source/src/ECS/Components/Renderables/Sprites/PrototypeSpriteRenderer.ts @@ -0,0 +1,61 @@ +module es { + export class PrototypeSpriteRenderer extends SpriteRenderer { + public get width(): number { + return this._width; + } + + public get height(): number { + return this._height; + } + + public get bounds(): Rectangle { + if (this._areBoundsDirty){ + 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; + } + + public skewTopX: number = 0; + public skewBottomX: number = 0; + public skewLeftY: number = 0; + public skewRightY: number = 0; + + public _width: number = 0; + public _height: number = 0; + + constructor(width: number = 50, height: number = 50){ + super(Graphics.Instance.pixelTexture); + this._width = width; + this._height = height; + } + + public setWidth(width: number): PrototypeSpriteRenderer { + this._width = width; + return this; + } + + public setHeight(height: number): PrototypeSpriteRenderer { + this._height = height; + return this; + } + + public setSkew(skewTopX: number, skewBottomX: number, skewLeftY: number, skewRightY: number): PrototypeSpriteRenderer{ + this.skewTopX = skewTopX; + this.skewBottomX = skewBottomX; + this.skewLeftY = skewLeftY; + this.skewRightY = skewRightY; + return this; + } + + public onAddedToEntity() { + this.originNormalized = Vector2Ext.halfVector(); + } + + public render(camera: es.Camera) { + + } + } +} \ No newline at end of file diff --git a/source/src/ECS/Core.ts b/source/src/ECS/Core.ts index 6b25cbef..264cbc42 100644 --- a/source/src/ECS/Core.ts +++ b/source/src/ECS/Core.ts @@ -228,6 +228,7 @@ module es { } protected initialize() { + Graphics.Instance = new Graphics(); } protected async update() { diff --git a/source/src/Graphics/Graphics.ts b/source/src/Graphics/Graphics.ts new file mode 100644 index 00000000..e0466d21 --- /dev/null +++ b/source/src/Graphics/Graphics.ts @@ -0,0 +1,20 @@ +module es { + export class Graphics { + public static Instance: Graphics; + /** + * 用于绘制矩形、线条、圆等的精灵。 + * 将在启动时生成,但你可以用你的图集中的精灵代替,以减少纹理交换。应该是一个1x1的白色像素 + */ + public pixelTexture: Sprite; + + constructor(){ + let arrayBuffer = new ArrayBuffer(1); + arrayBuffer[0] = 0xffffff; + egret.BitmapData.create("arraybuffer", arrayBuffer, bitmapData => { + let tex = new egret.Texture(); + tex.bitmapData = bitmapData; + this.pixelTexture = new Sprite(tex); + }); + } + } +} \ No newline at end of file diff --git a/source/src/Utils/Vector2Ext.ts b/source/src/Utils/Vector2Ext.ts index 110c68d3..90ca0a67 100644 --- a/source/src/Utils/Vector2Ext.ts +++ b/source/src/Utils/Vector2Ext.ts @@ -10,6 +10,10 @@ module es { return this.cross(Vector2.subtract(center, a), Vector2.subtract(c, center)) < 0; } + public static halfVector(): Vector2 { + return new Vector2(0.5, 0.5); + } + /** * 计算二维伪叉乘点(Perp(u), v) * @param u