微信小游戏的putImageData有毛病,请官方修复
//js代码全部在game.js let systemInfo = wx.getSystemInfoSync(); console.log( "系统信息:" ,systemInfo); GameGlobal.isDevTool = systemInfo.platform === "devtools" ; // let canvas = wx.createCanvas(); let context = canvas.getContext( '2d' ); let image = wx.createImage(); let imgName = 'logo.jpg' ; image.src = 'images/' + imgName; let w = 150; let imgData = {}; image.onload = function () { context.drawImage(image, 0, 0); // //取canvas的部分数据 imgData = context.getImageData( 100,100, w,w); //写字 context.font = "20px Georgia" ; context.fillStyle = "black" ; context.fillText( "哇" , 120 , 120 ); //复原 //context.putImageData(imgData, 100,100);//去掉注释,单独执行,有效,但是与原来的样子出入明显 }; //移动棋子实现 wx.onTouchStart( function (e) { console.log( '触摸开始' ,e); //复原 //context.putImageData(imgData, 100,100);//去掉注释,单独执行,无效 }); wx.onTouchEnd( function (e) { console.log( '触摸结束' ,e.touches); //复原 context.putImageData(imgData, 100,100); //无效 }); |
来自手机的截图:
来自手机的截图:
中间明显有个方块,这哪里是复原?看看开发工具是怎么复原的: