melonjs 10.2.0 → 10.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
package/src/input/pointer.js
CHANGED
|
@@ -3,6 +3,7 @@ import device from "./../system/device.js";
|
|
|
3
3
|
import Bounds from "./../physics/bounds.js";
|
|
4
4
|
import { viewport } from "./../game.js";
|
|
5
5
|
import { globalToLocal } from "./input.js";
|
|
6
|
+
import { locked } from "./pointerevent.js";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -14,10 +15,9 @@ var tmpVec = new Vector2d();
|
|
|
14
15
|
/**
|
|
15
16
|
* @classdesc
|
|
16
17
|
* a pointer object, representing a single finger on a touch enabled device.
|
|
17
|
-
* @class
|
|
18
|
-
* @
|
|
19
|
-
* @
|
|
20
|
-
* @constructor
|
|
18
|
+
* @class Pointer
|
|
19
|
+
* @augments me.Bounds
|
|
20
|
+
* @memberof me
|
|
21
21
|
*/
|
|
22
22
|
class Pointer extends Bounds {
|
|
23
23
|
|
|
@@ -35,27 +35,27 @@ class Pointer extends Bounds {
|
|
|
35
35
|
/**
|
|
36
36
|
* constant for left button
|
|
37
37
|
* @public
|
|
38
|
-
* @type {
|
|
38
|
+
* @type {number}
|
|
39
39
|
* @name LEFT
|
|
40
|
-
* @
|
|
40
|
+
* @memberof me.Pointer
|
|
41
41
|
*/
|
|
42
42
|
this.LEFT = 0;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* constant for middle button
|
|
46
46
|
* @public
|
|
47
|
-
* @type {
|
|
47
|
+
* @type {number}
|
|
48
48
|
* @name MIDDLE
|
|
49
|
-
* @
|
|
49
|
+
* @memberof me.Pointer
|
|
50
50
|
*/
|
|
51
51
|
this.MIDDLE = 1;
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* constant for right button
|
|
55
55
|
* @public
|
|
56
|
-
* @type {
|
|
56
|
+
* @type {number}
|
|
57
57
|
* @name RIGHT
|
|
58
|
-
* @
|
|
58
|
+
* @memberof me.Pointer
|
|
59
59
|
*/
|
|
60
60
|
this.RIGHT = 2;
|
|
61
61
|
|
|
@@ -67,17 +67,17 @@ class Pointer extends Bounds {
|
|
|
67
67
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent
|
|
68
68
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent
|
|
69
69
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
|
|
70
|
-
* @
|
|
70
|
+
* @memberof me.Pointer
|
|
71
71
|
*/
|
|
72
72
|
this.event = undefined;
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* a string containing the event's type.
|
|
76
76
|
* @public
|
|
77
|
-
* @type {
|
|
77
|
+
* @type {string}
|
|
78
78
|
* @name type
|
|
79
79
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Event/type
|
|
80
|
-
* @
|
|
80
|
+
* @memberof me.Pointer
|
|
81
81
|
*/
|
|
82
82
|
this.type = undefined;
|
|
83
83
|
|
|
@@ -85,100 +85,120 @@ class Pointer extends Bounds {
|
|
|
85
85
|
/**
|
|
86
86
|
* the button property indicates which button was pressed on the mouse to trigger the event.
|
|
87
87
|
* @public
|
|
88
|
-
* @type {
|
|
88
|
+
* @type {number}
|
|
89
89
|
* @name button
|
|
90
90
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
|
|
91
|
-
* @
|
|
91
|
+
* @memberof me.Pointer
|
|
92
92
|
*/
|
|
93
93
|
this.button = 0;
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* indicates whether or not the pointer device that created the event is the primary pointer.
|
|
97
97
|
* @public
|
|
98
|
-
* @type {
|
|
98
|
+
* @type {boolean}
|
|
99
99
|
* @name isPrimary
|
|
100
100
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/isPrimary
|
|
101
|
-
* @
|
|
101
|
+
* @memberof me.Pointer
|
|
102
102
|
*/
|
|
103
103
|
this.isPrimary = false;
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* the horizontal coordinate at which the event occurred, relative to the left edge of the entire document.
|
|
107
107
|
* @public
|
|
108
|
-
* @type {
|
|
108
|
+
* @type {number}
|
|
109
109
|
* @name pageX
|
|
110
110
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/pageX
|
|
111
|
-
* @
|
|
111
|
+
* @memberof me.Pointer
|
|
112
112
|
*/
|
|
113
113
|
this.pageX = 0;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* the vertical coordinate at which the event occurred, relative to the left edge of the entire document.
|
|
117
117
|
* @public
|
|
118
|
-
* @type {
|
|
118
|
+
* @type {number}
|
|
119
119
|
* @name pageY
|
|
120
120
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/pageY
|
|
121
|
-
* @
|
|
121
|
+
* @memberof me.Pointer
|
|
122
122
|
*/
|
|
123
123
|
this.pageY = 0;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* the horizontal coordinate within the application's client area at which the event occurred
|
|
127
127
|
* @public
|
|
128
|
-
* @type {
|
|
128
|
+
* @type {number}
|
|
129
129
|
* @name clientX
|
|
130
130
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX
|
|
131
|
-
* @
|
|
131
|
+
* @memberof me.Pointer
|
|
132
132
|
*/
|
|
133
133
|
this.clientX = 0;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* the vertical coordinate within the application's client area at which the event occurred
|
|
137
137
|
* @public
|
|
138
|
-
* @type {
|
|
138
|
+
* @type {number}
|
|
139
139
|
* @name clientY
|
|
140
140
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientY
|
|
141
|
-
* @
|
|
141
|
+
* @memberof me.Pointer
|
|
142
142
|
*/
|
|
143
143
|
this.clientY = 0;
|
|
144
144
|
|
|
145
|
+
/**
|
|
146
|
+
* the difference in the X coordinate of the pointer since the previous move event
|
|
147
|
+
* @public
|
|
148
|
+
* @type {number}
|
|
149
|
+
* @name movementX
|
|
150
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
|
|
151
|
+
* @memberof me.Pointer
|
|
152
|
+
*/
|
|
153
|
+
this.movementX = 0;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* the difference in the Y coordinate of the pointer since the previous move event
|
|
157
|
+
* @public
|
|
158
|
+
* @type {number}
|
|
159
|
+
* @name movementY
|
|
160
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementY
|
|
161
|
+
* @memberof me.Pointer
|
|
162
|
+
*/
|
|
163
|
+
this.movementY = 0;
|
|
164
|
+
|
|
145
165
|
/**
|
|
146
166
|
* an unsigned long representing the unit of the delta values scroll amount
|
|
147
167
|
* @public
|
|
148
|
-
* @type {
|
|
168
|
+
* @type {number}
|
|
149
169
|
* @name deltaMode
|
|
150
170
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaMode
|
|
151
|
-
* @
|
|
171
|
+
* @memberof me.Pointer
|
|
152
172
|
*/
|
|
153
173
|
this.deltaMode = 0;
|
|
154
174
|
|
|
155
175
|
/**
|
|
156
176
|
* a double representing the horizontal scroll amount in the Wheel Event deltaMode unit.
|
|
157
177
|
* @public
|
|
158
|
-
* @type {
|
|
178
|
+
* @type {number}
|
|
159
179
|
* @name deltaX
|
|
160
180
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaX
|
|
161
|
-
* @
|
|
181
|
+
* @memberof me.Pointer
|
|
162
182
|
*/
|
|
163
183
|
this.deltaX = 0;
|
|
164
184
|
|
|
165
185
|
/**
|
|
166
186
|
* a double representing the vertical scroll amount in the Wheel Event deltaMode unit.
|
|
167
187
|
* @public
|
|
168
|
-
* @type {
|
|
188
|
+
* @type {number}
|
|
169
189
|
* @name deltaY
|
|
170
190
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaY
|
|
171
|
-
* @
|
|
191
|
+
* @memberof me.Pointer
|
|
172
192
|
*/
|
|
173
193
|
this.deltaY = 0;
|
|
174
194
|
|
|
175
195
|
/**
|
|
176
196
|
* a double representing the scroll amount in the z-axis, in the Wheel Event deltaMode unit.
|
|
177
197
|
* @public
|
|
178
|
-
* @type {
|
|
198
|
+
* @type {number}
|
|
179
199
|
* @name deltaZ
|
|
180
200
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/deltaZ
|
|
181
|
-
* @
|
|
201
|
+
* @memberof me.Pointer
|
|
182
202
|
*/
|
|
183
203
|
this.deltaZ = 0;
|
|
184
204
|
|
|
@@ -186,9 +206,9 @@ class Pointer extends Bounds {
|
|
|
186
206
|
* Event normalized X coordinate within the game canvas itself<br>
|
|
187
207
|
* <img src="images/event_coord.png"/>
|
|
188
208
|
* @public
|
|
189
|
-
* @type {
|
|
209
|
+
* @type {number}
|
|
190
210
|
* @name gameX
|
|
191
|
-
* @
|
|
211
|
+
* @memberof me.Pointer
|
|
192
212
|
*/
|
|
193
213
|
this.gameX = 0;
|
|
194
214
|
|
|
@@ -196,75 +216,93 @@ class Pointer extends Bounds {
|
|
|
196
216
|
* Event normalized Y coordinate within the game canvas itself<br>
|
|
197
217
|
* <img src="images/event_coord.png"/>
|
|
198
218
|
* @public
|
|
199
|
-
* @type {
|
|
219
|
+
* @type {number}
|
|
200
220
|
* @name gameY
|
|
201
|
-
* @
|
|
221
|
+
* @memberof me.Pointer
|
|
202
222
|
*/
|
|
203
223
|
this.gameY = 0;
|
|
204
224
|
|
|
205
225
|
/**
|
|
206
226
|
* Event X coordinate relative to the viewport
|
|
207
227
|
* @public
|
|
208
|
-
* @type {
|
|
228
|
+
* @type {number}
|
|
209
229
|
* @name gameScreenX
|
|
210
|
-
* @
|
|
230
|
+
* @memberof me.Pointer
|
|
211
231
|
*/
|
|
212
232
|
this.gameScreenX = 0;
|
|
213
233
|
|
|
214
234
|
/**
|
|
215
235
|
* Event Y coordinate relative to the viewport
|
|
216
236
|
* @public
|
|
217
|
-
* @type {
|
|
237
|
+
* @type {number}
|
|
218
238
|
* @name gameScreenY
|
|
219
|
-
* @
|
|
239
|
+
* @memberof me.Pointer
|
|
220
240
|
*/
|
|
221
241
|
this.gameScreenY = 0;
|
|
222
242
|
|
|
223
243
|
/**
|
|
224
244
|
* Event X coordinate relative to the map
|
|
225
245
|
* @public
|
|
226
|
-
* @type {
|
|
246
|
+
* @type {number}
|
|
227
247
|
* @name gameWorldX
|
|
228
|
-
* @
|
|
248
|
+
* @memberof me.Pointer
|
|
229
249
|
*/
|
|
230
250
|
this.gameWorldX = 0;
|
|
231
251
|
|
|
232
252
|
/**
|
|
233
253
|
* Event Y coordinate relative to the map
|
|
234
254
|
* @public
|
|
235
|
-
* @type {
|
|
255
|
+
* @type {number}
|
|
236
256
|
* @name gameWorldY
|
|
237
|
-
* @
|
|
257
|
+
* @memberof me.Pointer
|
|
238
258
|
*/
|
|
239
259
|
this.gameWorldY = 0;
|
|
240
260
|
|
|
241
261
|
/**
|
|
242
262
|
* Event X coordinate relative to the holding container
|
|
243
263
|
* @public
|
|
244
|
-
* @type {
|
|
264
|
+
* @type {number}
|
|
245
265
|
* @name gameLocalX
|
|
246
|
-
* @
|
|
266
|
+
* @memberof me.Pointer
|
|
247
267
|
*/
|
|
248
268
|
this.gameLocalX = 0;
|
|
249
269
|
|
|
250
270
|
/**
|
|
251
271
|
* Event Y coordinate relative to the holding container
|
|
252
272
|
* @public
|
|
253
|
-
* @type {
|
|
273
|
+
* @type {number}
|
|
254
274
|
* @name gameLocalY
|
|
255
|
-
* @
|
|
275
|
+
* @memberof me.Pointer
|
|
256
276
|
*/
|
|
257
277
|
this.gameLocalY = 0;
|
|
258
278
|
|
|
259
279
|
/**
|
|
260
|
-
|
|
280
|
+
* The unique identifier of the contact for a touch, mouse or pen
|
|
281
|
+
* @public
|
|
282
|
+
* @type {number}
|
|
283
|
+
* @name pointerId
|
|
284
|
+
* @memberof me.Pointer
|
|
285
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId
|
|
286
|
+
*/
|
|
287
|
+
this.pointerId = undefined;
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* true if not originally a pointer event
|
|
261
291
|
* @public
|
|
262
|
-
* @type {
|
|
263
|
-
* @name
|
|
264
|
-
* @
|
|
265
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/pointerId
|
|
292
|
+
* @type {boolean}
|
|
293
|
+
* @name isNormalized
|
|
294
|
+
* @memberof me.Pointer
|
|
266
295
|
*/
|
|
267
|
-
this.
|
|
296
|
+
this.isNormalized = false;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* true if the pointer is currently locked
|
|
300
|
+
* @public
|
|
301
|
+
* @type {boolean}
|
|
302
|
+
* @name locked
|
|
303
|
+
* @memberof me.Pointer
|
|
304
|
+
*/
|
|
305
|
+
this.locked = false;
|
|
268
306
|
|
|
269
307
|
// bind list for mouse buttons
|
|
270
308
|
this.bind = [ 0, 0, 0 ];
|
|
@@ -276,11 +314,11 @@ class Pointer extends Bounds {
|
|
|
276
314
|
* @private
|
|
277
315
|
* @function
|
|
278
316
|
* @param {Event} event the original Event object
|
|
279
|
-
* @param {
|
|
280
|
-
* @param {
|
|
281
|
-
* @param {
|
|
282
|
-
* @param {
|
|
283
|
-
* @param {
|
|
317
|
+
* @param {number} [pageX=0] the horizontal coordinate at which the event occurred, relative to the left edge of the entire document
|
|
318
|
+
* @param {number} [pageY=0] the vertical coordinate at which the event occurred, relative to the left edge of the entire document
|
|
319
|
+
* @param {number} [clientX=0] the horizontal coordinate within the application's client area at which the event occurred
|
|
320
|
+
* @param {number} [clientY=0] the vertical coordinate within the application's client area at which the event occurred
|
|
321
|
+
* @param {number} [pointerId=1] the Pointer, Touch or Mouse event Id (1)
|
|
284
322
|
*/
|
|
285
323
|
setEvent(event, pageX = 0, pageY = 0, clientX = 0, clientY = 0, pointerId = 1) {
|
|
286
324
|
// the original event object
|
|
@@ -299,6 +337,10 @@ class Pointer extends Bounds {
|
|
|
299
337
|
// true if not originally a pointer event
|
|
300
338
|
this.isNormalized = !device.PointerEvent || (device.PointerEvent && !(event instanceof window.PointerEvent));
|
|
301
339
|
|
|
340
|
+
this.locked = locked;
|
|
341
|
+
this.movementX = event.movementX || 0;
|
|
342
|
+
this.movementY = event.movementY || 0;
|
|
343
|
+
|
|
302
344
|
if (event.type === "wheel") {
|
|
303
345
|
this.deltaMode = event.deltaMode || 0;
|
|
304
346
|
this.deltaX = event.deltaX || 0;
|
|
@@ -320,8 +362,6 @@ class Pointer extends Bounds {
|
|
|
320
362
|
|
|
321
363
|
this.type = event.type;
|
|
322
364
|
|
|
323
|
-
|
|
324
|
-
|
|
325
365
|
// get the current screen to game world offset
|
|
326
366
|
if (typeof viewport !== "undefined") {
|
|
327
367
|
viewport.localToWorld(this.gameScreenX, this.gameScreenY, tmpVec);
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import {preventDefault} from "./input.js";
|
|
2
2
|
import {getBindingKey, triggerKeyEvent} from "./keyboard.js";
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import * as arrayUtil from "./../utils/array.js";
|
|
3
|
+
import { renderer, scaleRatio, getParent } from "./../video/video.js";
|
|
4
|
+
import { throttle } from "./../utils/function.js";
|
|
5
|
+
import { remove } from "./../utils/array.js";
|
|
7
6
|
import * as event from "./../system/event.js";
|
|
8
7
|
import timer from "./../system/timer.js";
|
|
9
8
|
import pool from "./../system/pooling.js";
|
|
10
9
|
import device from "./../system/device.js";
|
|
11
10
|
import Pointer from "./pointer.js";
|
|
12
|
-
import Rect from "./../
|
|
11
|
+
import Rect from "./../geometries/rectangle.js";
|
|
13
12
|
import Container from "./../renderable/container.js";
|
|
14
|
-
import Renderable from "./../renderable/renderable.js";
|
|
15
13
|
import { world, viewport } from "./../game.js";
|
|
16
14
|
|
|
17
|
-
|
|
18
15
|
/**
|
|
19
16
|
* A pool of `Pointer` objects to cache pointer/touch event coordinates.
|
|
20
|
-
* @type {Array.<
|
|
17
|
+
* @type {Array.<me.Vector2d>}
|
|
21
18
|
* @ignore
|
|
22
19
|
*/
|
|
23
20
|
var T_POINTERS = [];
|
|
@@ -181,7 +178,7 @@ function enablePointerEvent() {
|
|
|
181
178
|
if (activeEventList.indexOf(events[i]) !== -1) {
|
|
182
179
|
pointerEventTarget.addEventListener(
|
|
183
180
|
events[i],
|
|
184
|
-
|
|
181
|
+
throttle(
|
|
185
182
|
onMoveEvent,
|
|
186
183
|
throttlingInterval,
|
|
187
184
|
false
|
|
@@ -194,6 +191,17 @@ function enablePointerEvent() {
|
|
|
194
191
|
// disable all gesture by default
|
|
195
192
|
setTouchAction(pointerEventTarget);
|
|
196
193
|
|
|
194
|
+
// set a on change listener on pointerlock if supported
|
|
195
|
+
if (device.hasPointerLockSupport) {
|
|
196
|
+
document.addEventListener("pointerlockchange", () => {
|
|
197
|
+
// change the locked status accordingly
|
|
198
|
+
locked = document.pointerLockElement === getParent();
|
|
199
|
+
// emit the corresponding internal event
|
|
200
|
+
event.emit(event.POINTERLOCKCHANGE, locked);
|
|
201
|
+
}, true);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// all done !
|
|
197
205
|
pointerInitialized = true;
|
|
198
206
|
}
|
|
199
207
|
}
|
|
@@ -292,7 +300,7 @@ function dispatchEvent(normalizedEvents) {
|
|
|
292
300
|
var bounds = region.getBounds();
|
|
293
301
|
var eventInBounds = false;
|
|
294
302
|
|
|
295
|
-
if (region.
|
|
303
|
+
if (region.isFloating === true) {
|
|
296
304
|
pointer.gameX = pointer.gameLocalX = pointer.gameScreenX;
|
|
297
305
|
pointer.gameY = pointer.gameLocalY = pointer.gameScreenY;
|
|
298
306
|
} else {
|
|
@@ -308,10 +316,11 @@ function dispatchEvent(normalizedEvents) {
|
|
|
308
316
|
pointer.gameLocalY = pointer.gameY - parentBounds.y;
|
|
309
317
|
}
|
|
310
318
|
|
|
319
|
+
var gameX = pointer.gameX;
|
|
320
|
+
var gameY = pointer.gameY;
|
|
321
|
+
|
|
311
322
|
// apply inverse transformation for renderable
|
|
312
|
-
if (region
|
|
313
|
-
var gameX = pointer.gameX;
|
|
314
|
-
var gameY = pointer.gameY;
|
|
323
|
+
if (typeof region.currentTransform !== "undefined") {
|
|
315
324
|
if (!region.currentTransform.isIdentity()) {
|
|
316
325
|
var invV = region.currentTransform.applyInverse(
|
|
317
326
|
pool.pull("Vector2d", gameX, gameY)
|
|
@@ -320,14 +329,8 @@ function dispatchEvent(normalizedEvents) {
|
|
|
320
329
|
gameY = invV.y;
|
|
321
330
|
pool.push(invV);
|
|
322
331
|
}
|
|
323
|
-
eventInBounds = bounds.contains(gameX, gameY);
|
|
324
|
-
} else {
|
|
325
|
-
eventInBounds =
|
|
326
|
-
bounds.contains(pointer.gameX, pointer.gameY) &&
|
|
327
|
-
(bounds === region ||
|
|
328
|
-
// if the given target is another shape than me.Rect
|
|
329
|
-
region.contains(pointer.gameLocalX, pointer.gameLocalY));
|
|
330
332
|
}
|
|
333
|
+
eventInBounds = bounds.contains(gameX, gameY);
|
|
331
334
|
|
|
332
335
|
switch (pointer.type) {
|
|
333
336
|
case POINTER_MOVE[0]:
|
|
@@ -498,9 +501,9 @@ function onPointerEvent(e) {
|
|
|
498
501
|
/**
|
|
499
502
|
* the default target element for pointer events (usually the canvas element in which the game is rendered)
|
|
500
503
|
* @public
|
|
501
|
-
* @type EventTarget
|
|
504
|
+
* @type {EventTarget}
|
|
502
505
|
* @name pointerEventTarget
|
|
503
|
-
* @
|
|
506
|
+
* @memberof me.input
|
|
504
507
|
*/
|
|
505
508
|
export var pointerEventTarget = null;
|
|
506
509
|
|
|
@@ -509,18 +512,28 @@ function onPointerEvent(e) {
|
|
|
509
512
|
* @public
|
|
510
513
|
* @type {me.Rect}
|
|
511
514
|
* @name pointer
|
|
512
|
-
* @
|
|
515
|
+
* @memberof me.input
|
|
513
516
|
*/
|
|
514
517
|
export var pointer = new Pointer(0, 0, 1, 1);
|
|
515
518
|
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* indicates if the pointer is currently locked
|
|
522
|
+
* @public
|
|
523
|
+
* @type {boolean}
|
|
524
|
+
* @name locked
|
|
525
|
+
* @memberof me.input
|
|
526
|
+
*/
|
|
527
|
+
export var locked = false;
|
|
528
|
+
|
|
516
529
|
/**
|
|
517
530
|
* time interval for event throttling in milliseconds<br>
|
|
518
531
|
* default value : "1000/me.timer.maxfps" ms<br>
|
|
519
532
|
* set to 0 ms to disable the feature
|
|
520
533
|
* @public
|
|
521
|
-
* @type
|
|
534
|
+
* @type {number}
|
|
522
535
|
* @name throttlingInterval
|
|
523
|
-
* @
|
|
536
|
+
* @memberof me.input
|
|
524
537
|
*/
|
|
525
538
|
export var throttlingInterval;
|
|
526
539
|
|
|
@@ -528,13 +541,13 @@ export var throttlingInterval;
|
|
|
528
541
|
* Translate the specified x and y values from the global (absolute)
|
|
529
542
|
* coordinate to local (viewport) relative coordinate.
|
|
530
543
|
* @name globalToLocal
|
|
531
|
-
* @
|
|
544
|
+
* @memberof me.input
|
|
532
545
|
* @public
|
|
533
546
|
* @function
|
|
534
|
-
* @param {
|
|
535
|
-
* @param {
|
|
547
|
+
* @param {number} x the global x coordinate to be translated.
|
|
548
|
+
* @param {number} y the global y coordinate to be translated.
|
|
536
549
|
* @param {me.Vector2d} [v] an optional vector object where to set the translated coordinates
|
|
537
|
-
* @
|
|
550
|
+
* @returns {me.Vector2d} A vector object with the corresponding translated coordinates
|
|
538
551
|
* @example
|
|
539
552
|
* onMouseEvent : function (pointer) {
|
|
540
553
|
* // convert the given into local (viewport) relative coordinates
|
|
@@ -543,7 +556,7 @@ export var throttlingInterval;
|
|
|
543
556
|
* };
|
|
544
557
|
*/
|
|
545
558
|
export function globalToLocal(x, y, v) {
|
|
546
|
-
v = v ||
|
|
559
|
+
v = v || pool.pull("Vector2d");
|
|
547
560
|
var rect = device.getElementBounds(renderer.getScreenCanvas());
|
|
548
561
|
var pixelRatio = device.devicePixelRatio;
|
|
549
562
|
x -= rect.left + (window.pageXOffset || 0);
|
|
@@ -560,12 +573,12 @@ export function globalToLocal(x, y, v) {
|
|
|
560
573
|
* enable/disable all gestures on the given element.<br>
|
|
561
574
|
* by default melonJS will disable browser handling of all panning and zooming gestures.
|
|
562
575
|
* @name setTouchAction
|
|
563
|
-
* @
|
|
576
|
+
* @memberof me.input
|
|
564
577
|
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action
|
|
565
578
|
* @public
|
|
566
579
|
* @function
|
|
567
580
|
* @param {HTMLCanvasElement} element
|
|
568
|
-
* @param {
|
|
581
|
+
* @param {string} [value="none"]
|
|
569
582
|
*/
|
|
570
583
|
export function setTouchAction(element, value) {
|
|
571
584
|
element.style["touch-action"] = value || "none";
|
|
@@ -577,10 +590,10 @@ export function setTouchAction(element, value) {
|
|
|
577
590
|
* Middle button – 1
|
|
578
591
|
* Right button – 2
|
|
579
592
|
* @name bindPointer
|
|
580
|
-
* @
|
|
593
|
+
* @memberof me.input
|
|
581
594
|
* @public
|
|
582
595
|
* @function
|
|
583
|
-
* @param {
|
|
596
|
+
* @param {number} [button=me.input.pointer.LEFT] (accordingly to W3C values : 0,1,2 for left, middle and right buttons)
|
|
584
597
|
* @param {me.input.KEY} keyCode
|
|
585
598
|
* @example
|
|
586
599
|
* // enable the keyboard
|
|
@@ -608,10 +621,10 @@ export function bindPointer() {
|
|
|
608
621
|
/**
|
|
609
622
|
* unbind the defined keycode
|
|
610
623
|
* @name unbindPointer
|
|
611
|
-
* @
|
|
624
|
+
* @memberof me.input
|
|
612
625
|
* @public
|
|
613
626
|
* @function
|
|
614
|
-
* @param {
|
|
627
|
+
* @param {number} [button=me.input.pointer.LEFT] (accordingly to W3C values : 0,1,2 for left, middle and right buttons)
|
|
615
628
|
* @example
|
|
616
629
|
* me.input.unbindPointer(me.input.pointer.LEFT);
|
|
617
630
|
*/
|
|
@@ -630,10 +643,10 @@ export function unbindPointer(button) {
|
|
|
630
643
|
* @see me.Pointer
|
|
631
644
|
* @see {@link http://www.w3.org/TR/pointerevents/#list-of-pointer-events|W3C Pointer Event list}
|
|
632
645
|
* @name registerPointerEvent
|
|
633
|
-
* @
|
|
646
|
+
* @memberof me.input
|
|
634
647
|
* @public
|
|
635
648
|
* @function
|
|
636
|
-
* @param {
|
|
649
|
+
* @param {string} eventType The event type for which the object is registering <br>
|
|
637
650
|
* melonJS currently supports: <br>
|
|
638
651
|
* <ul>
|
|
639
652
|
* <li><code>"pointermove"</code></li>
|
|
@@ -702,10 +715,10 @@ export function registerPointerEvent(eventType, region, callback) {
|
|
|
702
715
|
* allows the removal of event listeners from the object target.
|
|
703
716
|
* @see {@link http://www.w3.org/TR/pointerevents/#list-of-pointer-events|W3C Pointer Event list}
|
|
704
717
|
* @name releasePointerEvent
|
|
705
|
-
* @
|
|
718
|
+
* @memberof me.input
|
|
706
719
|
* @public
|
|
707
720
|
* @function
|
|
708
|
-
* @param {
|
|
721
|
+
* @param {string} eventType The event type for which the object was registered. See {@link me.input.registerPointerEvent}
|
|
709
722
|
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse} region the registered region to release for this event
|
|
710
723
|
* @param {Function} [callback="all"] if specified unregister the event only for the specific callback
|
|
711
724
|
* @example
|
|
@@ -726,7 +739,7 @@ export function releasePointerEvent(eventType, region, callback) {
|
|
|
726
739
|
eventType = eventTypes[i];
|
|
727
740
|
if (handlers.callbacks[eventType]) {
|
|
728
741
|
if (typeof (callback) !== "undefined") {
|
|
729
|
-
|
|
742
|
+
remove(handlers.callbacks[eventType], callback);
|
|
730
743
|
} else {
|
|
731
744
|
while (handlers.callbacks[eventType].length > 0) {
|
|
732
745
|
handlers.callbacks[eventType].pop();
|
|
@@ -747,7 +760,7 @@ export function releasePointerEvent(eventType, region, callback) {
|
|
|
747
760
|
/**
|
|
748
761
|
* allows the removal of all registered event listeners from the object target.
|
|
749
762
|
* @name releaseAllPointerEvents
|
|
750
|
-
* @
|
|
763
|
+
* @memberof me.input
|
|
751
764
|
* @public
|
|
752
765
|
* @function
|
|
753
766
|
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse} region the registered region to release event from
|
|
@@ -762,3 +775,45 @@ export function releaseAllPointerEvents(region) {
|
|
|
762
775
|
}
|
|
763
776
|
};
|
|
764
777
|
};
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* request for the pointer to be locked on the parent DOM element.
|
|
781
|
+
* (Must be called in a click event or an event that requires user interaction)
|
|
782
|
+
* @name requestPointerLock
|
|
783
|
+
* @memberof me.input
|
|
784
|
+
* @public
|
|
785
|
+
* @function
|
|
786
|
+
* @param {Function} [success] callback if the request is successful
|
|
787
|
+
* @returns {boolean} return true if the request was successfully submitted
|
|
788
|
+
* @example
|
|
789
|
+
* // register on the pointer lock change event
|
|
790
|
+
* event.on(event.POINTERLOCKCHANGE, (locked)=> {
|
|
791
|
+
* console.log("pointer lock: " + locked);
|
|
792
|
+
* });
|
|
793
|
+
* // request for pointer lock
|
|
794
|
+
* me.input.requestPointerLock();
|
|
795
|
+
*/
|
|
796
|
+
export function requestPointerLock() {
|
|
797
|
+
if (device.hasPointerLockSupport) {
|
|
798
|
+
var element = getParent();
|
|
799
|
+
element.requestPointerLock();
|
|
800
|
+
return true;
|
|
801
|
+
}
|
|
802
|
+
return false;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* Initiates an exit from pointer lock state
|
|
807
|
+
* @name exitPointerLock
|
|
808
|
+
* @memberof me.input
|
|
809
|
+
* @public
|
|
810
|
+
* @function
|
|
811
|
+
* @returns {boolean} return true if the request was successfully submitted
|
|
812
|
+
*/
|
|
813
|
+
export function exitPointerLock() {
|
|
814
|
+
if (device.hasPointerLockSupport) {
|
|
815
|
+
document.exitPointerLock();
|
|
816
|
+
return true;
|
|
817
|
+
}
|
|
818
|
+
return false;
|
|
819
|
+
}
|