0

这是我的游戏 -我的游戏

问题:

当我在 Google 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>

4

1 回答 1

0

我假设您知道 300 毫秒的触摸延迟,这就是您添加width=device-width. 但是,这只适用于现代版本的操作系统/浏览器。因此,例如,如果您使用的是旧 Android,它不会有任何影响。(见这张图表。)

该页面继续建议使用FastClicktap.js作为 polyfill,因此请尝试其中一个,看看是否有帮助。

于 2016-05-03T13:39:07.983 回答