canvas2d requestAnimationFrame放一会突然加速,然后停了,再次正常?
发布于 7 年前 作者 oxiong 2957 次浏览 来自 官方Issues
// requestAnimationFrame放一会突然加速,然后停了,再次正常?还有就是cancelAnimationFrame 不生效???
// 代码如下
var doubleCount = 0;
const fishBufferLoop = () => {
  if((doubleCount++)%2==0){
    doubleCount = 0;
    goAnimate();
  }
  that.data.bufferCanvas.requestAnimationFrame(fishBufferLoop)
}
that.data.bufferCanvas.requestAnimationFrame(fishBufferLoop)

//
function goAnimate() {
  that.data.bufferContext.clearRect(0, 0, screenWidthOrg, canvasHeight);
  for (var i = 0; i < swimFishList.length; i++) {
      var currentFishObj = swimFishList[i];
      var fishName = currentFishObj.fishName;
      var fWidth = fishName.width * ratio;
      var fHeight = fishName.height * ratio;
      var fTop = currentFishObj.postop;
      var fLeft = currentFishObj.posleft;
      that.data.bufferContext.save()
      that.data.bufferContext.drawImage(
          fishName,
          fLeft,
          fTop,
          fWidth,
          fHeight,
      )
      that.data.bufferContext.restore()
  }
}

1 回复

你好,麻烦具体描述问题流程,提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部