Touch.enable 无法通过 Animate CC 在 CreateJS 中工作

Touch.enable not working in CreateJS through Animate CC

我在 Animate CC 中创建了一个 html5 canvas 文件,但在触摸屏设备上 运行 时,我似乎无法让它响应触摸。我创建了一个精简文件来演示这个问题。

我在网上找到的所有其他 post 都已通过 createjs.Touch.enable(stage) 解决,但是,这并不能为我启用触摸(它 returns 错误)。我还添加了一个 touchstart 事件侦听器,但这也无济于事。

我也试过this没有效果。

为了在控制台中调试,我在设备仿真模式下使用 chrome。在 Animate CC 中,centre stagemake responsive 都在发布设置中关闭。

下面示例代码的结果:

知道我哪里出错了吗? Animate CC 完全是最新的,createJS 是 v1.0.0

预期的行为是触摸开始时触发 touchstart 或 mousedown 处理程序,就像使用鼠标时一样。

console.log("Enable touch: "+createjs.Touch.enable(stage) );  // returns false

ball = this.ball_mc;

// mouse mouse event
ball.on("mousedown", function(event) {
    console.log("mouse down");
    ball.x += 10;
});

// finger down event
ball.addEventListener("touchstart", function mouseDownHandler(e) {
    console.log("finger down");
    ball.x += 10;
});

这是更新和回答。 我上面的代码是正确的,看到的问题实际上不是问题。

虽然我在触摸设备上进行了初步测试,但此后我并没有假设 Chrome dev tools 触摸设备模拟器是准确的。原来不是! Chrome 开发工具不会在触摸时发送鼠标按下事件,因此无法准确模拟触摸设备。

上面的代码因此工作正常,但需要 运行 直接在触摸设备上。