cocos-enhance-kit/adapters/common/engine/InputManager.js
2024-10-16 17:12:08 +08:00

42 lines
1.2 KiB
JavaScript

const mgr = cc.internal.inputManager;
const canvasPosition = {
left: 0,
top: 0,
width: window.innerWidth,
height: window.innerHeight
};
if (mgr) {
Object.assign(mgr, {
_updateCanvasBoundingRect () {},
registerSystemEvent (element) {
if(this._isRegisterEvent) return;
this._glView = cc.view;
let self = this;
//register touch event
let _touchEventsMap = {
onTouchStart: this.handleTouchesBegin,
onTouchMove: this.handleTouchesMove,
onTouchEnd: this.handleTouchesEnd,
onTouchCancel: this.handleTouchesCancel,
};
let registerTouchEvent = function (eventName) {
let handler = _touchEventsMap[eventName];
__globalAdapter[eventName](function (event) {
if (!event.changedTouches) return;
handler.call(self, self.getTouchesByEvent(event, canvasPosition));
});
};
for (let eventName in _touchEventsMap) {
registerTouchEvent(eventName);
}
this._isRegisterEvent = true;
},
});
}