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

Function dispatchEvent

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

* propagate events to registered objects * @ignore

(normalizedEvents: Pointer[])

Source from the content-addressed store, hash-verified

294 * @ignore
295 */
296function dispatchEvent(normalizedEvents: Pointer[]): boolean {
297 let handled = false;
298
299 while (normalizedEvents.length > 0) {
300 // keep a reference to the last item
301 const pointer = normalizedEvents.pop()!;
302 // and put it back into our cache
303 T_POINTERS.push(pointer);
304
305 // Do not fire older touch events (not required for PointerEvent type)
306 if (
307 pointer.isNormalized &&
308 typeof pointer.event!.timeStamp !== "undefined"
309 ) {
310 if (pointer.event!.timeStamp < lastTimeStamp) {
311 continue;
312 }
313 lastTimeStamp = pointer.event!.timeStamp;
314 }
315
316 currentPointer.pos.set(pointer.gameWorldX, pointer.gameWorldY);
317 currentPointer.setSize(pointer.width, pointer.height);
318
319 // trigger a global event for pointer move
320 if (POINTER_MOVE.includes(pointer.type)) {
321 pointer.gameX = pointer.gameLocalX = pointer.gameScreenX;
322 pointer.gameY = pointer.gameLocalY = pointer.gameScreenY;
323 emit(POINTERMOVE, pointer);
324 }
325
326 // fetch valid candiates from the game world container
327 let candidates = _app.world.broadphase.retrieve(
328 currentPointer,
329 (a: any, b: any) => _app.world._sortReverseZ(a, b),
330 undefined,
331 );
332
333 // add the main game viewport to the list of candidates
334 candidates = candidates.concat([_app.viewport]);
335
336 for (
337 let c = candidates.length, candidate;
338 c--, (candidate = candidates[c]);
339 ) {
340 if (eventHandlers.has(candidate) && candidate.isKinematic !== true) {
341 const handlers = eventHandlers.get(candidate)!;
342 const region = handlers.region;
343 const ancestor = region.ancestor;
344 const bounds = region.getBounds();
345
346 if (region.isFloating === true) {
347 pointer.gameX = pointer.gameLocalX = pointer.gameScreenX;
348 pointer.gameY = pointer.gameLocalY = pointer.gameScreenY;
349 } else {
350 pointer.gameX = pointer.gameLocalX = pointer.gameWorldX;
351 pointer.gameY = pointer.gameLocalY = pointer.gameWorldY;
352 }
353

Callers 2

onMoveEventFunction · 0.85
onPointerEventFunction · 0.85

Calls 12

emitFunction · 0.90
triggerEventFunction · 0.85
findActiveEventFunction · 0.85
_sortReverseZMethod · 0.80
retrieveMethod · 0.65
getMethod · 0.65
getBoundsMethod · 0.65
pushMethod · 0.45
setMethod · 0.45
setSizeMethod · 0.45
hasMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected