mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 14:55:24 +00:00
[adapters] 增加小游戏适配部分源码
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
export default class MouseEvent {
|
||||
constructor() {
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
import { noop } from '../util/index.js'
|
||||
|
||||
export default class TouchEvent {
|
||||
touches = []
|
||||
targetTouches = []
|
||||
changedTouches = []
|
||||
preventDefault = noop
|
||||
stopPropagation = noop
|
||||
|
||||
constructor(type) {
|
||||
this.type = type
|
||||
this.target = window.canvas
|
||||
this.currentTarget = window.canvas
|
||||
}
|
||||
}
|
||||
|
||||
function touchEventHandlerFactory(type) {
|
||||
return (event) => {
|
||||
const touchEvent = new TouchEvent(type)
|
||||
|
||||
touchEvent.touches = event.touches
|
||||
touchEvent.targetTouches = Array.prototype.slice.call(event.touches)
|
||||
touchEvent.changedTouches = event.changedTouches
|
||||
touchEvent.timeStamp = event.timeStamp
|
||||
document.dispatchEvent(touchEvent)
|
||||
}
|
||||
}
|
||||
|
||||
tt.onTouchStart(touchEventHandlerFactory('touchstart'))
|
||||
tt.onTouchMove(touchEventHandlerFactory('touchmove'))
|
||||
tt.onTouchEnd(touchEventHandlerFactory('touchend'))
|
||||
tt.onTouchCancel(touchEventHandlerFactory('touchcancel'))
|
@@ -0,0 +1,2 @@
|
||||
export TouchEvent from './TouchEvent'
|
||||
export MouseEvent from './MouseEvent'
|
Reference in New Issue
Block a user