From 8d7ca27bb48b818a0bd4bb854b4d85656b90a480 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Fri, 4 Oct 2024 01:07:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=B2=E6=9F=93=E6=A0=B9=E5=85=83?= =?UTF-8?q?=E7=B4=A0=E5=8F=96=E6=B6=88=E7=94=BB=E5=B8=83=E7=9A=84alpha?= =?UTF-8?q?=E9=80=9A=E9=81=93=EF=BC=8C=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/fx/canvas2d.ts | 12 ++++++++---- src/core/render/render.ts | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/fx/canvas2d.ts b/src/core/fx/canvas2d.ts index 3ec7d60..355d030 100644 --- a/src/core/fx/canvas2d.ts +++ b/src/core/fx/canvas2d.ts @@ -29,11 +29,11 @@ export class MotaOffscreenCanvas2D extends EventEmitter { /** 更新标识符,如果发生变化则说明画布被动清空 */ symbol: number = 0; - constructor() { + constructor(alpha: boolean = true) { super(); this.canvas = document.createElement('canvas'); - this.ctx = this.canvas.getContext('2d')!; + this.ctx = this.canvas.getContext('2d', { alpha })!; this.width = this.canvas.width / devicePixelRatio; this.height = this.canvas.height / devicePixelRatio; @@ -203,14 +203,18 @@ export class MotaCanvas2D extends MotaOffscreenCanvas2D { /** 是否是高清画布 */ highResolution: boolean = true; - constructor(id: string = '', setTarget: boolean = true) { + constructor( + id: string = '', + setTarget: boolean = true, + alpha: boolean = true + ) { super(); this.id = id; if (setTarget) this.target = core.dom.gameDraw; this.canvas = document.createElement('canvas'); this.canvas.id = id; - this.ctx = this.canvas.getContext('2d')!; + this.ctx = this.canvas.getContext('2d', { alpha })!; this.width = this.canvas.width / devicePixelRatio; this.height = this.canvas.height / devicePixelRatio; diff --git a/src/core/render/render.ts b/src/core/render/render.ts index b6afca2..a1ab524 100644 --- a/src/core/render/render.ts +++ b/src/core/render/render.ts @@ -13,7 +13,7 @@ export class MotaRenderer extends Container { constructor(id: string = 'render-main') { super('static', false); - this.target = new MotaCanvas2D(id); + this.target = new MotaCanvas2D(id, true, false); this.size(core._PX_, core._PY_); this.target.withGameScale(true); this.target.size(core._PX_, core._PY_);