安卓运行小游戏很卡是什么情况?
发布于 6 年前 作者 fliao 1863 次浏览 来自 问答

微信小游戏:

draw(x,y)是绘制移动,我现在需求是一直移动一块canvas

但是在苹果手机上就很流畅,到了安卓手机上就很卡了,这是什么情况?安卓是要做什么兼容吗?

import PictureManager from "../player/PictureManager";

import Base from "../base/Base";  

export default class ScreenView extends Base {   

  constructor(x = 0, y = 0, width = GameGlobal.WIDTH, height = GameGlobal.HEIGHT) {       

  super()       

  this.showPicNum = 1       

  this.oringX = x         

 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)  

   } 

}



1 回复

可能和机型有关系,我做了几个小程序下来,小米表现就是要差些,你可以用别的机型试一试

回到顶部