首页 > 解决方案 > 在移动浏览器中滑动表格

问题描述

我和我的队友正在用 dart 为移动浏览器编写游戏“Battlecity”。问题在于在移动浏览器中滑动坦克方向(从左到右,从右到左等)。它具有很大的延迟(并且由于某种原因在 Chrome 浏览器中不起作用)。如果您在移动设备上启动游戏,您可以更好地看到问题(只需打开游戏链接:https ://javajunikorn.github.io/BattleCity/build/web/html/test.html )有趣的是,问题仅存在于游戏场上的滑动(在我们的例子中是 27*27 html 表)。如果我们退出游戏感觉,那效果会很好。

这是我们控制器的代码:

class Direction{


  Point first, last;
  Game game;

  void startListening(){


    window.onTouchStart.listen((ev) {
      last = null;
      first = ev.touches.first.client;
    });

    window.onTouchMove.listen((ev){
      last = ev.touches.first.client;
    });

    window.onTouchEnd.listen((ev) {
      if(last == null || first.distanceTo(last) < 20)
        game.player.shoot();
      else {
        Point d = first - last;
        if(d.x.abs() > d.y.abs()){
          //Waagerecht
          if( first.x > last.x){
            //links
            game.player.changeDirection(Directions.left);
          }
          else{
            //rechts
            game.player.changeDirection(Directions.right);
          }
        }
        else{
          //Senkrecht
          if(first.y > last.y){
            //Up
            game.player.changeDirection(Directions.up);
          }
          else{
            //Down
            game.player.changeDirection(Directions.down);

          }
        }
      }
    });


    window.onKeyPress.listen((k) {
      //Shoot
      if(k.which == 32) { //spacebar
        game.player.shoot();
      }
      //Up
      if(k.which == 119 || k.keyCode == KeyCode.UP){
        game.player.changeDirection(Directions.up);
      }
      //Down
      if(k.which == 115 || k.keyCode == KeyCode.DOWN){
        game.player.changeDirection(Directions.down);
      }
      //Left
      if(k.which == 97 || k.keyCode == KeyCode.LEFT){
        game.player.changeDirection(Directions.left);
      }
      //Right
      if(k.which == 100 || k.keyCode == KeyCode.RIGHT){
        game.player.changeDirection(Directions.right);
      }
    });

  }

}

标签: mobilebrowserdart

解决方案


推荐阅读