即 id="GameCanvas" 的 <canvas> 元素好像禁止了 touchstart、touchmove、touchend 事件的冒泡,导致该 canvas 的父级元素(例如 <div="GameDiv" />、<body> 等)都无法监听这些方法。
有什么办法可以让 Cocos 不要禁止这些事件冒泡么?
即 id="GameCanvas" 的 <canvas> 元素好像禁止了 touchstart、touchmove、touchend 事件的冒泡,导致该 canvas 的父级元素(例如 <div="GameDiv" />、<body> 等)都无法监听这些方法。
有什么办法可以让 Cocos 不要禁止这些事件冒泡么?
if (sys.isMobile) {
input.on(Input.EventType.TOUCH_START, this.TouchDown, this);
input.on(Input.EventType.TOUCH_MOVE, this.TouchMove, this);
input.on(Input.EventType.TOUCH_CANCEL, this.TouchUp, this);
input.on(Input.EventType.TOUCH_END, this.TouchUp, this);
} else {
input.on(Input.EventType.MOUSE_MOVE, this.MouseMove, this);
input.on(Input.EventType.MOUSE_DOWN, this.MouseDown, this);
input.on(Input.EventType.MOUSE_UP, this.MouseUp, this);
input.on(Input.EventType.MOUSE_WHEEL, this.MouseWheel, this);
}
但我并不想在Cocos里再去定义事件,那样性能并不好。
补充下:我的项目是 H5 混合式的页面,最外层是常规的 H5,里面集成了一个 Cocos 构建后的画布和脚本。
那可能要构建web-desktop版本
我们是 H5 项目,只构建 web-mobile
感觉没办法,只能顶层再对 cocos canvas 多加一个事件监听了。
构建web-desktop,然后修改index.html。web-mobile是全屏的。