我们是使用原始JS来制作的游戏。 原本是在微信那边编写。 但是移植过来后遇到了canvas绘制方面导致内存暴涨的问题
我们主要的绘制方式是下面几种。
没排查出来是什么原因导致的。游戏基本运行几分钟,特别是在有动画的对象场景。内存涨得非常快,最快可以达到每秒涨1-2mb。游戏很快就会卡顿死。以及还发现了游戏中文字大小会闪烁不定的情况。
在空场景下,或者画面中只有一两个对象绘制的时候,不会涨或者几乎看不出来有变化。
请问是字节跳动平台在内存释放机制上面与微信方便有些不同,还是其他什么原因。 官方能否帮忙解决一下这个问题,非常严重。IOS和安卓均有这个问题。
第一种:
DataBus.Instance().ctx.save();
DataBus.Instance().ctx.globalAlpha = this.alpha;
DataBus.Instance().images[this.imageSrc],
this.dx,
this.dy,
this.dw,
this.dh,//取样坐标不能缩放
this.x,
this.y,
this.width,
this.height,
)
DataBus.Instance().ctx.restore();
第二种:
ctx.save();
ctx.translate(this.GetCenterX(), this.GetCenterY() );
ctx.rotate(this.rotate);//弧度制
ctx.translate(-this.GetCenterX(), -this.GetCenterY());
ctx.globalAlpha = this.alpha;
ctx.drawImage(
DataBus.Instance().images[this.imageSrc],
this.x,
this.y,
this.sprWidth * this.xScale,
this.sprHeight * this.yScale
)
ctx.restore();
第三种:
DataBus.Instance().ctx.save();
DataBus.Instance().ctx.font = 'normal bold ' + Math.round(this.textShowSize * DataBus.Instance().rate) + 'px 微软雅黑';
DataBus.Instance().ctx.fillStyle = this.textShowColor;
DataBus.Instance().ctx.fillText(this.textShow, this.textShowX, this.textShowY);
DataBus.Instance().ctx.restore();