【求助】onTouchMove的回调函数的延迟问题
79 浏览2024年09月22日作者:Cray-z

在onTouchMove的回调函数中,把一个对象在屏幕中的位置设置为


const pos = {x: e.touches[0].clientX, y:e.touches[0].clientY};

IDE中和真机运行时都明显出现位置更新的延迟。


请问是什么原因?有解决方案吗?


下面是一个简化的代码:

console.log('使用抖音开发者工具开发过程中可以参考以下文档:');
console.log(
  'https://developer.open-douyin.com/docs/resource/zh-CN/mini-game/guide/minigame/introduction',
);

let systemInfo = tt.getSystemInfoSync();
let canvas = tt.createCanvas(),
  ctx = canvas.getContext('2d');
canvas.width = systemInfo.windowWidth;
canvas.height = systemInfo.windowHeight;

let touchX = 0,
  touchY = 0;

tt.onTouchMove(function (e) {
  touchX = e.touches[0].clientX;
  touchY = e.touches[0].clientY;
});

function frame() {
  draw();
  requestAnimationFrame(frame);
}

function draw() {
  ctx.fillstyle='#ffffff';
  ctx.fillRect(0, 0, systemInfo.windowWidth, systemInfo.windowHeight);

  ctx.fillstyle='#000000';
  ctx.font = `${parseInt(systemInfo.windowWidth / 20)}px Arial`;
  ctx.fillText('欢迎使用抖音开发者工具', 80, 200);
  
  
  ctx.fillRect(touchX, touchY, 10, 10);
}

frame();
最后一次编辑于 2024 年 09 月 22 日
0 条评论

相关问答

专题推荐

热门文章

热门问答