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

Method setEvent

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

* initialize the Pointer object using the given Event Object * @param event - the original Event object * @param pageX - the horizontal coordinate at which the event occurred, relative to the left edge of the entire document * @param pageY - the vertical coordinate at which the event occurred,

(
		event: Event,
		pageX: number = 0,
		pageY: number = 0,
		clientX: number = 0,
		clientY: number = 0,
		pointerId: number = 1,
	)

Source from the content-addressed store, hash-verified

229 * @param pointerId - the Pointer, Touch or Mouse event Id (1)
230 */
231 setEvent(
232 event: Event,
233 pageX: number = 0,
234 pageY: number = 0,
235 clientX: number = 0,
236 clientY: number = 0,
237 pointerId: number = 1,
238 ): void {
239 // the original event object
240 this.event = event as PointerEvent | TouchEvent | MouseEvent;
241
242 this.pageX = pageX;
243 this.pageY = pageY;
244 this.clientX = clientX;
245 this.clientY = clientY;
246
247 // translate to local coordinates
248 globalToLocal(this.pageX, this.pageY, tmpVec);
249 this.gameScreenX = this.x = tmpVec.x;
250 this.gameScreenY = this.y = tmpVec.y;
251
252 // true if not originally a pointer event
253 this.isNormalized =
254 typeof globalThis.PointerEvent !== "undefined" &&
255 !(event instanceof globalThis.PointerEvent);
256
257 this.locked = locked;
258 this.movementX = (event as any).movementX || 0;
259 this.movementY = (event as any).movementY || 0;
260
261 if (event.type === "wheel") {
262 this.deltaMode = (event as any).deltaMode || 0;
263 this.deltaX = (event as any).deltaX || 0;
264 this.deltaY = (event as any).deltaY || 0;
265 this.deltaZ = (event as any).deltaZ || 0;
266 } else {
267 this.deltaMode = 0;
268 this.deltaX = 0;
269 this.deltaY = 0;
270 this.deltaZ = 0;
271 }
272
273 this.pointerId = pointerId;
274
275 this.isPrimary =
276 typeof (event as any).isPrimary !== "undefined"
277 ? (event as any).isPrimary
278 : true;
279
280 // in case of touch events, button is not defined
281 this.button = (event as any).button || 0;
282
283 this.type = event.type;
284
285 // get the current screen to game world offset
286 if (typeof _app?.viewport !== "undefined") {
287 _app.viewport.localToWorld(this.gameScreenX, this.gameScreenY, tmpVec);
288 }

Callers 1

normalizeEventFunction · 0.80

Calls 2

globalToLocalFunction · 0.90
localToWorldMethod · 0.80

Tested by

no test coverage detected