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

Method initEvents

packages/melonjs/src/renderable/draggable.js:42–72  ·  view source on GitHub ↗

* Initializes the events the modules needs to listen to * It translates the pointer events to me.events * in order to make them pass through the system and to make * this module testable. Then we subscribe this module to the * transformed events. * @private

()

Source from the content-addressed store, hash-verified

40 * @private
41 */
42 initEvents() {
43 input.registerPointerEvent("pointerdown", this, (e) => {
44 emit(DRAGSTART, e, this);
45 });
46 input.registerPointerEvent("pointerup", this, (e) => {
47 emit(DRAGEND, e, this);
48 });
49 input.registerPointerEvent("pointercancel", this, (e) => {
50 emit(DRAGEND, e, this);
51 });
52
53 this.handlePointerMove = (e) => {
54 this.dragMove(e);
55 };
56
57 this.handleDragStart = (e, draggable) => {
58 if (draggable === this) {
59 this.dragStart(e);
60 }
61 };
62
63 this.handleDragEnd = (e, draggable) => {
64 if (draggable === this) {
65 this.dragEnd(e);
66 }
67 };
68
69 on(POINTERMOVE, this.handlePointerMove);
70 on(DRAGSTART, this.handleDragStart);
71 on(DRAGEND, this.handleDragEnd);
72 }
73
74 /**
75 * Gets called when the user starts dragging the entity

Callers 1

constructorMethod · 0.95

Calls 5

dragMoveMethod · 0.95
dragStartMethod · 0.95
dragEndMethod · 0.95
emitFunction · 0.90
onFunction · 0.90

Tested by

no test coverage detected