feat: 渲染根元素取消画布的alpha通道,提高性能

This commit is contained in:
unanmed 2024-10-04 01:07:45 +08:00
parent fc8e666c3a
commit 8d7ca27bb4
2 changed files with 9 additions and 5 deletions

View File

@ -29,11 +29,11 @@ export class MotaOffscreenCanvas2D extends EventEmitter<OffscreenCanvasEvent> {
/** 更新标识符,如果发生变化则说明画布被动清空 */
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;

View File

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