phinajs / phina.js

phina.js is game library

Home Page:http://phinajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

指を離すと同時にタップをするとtouchStart判定が二重になってしまう

pentamania opened this issue · comments

タッチパネル端末で、指を離すと同時にタップを行うとタッチ開始判定が二重になってしまうバグがありました。

// Sceneクラス
update: (app) {
  app.pointers.forEach(function(p) {
    if (p.getPointingStart()) {
      // ここの処理が2フレームに渡って実行され、結果二重判定になる
    }
  });
},

調べてみるとTouchList.updateで、離れたtouchに対してspliceで配列操作をしてしまっているため、ループがうまく回らずtouchstartした方のtouchオブジェクトが更新されないのが原因のようです。

phina.js/src/input/touch.js

Lines 153 to 174 in 4cc8851

removeTouch: function(touch) {
var i = this.touches.indexOf(touch);
this.touches.splice(i, 1);
},
update: function() {
this.touches.forEach(function(touch) {
if (!touch.released) {
touch.update();
if (touch.flags === 0) {
touch.released = true;
}
}
else {
touch.released = false;
this.removeTouch(touch);
}
}, this);
},

色々解決法はあると思いますが、とりあえずforEachではなく、ネガティブforループにすることで解決できましたのでご参考までに。

    update: function() {
      if (this.touches.length > 0) {
        for (var i = this.touches.length - 1; i >= 0; i--) {
          var touch = this.touches[i];
          if (!touch.released) {
            touch.update();

            if (touch.flags === 0) {
              touch.released = true;
            }
          }
          else {
            touch.released = false;
            this.removeTouch(touch);
          }
        }
      }
    },

(自分でPRを出すかもしれませんが、一応issueとして上げときます。)