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_);