微信小游戏:
draw(x,y)是绘制移动,我现在需求是一直移动一块canvas
但是在苹果手机上就很流畅,到了安卓手机上就很卡了,这是什么情况?安卓是要做什么兼容吗?
this.oringY = y this.width = width this.autoWidth = GameGlobal.WIDTH - this.autoX(2 * this.oringX) this.height = this.autoWidth + this.autoY(50) this.pictures = GameGlobal.showUserList //获取照片数 //一直createCanvas会在安卓上导致崩溃 this.screenCanvas = wx.createCanvas() this.screenCanvas.width = GameGlobal.WIDTH this.screenCanvas.height = GameGlobal.HEIGHT this.pageCtx = this.screenCanvas.getContext('2d') GameGlobal.currentCanvas = this.screenCanvas GameGlobal.currentCtx = this.pageCtx //先预加载首张照片,不然会导致图片读取不及时显示空白 let curUser = this.pictures[0] this.getImgBase64(curUser.photo, (dataURL) => { this.draw(x, y) }) } draw(x, y) { this.pageCtx.clearRect(0, 0, GameGlobal.WIDTH, GameGlobal.HEIGHT); //当超出屏幕后重置原点、更新数据 if (x > GameGlobal.W || x + this.width < 0) { //当前照片 let curUser = this.pictures[0] let likeCode = x > GameGlobal.W ? 1 : 0 //左右滑喜好请求接口 GameGlobal.netTool.likeRequest(curUser.id, likeCode, () => {}) x = this.oringX y = this.oringY this.pictures.shift()
//当照片数只剩指定展示数时,请求接口获取后续展示照片 if (this.pictures.length == this.showPicNum) { GameGlobal.netTool.getShowUserInfoRequest((userRes) => { this.pictures = this.pictures.concat(GameGlobal.showUserList) console.log('追加后的数组数' + this.pictures.length) }) } } for (let i = this.showPicNum - 1; i >= 0; i--) { let setX = i == 0 ? x : this.oringX + 5 * i let setY = i == 0 ? y : this.oringY + 5 * i let space = i == 0 ? 0 : this.autoX(2 * 5 * i) this.picManager = new PictureManager(this.pictures[i], this.autoX(setX), this.autoY(setY), this.autoWidth - space, this.autoWidth) } GameGlobal.dataStore.ctx.drawImage(this.screenCanvas, 0, 0) } } |