MS指针事件监听器未触发

问题描述 投票:0回答:1

我目前正在尝试学习Javascript并进行以下教程(http://www.sitepoint.com/creating-a-simple-windows-8-game-with-javascript-input-and-sound/),但是遇到了无法逾越的问题。

我创建了一个canvas元素,在画布上附加了三个侦听器以使用鼠标单击:

canvas.addEventListener("MSPointerUp", endAim, false);
canvas.addEventListener("MSPointerMove", adjustAim, false);
canvas.addEventListener("MSPointerDown", beginAim, false);

但是我的函数永远不会在PointerUp或Down或Move上调用。下面是有问题的功能,还请注意,我已经完成了“ console.log”的调试工作。这些功能甚至都没有记录到控制台,这就是为什么我认为未触发事件的原因。 >

function beginAim(event){
   console.log("Aim ahoy");
   if (playerTurn == 1) {
      if (!isAiming) {
         aimStart = new createjs.Point(event.x, event.y);
         isAiming = true;
      }
   }
}

function adjustAim(event){
   console.log("adjustAim event called");
   if (isAiming) {
      var aimCurrent = new createjs.Point(event.x, event.y);
      aimVector = calculateAim(aimStart, aimCurrent);
      //ToDo: write text / show aim arror
      console.log("Aiming... " + aimVector.x + "/" + aimVector.y);
   }
}

function endAim(event){
   if (isAiming) {
      console.log("endAim Function called");
      isAiming = false;
      var aimCurrent = new createjs.Point(event.x, event.y);
      aimVector = calculateAim(aimStart, aimCurrent);
      playerFire = true;
   }
}

function calculateAim(start, end){
   var aim = new createjs.Point(
      (end.x - start.x) / 80,
      (end.y - start.y) / 80);
   aim.x = Math.min(MAX_SHOT_POWER, aim.x);
   aim.x = Math.max(0, aim.x);
   aim.y = Math.max(-MAX_SHOT_POWER, aim.y);
   aim.y = Math.min(0, aim.y);
   return aim;
}

我知道这将是一个简单的问题。MSPointerUp / Down / Move全部用于Windows8,这就是它们从未触发的原因。

我最终切换到mousedown,mouseup和mousemove来获得相同的结果。

我目前正在尝试学习Javascript并进行以下教程(http://www.sitepoint.com/creating-a-simple-windows-8-game-with-javascript-input-and-sound/),但是我遇到了问题...

javascript html dom-events javascript-framework
1个回答
1
投票

添加到正文或画布以将触摸事件路由到JavaScript:

© www.soinside.com 2019 - 2024. All rights reserved.