2
touchmoveイベントに問題があります。ユーザーがディスプレイに触れると(タッチスタート)、touchmove
イベントハンドラとgame()
が実行され、ユーザーが画面を離れる場合はすべてを停止する必要があります。しかし、間隔のif条件は、e.pageX
とe.pageY
が常にタッチスタートの座標を持ち、ユーザーが画面上で指を動かすとその値が更新されないため正しく動作しません。これをどうすれば解決できますか? demoタッチスタートハンドラの処理後のtouchmoveハンドラ
$("body").on({
'touchstart mousedown': function (e) {
$(this).on('touchmove mousemove');
collisiondetection = setInterval(function() {
var xp1 = $("#n1").position();
if (e.pageY >= xp1.top && e.pageY <= xp1.top + cy * 10 && e.pageX >= xp1.left && e.pageX <= xp1.left + cx * 25) {
console.log("hit");
}
var xp2 = $("#n2").position();
if (e.pageY >= xp2.top && e.pageY <= xp2.top + cy * 10 && e.pageX >= xp2.left && e.pageX <= xp2.left + cx * 25) {
console.log("hit");
}
},10);
game();
},
'touchend mouseup': function (e) {
$(this).off('touchmove mousemove');
clearInterval(animaterects);
clearInterval(collisiondetection);
}
});
UPDATE:私は'touchstart mousedown touchmove mousemove': function (e) {
にそれを編集した場合、衝突検出と更新がうまく機能を調整するが、アニメーションはいけません。