melonjs 10.10.0 → 11.0.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 +4 -3
- package/dist/melonjs.js +1071 -2102
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +600 -1351
- package/dist/melonjs.module.js +996 -2029
- package/package.json +16 -19
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +6 -11
- package/src/geometries/ellipse.js +3 -12
- package/src/geometries/line.js +1 -4
- package/src/geometries/path2d.js +4 -14
- package/src/geometries/poly.js +6 -24
- package/src/geometries/rectangle.js +3 -15
- package/src/geometries/roundrect.js +2 -6
- package/src/index.js +0 -1
- package/src/input/gamepad.js +3 -14
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +4 -3
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +0 -3
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +5 -26
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +1 -1
- package/src/physics/body.js +4 -5
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +1 -13
- package/src/physics/detector.js +6 -56
- package/src/physics/quadtree.js +0 -7
- package/src/physics/response.js +48 -0
- package/src/physics/sat.js +4 -4
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/roundrect.js +4 -2
- package/src/renderable/GUI.js +6 -9
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/colorlayer.js +9 -7
- package/src/renderable/container.js +12 -38
- package/src/renderable/dragndrop.js +1 -10
- package/src/renderable/imagelayer.js +6 -10
- package/src/renderable/light2d.js +48 -16
- package/src/renderable/renderable.js +6 -28
- package/src/renderable/sprite.js +4 -16
- package/src/renderable/trigger.js +10 -3
- package/src/state/stage.js +0 -4
- package/src/state/state.js +22 -23
- package/src/system/device.js +16 -119
- package/src/system/dom.js +69 -0
- package/src/system/event.js +22 -0
- package/src/system/pooling.js +20 -9
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +13 -8
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +0 -3
- package/src/video/canvas/canvas_renderer.js +4 -39
- package/src/video/renderer.js +1 -23
- package/src/video/texture/atlas.js +2 -0
- package/src/video/texture/cache.js +0 -1
- package/src/video/texture/canvas_texture.js +16 -4
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +3 -6
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +0 -42
package/src/math/vector3.js
CHANGED
|
@@ -40,7 +40,6 @@ class Vector3d {
|
|
|
40
40
|
* set the Vector x and y properties to the given values<br>
|
|
41
41
|
* @name set
|
|
42
42
|
* @memberof Vector3d
|
|
43
|
-
* @function
|
|
44
43
|
* @param {number} x
|
|
45
44
|
* @param {number} y
|
|
46
45
|
* @param {number} [z=0]
|
|
@@ -56,7 +55,7 @@ class Vector3d {
|
|
|
56
55
|
/**
|
|
57
56
|
* x value of the vector
|
|
58
57
|
* @public
|
|
59
|
-
* @
|
|
58
|
+
* @member {number}
|
|
60
59
|
* @name x
|
|
61
60
|
* @memberof Vector3d
|
|
62
61
|
*/
|
|
@@ -65,7 +64,7 @@ class Vector3d {
|
|
|
65
64
|
/**
|
|
66
65
|
* y value of the vector
|
|
67
66
|
* @public
|
|
68
|
-
* @
|
|
67
|
+
* @member {number}
|
|
69
68
|
* @name y
|
|
70
69
|
* @memberof Vector3d
|
|
71
70
|
*/
|
|
@@ -74,7 +73,7 @@ class Vector3d {
|
|
|
74
73
|
/**
|
|
75
74
|
* z value of the vector
|
|
76
75
|
* @public
|
|
77
|
-
* @
|
|
76
|
+
* @member {number}
|
|
78
77
|
* @name z
|
|
79
78
|
* @memberof Vector3d
|
|
80
79
|
*/
|
|
@@ -87,7 +86,6 @@ class Vector3d {
|
|
|
87
86
|
* set the Vector x and y properties to 0
|
|
88
87
|
* @name setZero
|
|
89
88
|
* @memberof Vector3d
|
|
90
|
-
* @function
|
|
91
89
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
92
90
|
*/
|
|
93
91
|
setZero() {
|
|
@@ -98,7 +96,6 @@ class Vector3d {
|
|
|
98
96
|
* set the Vector x and y properties using the passed vector
|
|
99
97
|
* @name setV
|
|
100
98
|
* @memberof Vector3d
|
|
101
|
-
* @function
|
|
102
99
|
* @param {Vector2d|Vector3d} v
|
|
103
100
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
104
101
|
*/
|
|
@@ -110,7 +107,6 @@ class Vector3d {
|
|
|
110
107
|
* Add the passed vector to this vector
|
|
111
108
|
* @name add
|
|
112
109
|
* @memberof Vector3d
|
|
113
|
-
* @function
|
|
114
110
|
* @param {Vector2d|Vector3d} v
|
|
115
111
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
116
112
|
*/
|
|
@@ -122,7 +118,6 @@ class Vector3d {
|
|
|
122
118
|
* Substract the passed vector to this vector
|
|
123
119
|
* @name sub
|
|
124
120
|
* @memberof Vector3d
|
|
125
|
-
* @function
|
|
126
121
|
* @param {Vector2d|Vector3d} v
|
|
127
122
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
128
123
|
*/
|
|
@@ -134,7 +129,6 @@ class Vector3d {
|
|
|
134
129
|
* Multiply this vector values by the given scalar
|
|
135
130
|
* @name scale
|
|
136
131
|
* @memberof Vector3d
|
|
137
|
-
* @function
|
|
138
132
|
* @param {number} x
|
|
139
133
|
* @param {number} [y=x]
|
|
140
134
|
* @param {number} [z=1]
|
|
@@ -149,7 +143,6 @@ class Vector3d {
|
|
|
149
143
|
* Multiply this vector values by the passed vector
|
|
150
144
|
* @name scaleV
|
|
151
145
|
* @memberof Vector3d
|
|
152
|
-
* @function
|
|
153
146
|
* @param {Vector2d|Vector3d} v
|
|
154
147
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
155
148
|
*/
|
|
@@ -161,7 +154,6 @@ class Vector3d {
|
|
|
161
154
|
* Convert this vector into isometric coordinate space
|
|
162
155
|
* @name toIso
|
|
163
156
|
* @memberof Vector3d
|
|
164
|
-
* @function
|
|
165
157
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
166
158
|
*/
|
|
167
159
|
toIso() {
|
|
@@ -172,7 +164,6 @@ class Vector3d {
|
|
|
172
164
|
* Convert this vector into 2d coordinate space
|
|
173
165
|
* @name to2d
|
|
174
166
|
* @memberof Vector3d
|
|
175
|
-
* @function
|
|
176
167
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
177
168
|
*/
|
|
178
169
|
to2d() {
|
|
@@ -183,7 +174,6 @@ class Vector3d {
|
|
|
183
174
|
* Divide this vector values by the passed value
|
|
184
175
|
* @name div
|
|
185
176
|
* @memberof Vector3d
|
|
186
|
-
* @function
|
|
187
177
|
* @param {number} n the value to divide the vector by
|
|
188
178
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
189
179
|
*/
|
|
@@ -195,7 +185,6 @@ class Vector3d {
|
|
|
195
185
|
* Update this vector values to absolute values
|
|
196
186
|
* @name abs
|
|
197
187
|
* @memberof Vector3d
|
|
198
|
-
* @function
|
|
199
188
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
200
189
|
*/
|
|
201
190
|
abs() {
|
|
@@ -206,7 +195,6 @@ class Vector3d {
|
|
|
206
195
|
* Clamp the vector value within the specified value range
|
|
207
196
|
* @name clamp
|
|
208
197
|
* @memberof Vector3d
|
|
209
|
-
* @function
|
|
210
198
|
* @param {number} low
|
|
211
199
|
* @param {number} high
|
|
212
200
|
* @returns {Vector3d} new me.Vector3d
|
|
@@ -219,7 +207,6 @@ class Vector3d {
|
|
|
219
207
|
* Clamp this vector value within the specified value range
|
|
220
208
|
* @name clampSelf
|
|
221
209
|
* @memberof Vector3d
|
|
222
|
-
* @function
|
|
223
210
|
* @param {number} low
|
|
224
211
|
* @param {number} high
|
|
225
212
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
@@ -232,7 +219,6 @@ class Vector3d {
|
|
|
232
219
|
* Update this vector with the minimum value between this and the passed vector
|
|
233
220
|
* @name minV
|
|
234
221
|
* @memberof Vector3d
|
|
235
|
-
* @function
|
|
236
222
|
* @param {Vector2d|Vector3d} v
|
|
237
223
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
238
224
|
*/
|
|
@@ -245,7 +231,6 @@ class Vector3d {
|
|
|
245
231
|
* Update this vector with the maximum value between this and the passed vector
|
|
246
232
|
* @name maxV
|
|
247
233
|
* @memberof Vector3d
|
|
248
|
-
* @function
|
|
249
234
|
* @param {Vector2d|Vector3d} v
|
|
250
235
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
251
236
|
*/
|
|
@@ -258,7 +243,6 @@ class Vector3d {
|
|
|
258
243
|
* Floor the vector values
|
|
259
244
|
* @name floor
|
|
260
245
|
* @memberof Vector3d
|
|
261
|
-
* @function
|
|
262
246
|
* @returns {Vector3d} new me.Vector3d
|
|
263
247
|
*/
|
|
264
248
|
floor() {
|
|
@@ -269,7 +253,6 @@ class Vector3d {
|
|
|
269
253
|
* Floor this vector values
|
|
270
254
|
* @name floorSelf
|
|
271
255
|
* @memberof Vector3d
|
|
272
|
-
* @function
|
|
273
256
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
274
257
|
*/
|
|
275
258
|
floorSelf() {
|
|
@@ -280,7 +263,6 @@ class Vector3d {
|
|
|
280
263
|
* Ceil the vector values
|
|
281
264
|
* @name ceil
|
|
282
265
|
* @memberof Vector3d
|
|
283
|
-
* @function
|
|
284
266
|
* @returns {Vector3d} new me.Vector3d
|
|
285
267
|
*/
|
|
286
268
|
ceil() {
|
|
@@ -291,7 +273,6 @@ class Vector3d {
|
|
|
291
273
|
* Ceil this vector values
|
|
292
274
|
* @name ceilSelf
|
|
293
275
|
* @memberof Vector3d
|
|
294
|
-
* @function
|
|
295
276
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
296
277
|
*/
|
|
297
278
|
ceilSelf() {
|
|
@@ -302,7 +283,6 @@ class Vector3d {
|
|
|
302
283
|
* Negate the vector values
|
|
303
284
|
* @name negate
|
|
304
285
|
* @memberof Vector3d
|
|
305
|
-
* @function
|
|
306
286
|
* @returns {Vector3d} new me.Vector3d
|
|
307
287
|
*/
|
|
308
288
|
negate() {
|
|
@@ -313,7 +293,6 @@ class Vector3d {
|
|
|
313
293
|
* Negate this vector values
|
|
314
294
|
* @name negateSelf
|
|
315
295
|
* @memberof Vector3d
|
|
316
|
-
* @function
|
|
317
296
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
318
297
|
*/
|
|
319
298
|
negateSelf() {
|
|
@@ -324,7 +303,6 @@ class Vector3d {
|
|
|
324
303
|
* Copy the components of the given vector into this one
|
|
325
304
|
* @name copy
|
|
326
305
|
* @memberof Vector3d
|
|
327
|
-
* @function
|
|
328
306
|
* @param {Vector2d|Vector3d} v
|
|
329
307
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
330
308
|
*/
|
|
@@ -336,7 +314,7 @@ class Vector3d {
|
|
|
336
314
|
* return true if the two vectors are the same
|
|
337
315
|
* @name equals
|
|
338
316
|
* @memberof Vector3d
|
|
339
|
-
* @
|
|
317
|
+
* @method
|
|
340
318
|
* @param {Vector2d|Vector3d} v
|
|
341
319
|
* @returns {boolean}
|
|
342
320
|
*/
|
|
@@ -344,7 +322,6 @@ class Vector3d {
|
|
|
344
322
|
* return true if this vector is equal to the given values
|
|
345
323
|
* @name equals
|
|
346
324
|
* @memberof Vector3d
|
|
347
|
-
* @function
|
|
348
325
|
* @param {number} x
|
|
349
326
|
* @param {number} y
|
|
350
327
|
* @param {number} [z]
|
|
@@ -375,7 +352,6 @@ class Vector3d {
|
|
|
375
352
|
* normalize this vector (scale the vector so that its magnitude is 1)
|
|
376
353
|
* @name normalize
|
|
377
354
|
* @memberof Vector3d
|
|
378
|
-
* @function
|
|
379
355
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
380
356
|
*/
|
|
381
357
|
normalize() {
|
|
@@ -387,7 +363,6 @@ class Vector3d {
|
|
|
387
363
|
* (Effectively rotates it 90 degrees in a clockwise direction around the z axis)
|
|
388
364
|
* @name perp
|
|
389
365
|
* @memberof Vector3d
|
|
390
|
-
* @function
|
|
391
366
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
392
367
|
*/
|
|
393
368
|
perp() {
|
|
@@ -398,7 +373,6 @@ class Vector3d {
|
|
|
398
373
|
* Rotate this vector (counter-clockwise) by the specified angle (in radians) around the z axis
|
|
399
374
|
* @name rotate
|
|
400
375
|
* @memberof Vector3d
|
|
401
|
-
* @function
|
|
402
376
|
* @param {number} angle The angle to rotate (in radians)
|
|
403
377
|
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around (on the same z axis)
|
|
404
378
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
@@ -426,7 +400,6 @@ class Vector3d {
|
|
|
426
400
|
* return the dot product of this vector and the passed one
|
|
427
401
|
* @name dot
|
|
428
402
|
* @memberof Vector3d
|
|
429
|
-
* @function
|
|
430
403
|
* @param {Vector2d|Vector3d} v
|
|
431
404
|
* @returns {number} The dot product.
|
|
432
405
|
*/
|
|
@@ -438,7 +411,6 @@ class Vector3d {
|
|
|
438
411
|
* calculate the cross product of this vector and the passed one
|
|
439
412
|
* @name cross
|
|
440
413
|
* @memberof Vector3d
|
|
441
|
-
* @function
|
|
442
414
|
* @param {Vector3d} v
|
|
443
415
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
444
416
|
*/
|
|
@@ -457,7 +429,6 @@ class Vector3d {
|
|
|
457
429
|
* return the square length of this vector
|
|
458
430
|
* @name length2
|
|
459
431
|
* @memberof Vector3d
|
|
460
|
-
* @function
|
|
461
432
|
* @returns {number} The length^2 of this vector.
|
|
462
433
|
*/
|
|
463
434
|
length2() {
|
|
@@ -468,7 +439,6 @@ class Vector3d {
|
|
|
468
439
|
* return the length (magnitude) of this vector
|
|
469
440
|
* @name length
|
|
470
441
|
* @memberof Vector3d
|
|
471
|
-
* @function
|
|
472
442
|
* @returns {number} the length of this vector
|
|
473
443
|
*/
|
|
474
444
|
length() {
|
|
@@ -479,7 +449,6 @@ class Vector3d {
|
|
|
479
449
|
* Linearly interpolate between this vector and the given one.
|
|
480
450
|
* @name lerp
|
|
481
451
|
* @memberof Vector3d
|
|
482
|
-
* @function
|
|
483
452
|
* @param {Vector3d} v
|
|
484
453
|
* @param {number} alpha distance along the line (alpha = 0 will be this vector, and alpha = 1 will be the given one).
|
|
485
454
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
@@ -495,7 +464,6 @@ class Vector3d {
|
|
|
495
464
|
* return the distance between this vector and the passed one
|
|
496
465
|
* @name distance
|
|
497
466
|
* @memberof Vector3d
|
|
498
|
-
* @function
|
|
499
467
|
* @param {Vector2d|Vector3d} v
|
|
500
468
|
* @returns {number}
|
|
501
469
|
*/
|
|
@@ -510,7 +478,6 @@ class Vector3d {
|
|
|
510
478
|
* return the angle between this vector and the passed one
|
|
511
479
|
* @name angle
|
|
512
480
|
* @memberof Vector3d
|
|
513
|
-
* @function
|
|
514
481
|
* @param {Vector2d|Vector3d} v
|
|
515
482
|
* @returns {number} angle in radians
|
|
516
483
|
*/
|
|
@@ -522,7 +489,6 @@ class Vector3d {
|
|
|
522
489
|
* project this vector on to another vector.
|
|
523
490
|
* @name project
|
|
524
491
|
* @memberof Vector3d
|
|
525
|
-
* @function
|
|
526
492
|
* @param {Vector2d|Vector3d} v The vector to project onto.
|
|
527
493
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
528
494
|
*/
|
|
@@ -536,7 +502,6 @@ class Vector3d {
|
|
|
536
502
|
* This is slightly more efficient than `project` when dealing with unit vectors.
|
|
537
503
|
* @name projectN
|
|
538
504
|
* @memberof Vector3d
|
|
539
|
-
* @function
|
|
540
505
|
* @param {Vector2d|Vector3d} v The unit vector to project onto.
|
|
541
506
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
542
507
|
*/
|
|
@@ -549,7 +514,6 @@ class Vector3d {
|
|
|
549
514
|
* return a clone copy of this vector
|
|
550
515
|
* @name clone
|
|
551
516
|
* @memberof Vector3d
|
|
552
|
-
* @function
|
|
553
517
|
* @returns {Vector3d} new me.Vector3d
|
|
554
518
|
*/
|
|
555
519
|
clone() {
|
|
@@ -560,7 +524,6 @@ class Vector3d {
|
|
|
560
524
|
* convert the object to a string representation
|
|
561
525
|
* @name toString
|
|
562
526
|
* @memberof Vector3d
|
|
563
|
-
* @function
|
|
564
527
|
* @returns {string}
|
|
565
528
|
*/
|
|
566
529
|
toString() {
|
package/src/particles/emitter.js
CHANGED
|
@@ -8,7 +8,7 @@ import Container from "./../renderable/container.js";
|
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
function createDefaultParticleTexture(w = 8, h = 8) {
|
|
11
|
-
var defaultParticleTexture = pool.pull("CanvasTexture", w, h, true);
|
|
11
|
+
var defaultParticleTexture = pool.pull("CanvasTexture", w, h, { offscreenCanvas: true });
|
|
12
12
|
|
|
13
13
|
defaultParticleTexture.context.fillStyle = "#fff";
|
|
14
14
|
defaultParticleTexture.context.fillRect(0, 0, w, h);
|
package/src/physics/body.js
CHANGED
|
@@ -13,6 +13,7 @@ import { world } from "./../game.js";
|
|
|
13
13
|
/**
|
|
14
14
|
* @classdesc
|
|
15
15
|
* a Generic Physic Body Object with some physic properties and behavior functionality, to as a member of a Renderable.
|
|
16
|
+
* @see Renderable.body
|
|
16
17
|
*/
|
|
17
18
|
class Body {
|
|
18
19
|
/**
|
|
@@ -368,7 +369,6 @@ class Body {
|
|
|
368
369
|
|
|
369
370
|
/**
|
|
370
371
|
* returns the AABB bounding box for this body
|
|
371
|
-
* @function
|
|
372
372
|
* @returns {Bounds} bounding box Rectangle object
|
|
373
373
|
*/
|
|
374
374
|
getBounds() {
|
|
@@ -439,7 +439,7 @@ class Body {
|
|
|
439
439
|
|
|
440
440
|
/**
|
|
441
441
|
* the built-in function to solve the collision response
|
|
442
|
-
* @param {object} response the collision response object (see {@link
|
|
442
|
+
* @param {object} response the collision response object (see {@link ResponseObject})
|
|
443
443
|
*/
|
|
444
444
|
respondToCollision(response) {
|
|
445
445
|
// the overlap vector
|
|
@@ -510,6 +510,7 @@ class Body {
|
|
|
510
510
|
|
|
511
511
|
/**
|
|
512
512
|
* Returns true if the any of the shape composing the body contains the given point.
|
|
513
|
+
* @method Body#contains
|
|
513
514
|
* @param {Vector2d} point
|
|
514
515
|
* @returns {boolean} true if contains
|
|
515
516
|
*/
|
|
@@ -573,7 +574,6 @@ class Body {
|
|
|
573
574
|
* cap the body velocity (body.maxVel property) to the specified value<br>
|
|
574
575
|
* @param {number} x max velocity on x axis
|
|
575
576
|
* @param {number} y max velocity on y axis
|
|
576
|
-
* @protected
|
|
577
577
|
*/
|
|
578
578
|
setMaxVelocity(x, y) {
|
|
579
579
|
this.maxVel.x = x;
|
|
@@ -584,7 +584,6 @@ class Body {
|
|
|
584
584
|
* set the body default friction
|
|
585
585
|
* @param {number} x horizontal friction
|
|
586
586
|
* @param {number} y vertical friction
|
|
587
|
-
* @protected
|
|
588
587
|
*/
|
|
589
588
|
setFriction(x = 0, y = 0) {
|
|
590
589
|
this.friction.x = x;
|
|
@@ -692,7 +691,7 @@ class Body {
|
|
|
692
691
|
pool.push(this.friction);
|
|
693
692
|
pool.push(this.maxVel);
|
|
694
693
|
this.shapes.forEach((shape) => {
|
|
695
|
-
pool.push(shape);
|
|
694
|
+
pool.push(shape, false);
|
|
696
695
|
});
|
|
697
696
|
|
|
698
697
|
// set to undefined
|
package/src/physics/bounds.js
CHANGED
|
@@ -34,7 +34,6 @@ class Bounds {
|
|
|
34
34
|
* reset the bound
|
|
35
35
|
* @name clear
|
|
36
36
|
* @memberof Bounds
|
|
37
|
-
* @function
|
|
38
37
|
*/
|
|
39
38
|
clear() {
|
|
40
39
|
this.setMinMax(Infinity, Infinity, -Infinity, -Infinity);
|
|
@@ -45,7 +44,6 @@ class Bounds {
|
|
|
45
44
|
* sets the bounds to the given min and max value
|
|
46
45
|
* @name setMinMax
|
|
47
46
|
* @memberof Bounds
|
|
48
|
-
* @function
|
|
49
47
|
* @param {number} minX
|
|
50
48
|
* @param {number} minY
|
|
51
49
|
* @param {number} maxX
|
|
@@ -205,7 +203,6 @@ class Bounds {
|
|
|
205
203
|
* Updates bounds using the given vertices
|
|
206
204
|
* @name update
|
|
207
205
|
* @memberof Bounds
|
|
208
|
-
* @function
|
|
209
206
|
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
210
207
|
*/
|
|
211
208
|
update(vertices) {
|
|
@@ -216,7 +213,6 @@ class Bounds {
|
|
|
216
213
|
* add the given vertices to the bounds definition.
|
|
217
214
|
* @name add
|
|
218
215
|
* @memberof Bounds
|
|
219
|
-
* @function
|
|
220
216
|
* @param {Vector2d[]} vertices an array of me.Vector2d points
|
|
221
217
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
222
218
|
*/
|
|
@@ -237,7 +233,6 @@ class Bounds {
|
|
|
237
233
|
* add the given bounds to the bounds definition.
|
|
238
234
|
* @name addBounds
|
|
239
235
|
* @memberof Bounds
|
|
240
|
-
* @function
|
|
241
236
|
* @param {Bounds} bounds
|
|
242
237
|
* @param {boolean} [clear=false] either to reset the bounds before adding the new vertices
|
|
243
238
|
*/
|
|
@@ -256,7 +251,6 @@ class Bounds {
|
|
|
256
251
|
* add the given point to the bounds definition.
|
|
257
252
|
* @name addPoint
|
|
258
253
|
* @memberof Bounds
|
|
259
|
-
* @function
|
|
260
254
|
* @param {Vector2d} v
|
|
261
255
|
* @param {Matrix2d} [m] an optional transform to apply to the given point
|
|
262
256
|
*/
|
|
@@ -274,7 +268,6 @@ class Bounds {
|
|
|
274
268
|
* add the given quad coordinates to this bound definition, multiplied by the given matrix
|
|
275
269
|
* @name addFrame
|
|
276
270
|
* @memberof Bounds
|
|
277
|
-
* @function
|
|
278
271
|
* @param {number} x0 - left X coordinates of the quad
|
|
279
272
|
* @param {number} y0 - top Y coordinates of the quad
|
|
280
273
|
* @param {number} x1 - right X coordinates of the quad
|
|
@@ -282,7 +275,7 @@ class Bounds {
|
|
|
282
275
|
* @param {Matrix2d} [m] an optional transform to apply to the given frame coordinates
|
|
283
276
|
*/
|
|
284
277
|
addFrame(x0, y0, x1, y1, m) {
|
|
285
|
-
var v =
|
|
278
|
+
var v = pool.pull("Vector2d");
|
|
286
279
|
|
|
287
280
|
// transform all points and add to the bound definition
|
|
288
281
|
this.addPoint(v.set(x0, y0), m);
|
|
@@ -290,14 +283,14 @@ class Bounds {
|
|
|
290
283
|
this.addPoint(v.set(x0, y1), m);
|
|
291
284
|
this.addPoint(v.set(x1, y1), m);
|
|
292
285
|
|
|
293
|
-
|
|
286
|
+
pool.push(v);
|
|
294
287
|
}
|
|
295
288
|
|
|
296
289
|
/**
|
|
297
290
|
* Returns true if the bounds contains the given point.
|
|
298
291
|
* @name contains
|
|
299
292
|
* @memberof Bounds
|
|
300
|
-
* @
|
|
293
|
+
* @method
|
|
301
294
|
* @param {Vector2d} point
|
|
302
295
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
303
296
|
*/
|
|
@@ -305,7 +298,6 @@ class Bounds {
|
|
|
305
298
|
* Returns true if the bounds contains the given point.
|
|
306
299
|
* @name contains
|
|
307
300
|
* @memberof Bounds
|
|
308
|
-
* @function
|
|
309
301
|
* @param {number} x
|
|
310
302
|
* @param {number} y
|
|
311
303
|
* @returns {boolean} True if the bounds contain the point, otherwise false
|
|
@@ -339,7 +331,6 @@ class Bounds {
|
|
|
339
331
|
* Returns true if the two bounds intersect.
|
|
340
332
|
* @name overlaps
|
|
341
333
|
* @memberof Bounds
|
|
342
|
-
* @function
|
|
343
334
|
* @param {Bounds|Rect} bounds
|
|
344
335
|
* @returns {boolean} True if the bounds overlap, otherwise false
|
|
345
336
|
*/
|
|
@@ -352,7 +343,6 @@ class Bounds {
|
|
|
352
343
|
* determines whether all coordinates of this bounds are finite numbers.
|
|
353
344
|
* @name isFinite
|
|
354
345
|
* @memberof Bounds
|
|
355
|
-
* @function
|
|
356
346
|
* @returns {boolean} false if all coordinates are positive or negative Infinity or NaN; otherwise, true.
|
|
357
347
|
*/
|
|
358
348
|
isFinite() {
|
|
@@ -363,14 +353,13 @@ class Bounds {
|
|
|
363
353
|
* Translates the bounds by the given vector.
|
|
364
354
|
* @name translate
|
|
365
355
|
* @memberof Bounds
|
|
366
|
-
* @
|
|
356
|
+
* @method
|
|
367
357
|
* @param {Vector2d} vector
|
|
368
358
|
*/
|
|
369
359
|
/**
|
|
370
360
|
* Translates the bounds by x on the x axis, and y on the y axis
|
|
371
361
|
* @name translate
|
|
372
362
|
* @memberof Bounds
|
|
373
|
-
* @function
|
|
374
363
|
* @param {number} x
|
|
375
364
|
* @param {number} y
|
|
376
365
|
*/
|
|
@@ -395,14 +384,13 @@ class Bounds {
|
|
|
395
384
|
* Shifts the bounds to the given position vector.
|
|
396
385
|
* @name shift
|
|
397
386
|
* @memberof Bounds
|
|
398
|
-
* @
|
|
387
|
+
* @method
|
|
399
388
|
* @param {Vector2d} position
|
|
400
389
|
*/
|
|
401
390
|
/**
|
|
402
391
|
* Shifts the bounds to the given x, y position.
|
|
403
392
|
* @name shift
|
|
404
393
|
* @memberof Bounds
|
|
405
|
-
* @function
|
|
406
394
|
* @param {number} x
|
|
407
395
|
* @param {number} y
|
|
408
396
|
*/
|
|
@@ -432,7 +420,6 @@ class Bounds {
|
|
|
432
420
|
* clone this bounds
|
|
433
421
|
* @name clone
|
|
434
422
|
* @memberof Bounds
|
|
435
|
-
* @function
|
|
436
423
|
* @returns {Bounds}
|
|
437
424
|
*/
|
|
438
425
|
clone() {
|
|
@@ -445,7 +432,6 @@ class Bounds {
|
|
|
445
432
|
* Returns a polygon whose edges are the same as this bounds.
|
|
446
433
|
* @name toPolygon
|
|
447
434
|
* @memberof Bounds
|
|
448
|
-
* @function
|
|
449
435
|
* @returns {Polygon} a new Polygon that represents this bounds.
|
|
450
436
|
*/
|
|
451
437
|
toPolygon () {
|
package/src/physics/collision.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rayCast
|
|
1
|
+
import { rayCast } from "./detector.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Collision detection (and projection-based collision response) of 2D shapes.<br>
|
|
@@ -91,23 +91,11 @@ var collision = {
|
|
|
91
91
|
ALL_OBJECT : 0xFFFFFFFF // all objects
|
|
92
92
|
},
|
|
93
93
|
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* a global instance of a response object used for collision detection <br>
|
|
97
|
-
* this object will be reused amongst collision detection call if not user-defined response is specified
|
|
98
|
-
* @name response
|
|
99
|
-
* @memberof collision
|
|
100
|
-
* @public
|
|
101
|
-
* @type {collision.ResponseObject}
|
|
102
|
-
*/
|
|
103
|
-
response : globalResponse,
|
|
104
|
-
|
|
105
94
|
/**
|
|
106
95
|
* Checks for object colliding with the given line
|
|
107
96
|
* @name rayCast
|
|
108
97
|
* @memberof collision
|
|
109
98
|
* @public
|
|
110
|
-
* @function
|
|
111
99
|
* @param {Line} line line to be tested for collision
|
|
112
100
|
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
113
101
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|
package/src/physics/detector.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as SAT from "./sat.js";
|
|
2
|
+
import ResponseObject from "./response.js";
|
|
2
3
|
import Vector2d from "./../math/vector2.js";
|
|
3
4
|
import { world } from "./../game.js";
|
|
4
5
|
|
|
5
6
|
// a dummy object when using Line for raycasting
|
|
6
|
-
|
|
7
|
+
let dummyObj = {
|
|
7
8
|
pos : new Vector2d(0, 0),
|
|
8
9
|
ancestor : {
|
|
9
10
|
_absPos : new Vector2d(0, 0),
|
|
@@ -13,13 +14,15 @@ var dummyObj = {
|
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
16
|
|
|
17
|
+
// the global response object used for collisions
|
|
18
|
+
let globalResponse = new ResponseObject();
|
|
19
|
+
|
|
16
20
|
/**
|
|
17
21
|
* a function used to determine if two objects should collide (based on both respective objects collision mask and type).<br>
|
|
18
22
|
* you can redefine this function if you need any specific rules over what should collide with what.
|
|
19
23
|
* @name shouldCollide
|
|
20
24
|
* @memberof collision
|
|
21
25
|
* @ignore
|
|
22
|
-
* @function
|
|
23
26
|
* @param {Renderable} a a reference to the object A.
|
|
24
27
|
* @param {Renderable} b a reference to the object B.
|
|
25
28
|
* @returns {boolean} true if they should collide, false otherwise
|
|
@@ -34,66 +37,14 @@ function shouldCollide(a, b) {
|
|
|
34
37
|
);
|
|
35
38
|
};
|
|
36
39
|
|
|
37
|
-
/**
|
|
38
|
-
* @classdesc
|
|
39
|
-
* An object representing the result of an intersection.
|
|
40
|
-
* @property {Renderable} a The first object participating in the intersection
|
|
41
|
-
* @property {Renderable} b The second object participating in the intersection
|
|
42
|
-
* @property {number} overlap Magnitude of the overlap on the shortest colliding axis
|
|
43
|
-
* @property {Vector2d} overlapV The overlap vector (i.e. `overlapN.scale(overlap, overlap)`). If this vector is subtracted from the position of a, a and b will no longer be colliding
|
|
44
|
-
* @property {Vector2d} overlapN The shortest colliding axis (unit-vector)
|
|
45
|
-
* @property {boolean} aInB Whether the first object is entirely inside the second
|
|
46
|
-
* @property {boolean} bInA Whether the second object is entirely inside the first
|
|
47
|
-
* @property {number} indexShapeA The index of the colliding shape for the object a body
|
|
48
|
-
* @property {number} indexShapeB The index of the colliding shape for the object b body
|
|
49
|
-
* @name ResponseObject
|
|
50
|
-
* @memberof collision
|
|
51
|
-
* @public
|
|
52
|
-
*/
|
|
53
|
-
class ResponseObject {
|
|
54
|
-
constructor() {
|
|
55
|
-
this.a = null;
|
|
56
|
-
this.b = null;
|
|
57
|
-
this.overlapN = new Vector2d();
|
|
58
|
-
this.overlapV = new Vector2d();
|
|
59
|
-
this.aInB = true;
|
|
60
|
-
this.bInA = true;
|
|
61
|
-
this.indexShapeA = -1;
|
|
62
|
-
this.indexShapeB = -1;
|
|
63
|
-
this.overlap = Number.MAX_VALUE;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Set some values of the response back to their defaults. <br>
|
|
68
|
-
* Call this between tests if you are going to reuse a single <br>
|
|
69
|
-
* Response object for multiple intersection tests <br>
|
|
70
|
-
* (recommended as it will avoid allocating extra memory) <br>
|
|
71
|
-
* @name clear
|
|
72
|
-
* @memberof collision.ResponseObject
|
|
73
|
-
* @public
|
|
74
|
-
* @function
|
|
75
|
-
* @returns {object} this object for chaining
|
|
76
|
-
*/
|
|
77
|
-
clear () {
|
|
78
|
-
this.aInB = true;
|
|
79
|
-
this.bInA = true;
|
|
80
|
-
this.overlap = Number.MAX_VALUE;
|
|
81
|
-
this.indexShapeA = -1;
|
|
82
|
-
this.indexShapeB = -1;
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
40
|
|
|
87
|
-
// @ignore
|
|
88
|
-
export var globalResponse = new ResponseObject();
|
|
89
41
|
|
|
90
42
|
/**
|
|
91
43
|
* find all the collisions for the specified object
|
|
92
44
|
* @name collisionCheck
|
|
93
45
|
* @ignore
|
|
94
|
-
* @function
|
|
95
46
|
* @param {Renderable} objA object to be tested for collision
|
|
96
|
-
* @param {
|
|
47
|
+
* @param {ResponseObject} [response] a user defined response object that will be populated if they intersect.
|
|
97
48
|
* @returns {boolean} in case of collision, false otherwise
|
|
98
49
|
*/
|
|
99
50
|
export function collisionCheck(objA, response = globalResponse) {
|
|
@@ -163,7 +114,6 @@ export function collisionCheck(objA, response = globalResponse) {
|
|
|
163
114
|
* Checks for object colliding with the given line
|
|
164
115
|
* @name rayCast
|
|
165
116
|
* @ignore
|
|
166
|
-
* @function
|
|
167
117
|
* @param {Line} line line to be tested for collision
|
|
168
118
|
* @param {Array.<Renderable>} [result] a user defined array that will be populated with intersecting physic objects.
|
|
169
119
|
* @returns {Array.<Renderable>} an array of intersecting physic objects
|