点击按钮后出现小延迟

Small lag after tapping the button

本文关键字:延迟 按钮      更新时间:2023-09-26

这是我的游戏-我的游戏

问题:

当我在谷歌Chrome开发者工具中检查游戏并点击(点击)画布(或按钮)时,会出现小的滞后,然后汽车向左或向右行驶。我该如何解决这个问题?

(我想为移动设备制作游戏)

我试过了:

    <meta name="viewport" content="width=device-width, user-scalable=no">

我正在使用touchstart事件。但还是什么都没有。。。

编辑:

好的,我试过FastClick,但它不起作用。

<script type="application/javascript" src="js/fastclick.js"></script>
<script type="application/javascript">
window.addEventListener('load', function() {
  FastClick.attach(document.body);
  document.getElementById("goleft").addEventListener('touchstart', function(){
      superCar.speedX = -40;
  }, true)
  document.getElementById("goleft").addEventListener('touchend', function(){
      superCar.speedX = 0;
  }, true)
  document.getElementById("goright").addEventListener('touchstart', function(){
      superCar.speedX = 40;
  }, true)
  document.getElementById("goright").addEventListener('touchend', function(){
      superCar.speedX = 0;
  }, true)
}, true)
</script>

触摸事件现在在<head>

我想您知道300ms的触摸延迟,这就是添加width=device-width的原因。然而,这只适用于现代版本的操作系统/浏览器。因此,例如,如果你使用的是旧的安卓系统,它不会有任何影响。(见此图表。)

该页面继续建议使用FastClick或tap.js作为polyfill,所以请尝试其中一种,看看这是否有帮助。