MCPcopy Create free account
hub / github.com/melonjs/melonJS / enablePointerEvent

Function enablePointerEvent

packages/melonjs/src/input/pointerevent.ts:139–231  ·  view source on GitHub ↗

* enable pointer event (Pointer/Mouse/Touch) * @ignore

()

Source from the content-addressed store, hash-verified

137 * @ignore
138 */
139function enablePointerEvent(): void {
140 if (!pointerInitialized) {
141 if (!_app) {
142 throw new Error("Pointer events require an initialized Application");
143 }
144 // the current pointer area
145 currentPointer = new Rect(0, 0, 1, 1);
146
147 // instantiate a pool of pointer catched
148 for (let v = 0; v < device.maxTouchPoints; v++) {
149 T_POINTERS.push(new Pointer());
150 }
151
152 if (pointerEventTarget === null || pointerEventTarget === undefined) {
153 // default pointer event target
154 pointerEventTarget = _app.renderer.getCanvas();
155 }
156
157 if (device.pointerEvent) {
158 // standard Pointer Events
159 activeEventList = pointerEventList;
160 } else {
161 // Regular Mouse events
162 activeEventList = mouseEventList;
163 }
164 if (device.touch && !device.pointerEvent) {
165 // touch event on mobile devices
166 activeEventList = activeEventList.concat(touchEventList);
167 }
168 registerEventListener(activeEventList, onPointerEvent);
169
170 // set the PointerMove/touchMove/MouseMove event
171 if (typeof throttlingInterval === "undefined") {
172 // set the default value
173 throttlingInterval = ~~(1000 / timer.maxfps);
174 }
175
176 if (device.autoFocus) {
177 device.focus();
178 pointerEventTarget.addEventListener(
179 activeEventList[2], // MOUSE/POINTER DOWN
180 () => {
181 device.focus();
182 },
183 { passive: !preventDefault },
184 );
185 }
186
187 // if time interval <= 16, disable the feature
188 const events = findAllActiveEvents(activeEventList, POINTER_MOVE);
189 if (throttlingInterval < 17) {
190 for (let i = 0; i < events.length; i++) {
191 if (activeEventList.indexOf(events[i]) !== -1) {
192 pointerEventTarget.addEventListener(
193 events[i],
194 onMoveEvent,
195 { passive: true }, // do not preventDefault on Move events
196 );

Callers 2

bindPointerFunction · 0.85
registerPointerEventFunction · 0.85

Calls 8

throttleFunction · 0.90
emitFunction · 0.90
registerEventListenerFunction · 0.85
findAllActiveEventsFunction · 0.85
setTouchActionFunction · 0.85
getCanvasMethod · 0.80
getParentElementMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected