做一个记录 版本:CocosCreator2.4.6
功能:鼠标拖拽,绘制对应路径
问题:字节小游戏平台,路径点过多后会出现帧率暴降
原思路:touch事件中记录鼠标移动的点,graphics moveto至第0点的坐标,之后每次touch回调执行lineto方法连接路径,使用stroke绘制路径
let len=this.touchPointList.length;
let point=this.touchPointList[len-1];
this.drawGraphics.lineTo(point.x,point.y);
this.drawGraphics.stroke();
解决办法:在每次lineto执行前,调用moveto移动到线段的开始点,再进行连线和绘制。
let len=this.touchPointList.length;
let point=this.touchPointList[len-1];
let sPoint=this.touchPointList[len-2];
this.drawGraphics.moveTo(sPoint.x,sPoint.y)
this.drawGraphics.lineTo(point.x,point.y);
this.drawGraphics.stroke();
结果对比:原先8秒左右帧率降为8,改后连续画线1分钟也未发现帧率降低