melonjs 10.2.1 → 10.2.2
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 +2735 -2760
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2186 -2162
- package/dist/melonjs.module.js +2323 -2362
- package/package.json +8 -9
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +52 -74
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +2 -2
- package/src/index.js +11 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +18 -26
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +29 -25
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +44 -44
- package/src/physics/bounds.js +34 -34
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -10
- package/src/physics/quadtree.js +19 -17
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +12 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +64 -46
- package/src/renderable/imagelayer.js +30 -31
- package/src/renderable/nineslicesprite.js +13 -13
- package/src/renderable/renderable.js +68 -66
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +6 -6
- package/src/state/state.js +54 -54
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +39 -41
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +74 -75
- package/src/video/video.js +30 -30
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +33 -34
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/particles/emitter.js
CHANGED
|
@@ -16,8 +16,8 @@ var pixel = (function () {
|
|
|
16
16
|
})();
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* me.ParticleEmitterSettings contains the default settings for me.ParticleEmitter
|
|
20
|
-
* @
|
|
19
|
+
* me.ParticleEmitterSettings contains the default settings for me.ParticleEmitter
|
|
20
|
+
* @ignore
|
|
21
21
|
* @class
|
|
22
22
|
* @memberOf me
|
|
23
23
|
* @see me.ParticleEmitter
|
|
@@ -26,7 +26,7 @@ var ParticleEmitterSettings = {
|
|
|
26
26
|
/**
|
|
27
27
|
* Width of the particle spawn area.<br>
|
|
28
28
|
* @public
|
|
29
|
-
* @type
|
|
29
|
+
* @type {number}
|
|
30
30
|
* @name width
|
|
31
31
|
* @memberOf me.ParticleEmitterSettings
|
|
32
32
|
* @default 0
|
|
@@ -34,9 +34,9 @@ var ParticleEmitterSettings = {
|
|
|
34
34
|
width : 0,
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Height of the particle spawn area
|
|
37
|
+
* Height of the particle spawn area
|
|
38
38
|
* @public
|
|
39
|
-
* @type
|
|
39
|
+
* @type {number}
|
|
40
40
|
* @name height
|
|
41
41
|
* @memberOf me.ParticleEmitterSettings
|
|
42
42
|
* @default 0
|
|
@@ -44,9 +44,9 @@ var ParticleEmitterSettings = {
|
|
|
44
44
|
height : 0,
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
|
-
* Image used for particles
|
|
47
|
+
* Image used for particles
|
|
48
48
|
* @public
|
|
49
|
-
* @type CanvasImageSource
|
|
49
|
+
* @type {CanvasImageSource}
|
|
50
50
|
* @name image
|
|
51
51
|
* @memberOf me.ParticleEmitterSettings
|
|
52
52
|
* @default 1x1 white pixel
|
|
@@ -55,9 +55,9 @@ var ParticleEmitterSettings = {
|
|
|
55
55
|
image : pixel,
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Total number of particles in the emitter
|
|
58
|
+
* Total number of particles in the emitter
|
|
59
59
|
* @public
|
|
60
|
-
* @type
|
|
60
|
+
* @type {number}
|
|
61
61
|
* @name totalParticles
|
|
62
62
|
* @default 50
|
|
63
63
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -65,9 +65,9 @@ var ParticleEmitterSettings = {
|
|
|
65
65
|
totalParticles : 50,
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
|
-
* Start angle for particle launch in Radians
|
|
68
|
+
* Start angle for particle launch in Radians
|
|
69
69
|
* @public
|
|
70
|
-
* @type
|
|
70
|
+
* @type {number}
|
|
71
71
|
* @name angle
|
|
72
72
|
* @default Math.PI / 2
|
|
73
73
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -75,9 +75,9 @@ var ParticleEmitterSettings = {
|
|
|
75
75
|
angle : Math.PI / 2,
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
* Variation in the start angle for particle launch in Radians
|
|
78
|
+
* Variation in the start angle for particle launch in Radians
|
|
79
79
|
* @public
|
|
80
|
-
* @type
|
|
80
|
+
* @type {number}
|
|
81
81
|
* @name angleVariation
|
|
82
82
|
* @default 0
|
|
83
83
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -85,9 +85,9 @@ var ParticleEmitterSettings = {
|
|
|
85
85
|
angleVariation : 0,
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
|
-
* Minimum time each particle lives once it is emitted in ms
|
|
88
|
+
* Minimum time each particle lives once it is emitted in ms
|
|
89
89
|
* @public
|
|
90
|
-
* @type
|
|
90
|
+
* @type {number}
|
|
91
91
|
* @name minLife
|
|
92
92
|
* @default 1000
|
|
93
93
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -95,9 +95,9 @@ var ParticleEmitterSettings = {
|
|
|
95
95
|
minLife : 1000,
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
|
-
* Maximum time each particle lives once it is emitted in ms
|
|
98
|
+
* Maximum time each particle lives once it is emitted in ms
|
|
99
99
|
* @public
|
|
100
|
-
* @type
|
|
100
|
+
* @type {number}
|
|
101
101
|
* @name maxLife
|
|
102
102
|
* @default 3000
|
|
103
103
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -107,7 +107,7 @@ var ParticleEmitterSettings = {
|
|
|
107
107
|
/**
|
|
108
108
|
* Start speed of particles.<br>
|
|
109
109
|
* @public
|
|
110
|
-
* @type
|
|
110
|
+
* @type {number}
|
|
111
111
|
* @name speed
|
|
112
112
|
* @default 2
|
|
113
113
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -115,9 +115,9 @@ var ParticleEmitterSettings = {
|
|
|
115
115
|
speed : 2,
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Variation in the start speed of particles
|
|
118
|
+
* Variation in the start speed of particles
|
|
119
119
|
* @public
|
|
120
|
-
* @type
|
|
120
|
+
* @type {number}
|
|
121
121
|
* @name speedVariation
|
|
122
122
|
* @default 1
|
|
123
123
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -125,9 +125,9 @@ var ParticleEmitterSettings = {
|
|
|
125
125
|
speedVariation : 1,
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* Minimum start rotation for particles sprites in Radians
|
|
128
|
+
* Minimum start rotation for particles sprites in Radians
|
|
129
129
|
* @public
|
|
130
|
-
* @type
|
|
130
|
+
* @type {number}
|
|
131
131
|
* @name minRotation
|
|
132
132
|
* @default 0
|
|
133
133
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -135,9 +135,9 @@ var ParticleEmitterSettings = {
|
|
|
135
135
|
minRotation : 0,
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
* Maximum start rotation for particles sprites in Radians
|
|
138
|
+
* Maximum start rotation for particles sprites in Radians
|
|
139
139
|
* @public
|
|
140
|
-
* @type
|
|
140
|
+
* @type {number}
|
|
141
141
|
* @name maxRotation
|
|
142
142
|
* @default 0
|
|
143
143
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -145,9 +145,9 @@ var ParticleEmitterSettings = {
|
|
|
145
145
|
maxRotation : 0,
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* Minimum start scale ratio for particles (1 = no scaling)
|
|
148
|
+
* Minimum start scale ratio for particles (1 = no scaling)
|
|
149
149
|
* @public
|
|
150
|
-
* @type
|
|
150
|
+
* @type {number}
|
|
151
151
|
* @name minStartScale
|
|
152
152
|
* @default 1
|
|
153
153
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -155,9 +155,9 @@ var ParticleEmitterSettings = {
|
|
|
155
155
|
minStartScale : 1,
|
|
156
156
|
|
|
157
157
|
/**
|
|
158
|
-
* Maximum start scale ratio for particles (1 = no scaling)
|
|
158
|
+
* Maximum start scale ratio for particles (1 = no scaling)
|
|
159
159
|
* @public
|
|
160
|
-
* @type
|
|
160
|
+
* @type {number}
|
|
161
161
|
* @name maxStartScale
|
|
162
162
|
* @default 1
|
|
163
163
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -165,9 +165,9 @@ var ParticleEmitterSettings = {
|
|
|
165
165
|
maxStartScale : 1,
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
|
-
* Minimum end scale ratio for particles
|
|
168
|
+
* Minimum end scale ratio for particles
|
|
169
169
|
* @public
|
|
170
|
-
* @type
|
|
170
|
+
* @type {number}
|
|
171
171
|
* @name minEndScale
|
|
172
172
|
* @default 0
|
|
173
173
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -175,9 +175,9 @@ var ParticleEmitterSettings = {
|
|
|
175
175
|
minEndScale : 0,
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
|
-
* Maximum end scale ratio for particles
|
|
178
|
+
* Maximum end scale ratio for particles
|
|
179
179
|
* @public
|
|
180
|
-
* @type
|
|
180
|
+
* @type {number}
|
|
181
181
|
* @name maxEndScale
|
|
182
182
|
* @default 0
|
|
183
183
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -185,9 +185,9 @@ var ParticleEmitterSettings = {
|
|
|
185
185
|
maxEndScale : 0,
|
|
186
186
|
|
|
187
187
|
/**
|
|
188
|
-
* Vertical force (Gravity) for each particle
|
|
188
|
+
* Vertical force (Gravity) for each particle
|
|
189
189
|
* @public
|
|
190
|
-
* @type
|
|
190
|
+
* @type {number}
|
|
191
191
|
* @name gravity
|
|
192
192
|
* @default 0
|
|
193
193
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -196,9 +196,9 @@ var ParticleEmitterSettings = {
|
|
|
196
196
|
gravity : 0,
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
* Horizontal force (like a Wind) for each particle
|
|
199
|
+
* Horizontal force (like a Wind) for each particle
|
|
200
200
|
* @public
|
|
201
|
-
* @type
|
|
201
|
+
* @type {number}
|
|
202
202
|
* @name wind
|
|
203
203
|
* @default 0
|
|
204
204
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -210,7 +210,7 @@ var ParticleEmitterSettings = {
|
|
|
210
210
|
* The particle sprite should aim at zero angle (draw from left to right).<br>
|
|
211
211
|
* Override the particle minRotation and maxRotation.<br>
|
|
212
212
|
* @public
|
|
213
|
-
* @type
|
|
213
|
+
* @type {boolean}
|
|
214
214
|
* @name followTrajectory
|
|
215
215
|
* @default false
|
|
216
216
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -221,7 +221,7 @@ var ParticleEmitterSettings = {
|
|
|
221
221
|
* Enable the Texture Additive by canvas composite operation (lighter).<br>
|
|
222
222
|
* WARNING: Composite Operation may decreases performance!.<br>
|
|
223
223
|
* @public
|
|
224
|
-
* @type
|
|
224
|
+
* @type {boolean}
|
|
225
225
|
* @name textureAdditive
|
|
226
226
|
* @default false
|
|
227
227
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -231,7 +231,7 @@ var ParticleEmitterSettings = {
|
|
|
231
231
|
/**
|
|
232
232
|
* Update particles only in the viewport, remove it when out of viewport.<br>
|
|
233
233
|
* @public
|
|
234
|
-
* @type
|
|
234
|
+
* @type {boolean}
|
|
235
235
|
* @name onlyInViewport
|
|
236
236
|
* @default true
|
|
237
237
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -241,7 +241,7 @@ var ParticleEmitterSettings = {
|
|
|
241
241
|
/**
|
|
242
242
|
* Render particles in screen space. <br>
|
|
243
243
|
* @public
|
|
244
|
-
* @type
|
|
244
|
+
* @type {boolean}
|
|
245
245
|
* @name floating
|
|
246
246
|
* @default false
|
|
247
247
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -251,7 +251,7 @@ var ParticleEmitterSettings = {
|
|
|
251
251
|
/**
|
|
252
252
|
* Maximum number of particles launched each time in this emitter (used only if emitter is Stream).<br>
|
|
253
253
|
* @public
|
|
254
|
-
* @type
|
|
254
|
+
* @type {number}
|
|
255
255
|
* @name maxParticles
|
|
256
256
|
* @default 10
|
|
257
257
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -262,7 +262,7 @@ var ParticleEmitterSettings = {
|
|
|
262
262
|
* How often a particle is emitted in ms (used only if emitter is Stream).<br>
|
|
263
263
|
* Necessary that value is greater than zero.<br>
|
|
264
264
|
* @public
|
|
265
|
-
* @type
|
|
265
|
+
* @type {number}
|
|
266
266
|
* @name frequency
|
|
267
267
|
* @default 100
|
|
268
268
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -273,7 +273,7 @@ var ParticleEmitterSettings = {
|
|
|
273
273
|
* Duration that the emitter releases particles in ms (used only if emitter is Stream).<br>
|
|
274
274
|
* After this period, the emitter stop the launch of particles.<br>
|
|
275
275
|
* @public
|
|
276
|
-
* @type
|
|
276
|
+
* @type {number}
|
|
277
277
|
* @name duration
|
|
278
278
|
* @default Infinity
|
|
279
279
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -284,7 +284,7 @@ var ParticleEmitterSettings = {
|
|
|
284
284
|
* Skip n frames after updating the particle system once. <br>
|
|
285
285
|
* This can be used to reduce the performance impact of emitters with many particles.<br>
|
|
286
286
|
* @public
|
|
287
|
-
* @type
|
|
287
|
+
* @type {number}
|
|
288
288
|
* @name framesToSkip
|
|
289
289
|
* @default 0
|
|
290
290
|
* @memberOf me.ParticleEmitterSettings
|
|
@@ -298,11 +298,10 @@ var ParticleEmitterSettings = {
|
|
|
298
298
|
* @extends Rect
|
|
299
299
|
* @memberOf me
|
|
300
300
|
* @constructor
|
|
301
|
-
* @param {
|
|
302
|
-
* @param {
|
|
301
|
+
* @param {number} x x-position of the particle emitter
|
|
302
|
+
* @param {number} y y-position of the particle emitter
|
|
303
303
|
* @param {object} settings An object containing the settings for the particle emitter. See {@link me.ParticleEmitterSettings}
|
|
304
304
|
* @example
|
|
305
|
-
*
|
|
306
305
|
* // Create a basic emitter at position 100, 100
|
|
307
306
|
* var emitter = new me.ParticleEmitter(100, 100);
|
|
308
307
|
*
|
|
@@ -324,7 +323,6 @@ var ParticleEmitterSettings = {
|
|
|
324
323
|
* // At the end, remove emitter from the game world
|
|
325
324
|
* // call this in onDestroyEvent function
|
|
326
325
|
* me.game.world.removeChild(emitter);
|
|
327
|
-
*
|
|
328
326
|
*/
|
|
329
327
|
class ParticleEmitter extends Renderable {
|
|
330
328
|
|
|
@@ -379,7 +377,7 @@ class ParticleEmitter extends Renderable {
|
|
|
379
377
|
|
|
380
378
|
/**
|
|
381
379
|
* Floating property for particles, value is forwarded to the particle container <br>
|
|
382
|
-
* @type
|
|
380
|
+
* @type {boolean}
|
|
383
381
|
* @name floating
|
|
384
382
|
* @memberOf me.ParticleEmitter
|
|
385
383
|
*/
|
|
@@ -432,7 +430,7 @@ class ParticleEmitter extends Renderable {
|
|
|
432
430
|
* @name getRandomPointX
|
|
433
431
|
* @memberOf me.ParticleEmitter
|
|
434
432
|
* @function
|
|
435
|
-
* @
|
|
433
|
+
* @returns {number}
|
|
436
434
|
*/
|
|
437
435
|
getRandomPointX() {
|
|
438
436
|
return this.pos.x + randomFloat(0, this.width);
|
|
@@ -443,7 +441,7 @@ class ParticleEmitter extends Renderable {
|
|
|
443
441
|
* @name getRandomPointY
|
|
444
442
|
* @memberOf me.ParticleEmitter
|
|
445
443
|
* @function
|
|
446
|
-
* @
|
|
444
|
+
* @returns {number}
|
|
447
445
|
*/
|
|
448
446
|
getRandomPointY() {
|
|
449
447
|
return this.pos.y + randomFloat(0, this.height);
|
|
@@ -452,7 +450,7 @@ class ParticleEmitter extends Renderable {
|
|
|
452
450
|
/**
|
|
453
451
|
* Reset the emitter with default values.<br>
|
|
454
452
|
* @function
|
|
455
|
-
* @param {
|
|
453
|
+
* @param {object} settings [optional] object with emitter settings. See {@link me.ParticleEmitterSettings}
|
|
456
454
|
* @name reset
|
|
457
455
|
* @memberOf me.ParticleEmitter
|
|
458
456
|
*/
|
|
@@ -484,7 +482,7 @@ class ParticleEmitter extends Renderable {
|
|
|
484
482
|
/**
|
|
485
483
|
* Emitter is of type stream and is launching particles <br>
|
|
486
484
|
* @function
|
|
487
|
-
* @returns {
|
|
485
|
+
* @returns {boolean} Emitter is Stream and is launching particles
|
|
488
486
|
* @name isRunning
|
|
489
487
|
* @memberOf me.ParticleEmitter
|
|
490
488
|
*/
|
|
@@ -495,7 +493,7 @@ class ParticleEmitter extends Renderable {
|
|
|
495
493
|
/**
|
|
496
494
|
* Launch particles from emitter constantly <br>
|
|
497
495
|
* Particles example: Fountains
|
|
498
|
-
* @param {
|
|
496
|
+
* @param {number} duration [optional] time that the emitter releases particles in ms
|
|
499
497
|
* @function
|
|
500
498
|
* @name streamParticles
|
|
501
499
|
* @memberOf me.ParticleEmitter
|
|
@@ -520,7 +518,7 @@ class ParticleEmitter extends Renderable {
|
|
|
520
518
|
/**
|
|
521
519
|
* Launch all particles from emitter and stop <br>
|
|
522
520
|
* Particles example: Explosions <br>
|
|
523
|
-
* @param {
|
|
521
|
+
* @param {number} total [optional] number of particles to launch
|
|
524
522
|
* @function
|
|
525
523
|
* @name burstParticles
|
|
526
524
|
* @memberOf me.ParticleEmitter
|
|
@@ -101,7 +101,7 @@ class Particle extends Renderable {
|
|
|
101
101
|
* @memberOf me.Particle
|
|
102
102
|
* @function
|
|
103
103
|
* @ignore
|
|
104
|
-
* @param {
|
|
104
|
+
* @param {number} dt time since the last update in milliseconds
|
|
105
105
|
*/
|
|
106
106
|
update(dt) {
|
|
107
107
|
// move things forward independent of the current frame rate
|
package/src/physics/body.js
CHANGED
|
@@ -16,7 +16,7 @@ import { world } from "./../game.js";
|
|
|
16
16
|
* @memberOf me
|
|
17
17
|
* @constructor
|
|
18
18
|
* @param {me.Renderable} ancestor the parent object this body is attached to
|
|
19
|
-
* @param {me.Rect|me.Rect[]|me.Polygon|me.Polygon[]|me.Line|me.Line[]|me.Ellipse|me.Ellipse[]|me.Bounds|me.Bounds[]|
|
|
19
|
+
* @param {me.Rect|me.Rect[]|me.Polygon|me.Polygon[]|me.Line|me.Line[]|me.Ellipse|me.Ellipse[]|me.Bounds|me.Bounds[]|object} [shapes] a initial shape, list of shapes, or JSON object defining the body
|
|
20
20
|
* @param {Function} [onBodyUpdate] callback for when the body is updated (e.g. add/remove shapes)
|
|
21
21
|
*/
|
|
22
22
|
class Body {
|
|
@@ -27,7 +27,7 @@ class Body {
|
|
|
27
27
|
* a reference to the parent object that contains this body,
|
|
28
28
|
* or undefined if it has not been added to one.
|
|
29
29
|
* @public
|
|
30
|
-
* @type me.Renderable
|
|
30
|
+
* @type {me.Renderable}
|
|
31
31
|
* @default undefined
|
|
32
32
|
* @name me.Body#ancestor
|
|
33
33
|
*/
|
|
@@ -59,7 +59,7 @@ class Body {
|
|
|
59
59
|
* The body collision mask, that defines what should collide with what.<br>
|
|
60
60
|
* (by default will collide with all entities)
|
|
61
61
|
* @ignore
|
|
62
|
-
* @type
|
|
62
|
+
* @type {number}
|
|
63
63
|
* @default me.collision.types.ALL_OBJECT
|
|
64
64
|
* @name collisionMask
|
|
65
65
|
* @see me.collision.types
|
|
@@ -70,7 +70,7 @@ class Body {
|
|
|
70
70
|
/**
|
|
71
71
|
* define the collision type of the body for collision filtering
|
|
72
72
|
* @public
|
|
73
|
-
* @type
|
|
73
|
+
* @type {number}
|
|
74
74
|
* @default me.collision.types.ENEMY_OBJECT
|
|
75
75
|
* @name collisionType
|
|
76
76
|
* @see me.collision.types
|
|
@@ -84,7 +84,7 @@ class Body {
|
|
|
84
84
|
/**
|
|
85
85
|
* body velocity
|
|
86
86
|
* @public
|
|
87
|
-
* @type me.Vector2d
|
|
87
|
+
* @type {me.Vector2d}
|
|
88
88
|
* @default <0,0>
|
|
89
89
|
* @name vel
|
|
90
90
|
* @memberOf me.Body
|
|
@@ -98,7 +98,7 @@ class Body {
|
|
|
98
98
|
* body force or acceleration (automatically) applied to the body.
|
|
99
99
|
* when defining a force, user should also define a max velocity
|
|
100
100
|
* @public
|
|
101
|
-
* @type me.Vector2d
|
|
101
|
+
* @type {me.Vector2d}
|
|
102
102
|
* @default <0,0>
|
|
103
103
|
* @name force
|
|
104
104
|
* @see me.Body.setMaxVelocity
|
|
@@ -129,7 +129,7 @@ class Body {
|
|
|
129
129
|
/**
|
|
130
130
|
* body friction
|
|
131
131
|
* @public
|
|
132
|
-
* @type me.Vector2d
|
|
132
|
+
* @type {me.Vector2d}
|
|
133
133
|
* @default <0,0>
|
|
134
134
|
* @name friction
|
|
135
135
|
* @memberOf me.Body
|
|
@@ -143,7 +143,7 @@ class Body {
|
|
|
143
143
|
* the body bouciness level when colliding with other solid bodies :
|
|
144
144
|
* a value of 0 will not bounce, a value of 1 will fully rebound.
|
|
145
145
|
* @public
|
|
146
|
-
* @type {
|
|
146
|
+
* @type {number}
|
|
147
147
|
* @default 0
|
|
148
148
|
* @name bounce
|
|
149
149
|
* @memberOf me.Body
|
|
@@ -153,7 +153,7 @@ class Body {
|
|
|
153
153
|
/**
|
|
154
154
|
* the body mass
|
|
155
155
|
* @public
|
|
156
|
-
* @type {
|
|
156
|
+
* @type {number}
|
|
157
157
|
* @default 1
|
|
158
158
|
* @name mass
|
|
159
159
|
* @memberOf me.Body
|
|
@@ -163,7 +163,7 @@ class Body {
|
|
|
163
163
|
/**
|
|
164
164
|
* max velocity (to limit body velocity)
|
|
165
165
|
* @public
|
|
166
|
-
* @type me.Vector2d
|
|
166
|
+
* @type {me.Vector2d}
|
|
167
167
|
* @default <490,490>
|
|
168
168
|
* @name maxVel
|
|
169
169
|
* @memberOf me.Body
|
|
@@ -179,7 +179,7 @@ class Body {
|
|
|
179
179
|
* either this body is a static body or not
|
|
180
180
|
* @readonly
|
|
181
181
|
* @public
|
|
182
|
-
* @type
|
|
182
|
+
* @type {boolean}
|
|
183
183
|
* @default false
|
|
184
184
|
* @name isStatic
|
|
185
185
|
* @memberOf me.Body
|
|
@@ -191,7 +191,7 @@ class Body {
|
|
|
191
191
|
* The degree to which this body is affected by the world gravity
|
|
192
192
|
* @public
|
|
193
193
|
* @see me.World.gravity
|
|
194
|
-
* @type
|
|
194
|
+
* @type {number}
|
|
195
195
|
* @default 1.0
|
|
196
196
|
* @name gravityScale
|
|
197
197
|
* @memberOf me.Body
|
|
@@ -202,7 +202,7 @@ class Body {
|
|
|
202
202
|
* If true this body won't be affected by the world gravity
|
|
203
203
|
* @public
|
|
204
204
|
* @see me.World.gravity
|
|
205
|
-
* @type
|
|
205
|
+
* @type {boolean}
|
|
206
206
|
* @default false
|
|
207
207
|
* @name ignoreGravity
|
|
208
208
|
* @memberOf me.Body
|
|
@@ -215,7 +215,7 @@ class Body {
|
|
|
215
215
|
* false if the object is standing on something<br>
|
|
216
216
|
* @readonly
|
|
217
217
|
* @public
|
|
218
|
-
* @type
|
|
218
|
+
* @type {boolean}
|
|
219
219
|
* @default false
|
|
220
220
|
* @name falling
|
|
221
221
|
* @memberOf me.Body
|
|
@@ -227,7 +227,7 @@ class Body {
|
|
|
227
227
|
* equal true if the body is jumping<br>
|
|
228
228
|
* @readonly
|
|
229
229
|
* @public
|
|
230
|
-
* @type
|
|
230
|
+
* @type {boolean}
|
|
231
231
|
* @default false
|
|
232
232
|
* @name jumping
|
|
233
233
|
* @memberOf me.Body
|
|
@@ -263,7 +263,7 @@ class Body {
|
|
|
263
263
|
* @memberOf me.Body
|
|
264
264
|
* @public
|
|
265
265
|
* @function
|
|
266
|
-
* @param {
|
|
266
|
+
* @param {boolean} [isStatic=true]
|
|
267
267
|
*/
|
|
268
268
|
setStatic(isStatic = true) {
|
|
269
269
|
this.isStatic = isStatic === true;
|
|
@@ -276,8 +276,8 @@ class Body {
|
|
|
276
276
|
* @memberOf me.Body
|
|
277
277
|
* @public
|
|
278
278
|
* @function
|
|
279
|
-
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse|me.Bounds|
|
|
280
|
-
* @
|
|
279
|
+
* @param {me.Rect|me.Polygon|me.Line|me.Ellipse|me.Bounds|object} shape a shape or JSON object
|
|
280
|
+
* @returns {number} the shape array length
|
|
281
281
|
* @example
|
|
282
282
|
* // add a rectangle shape
|
|
283
283
|
* this.body.addShape(new me.Rect(0, 0, image.width, image.height));
|
|
@@ -331,7 +331,7 @@ class Body {
|
|
|
331
331
|
* @public
|
|
332
332
|
* @function
|
|
333
333
|
* @param {me.Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
|
|
334
|
-
* @param {
|
|
334
|
+
* @param {number} [index=0] the shape object for which to set the vertices
|
|
335
335
|
* @param {boolean} [clear=true] either to reset the body definition before adding the new vertices
|
|
336
336
|
*/
|
|
337
337
|
setVertices(vertices, index = 0, clear = true) {
|
|
@@ -358,7 +358,7 @@ class Body {
|
|
|
358
358
|
* @public
|
|
359
359
|
* @function
|
|
360
360
|
* @param {me.Vector2d[]} vertices an array of me.Vector2d points defining a convex hull
|
|
361
|
-
* @param {
|
|
361
|
+
* @param {number} [index=0] the shape object for which to set the vertices
|
|
362
362
|
*/
|
|
363
363
|
addVertices(vertices, index = 0) {
|
|
364
364
|
this.setVertices(vertices, index, false);
|
|
@@ -371,10 +371,10 @@ class Body {
|
|
|
371
371
|
* @memberOf me.Body
|
|
372
372
|
* @public
|
|
373
373
|
* @function
|
|
374
|
-
* @param {
|
|
375
|
-
* @param {
|
|
374
|
+
* @param {object} json a JSON object as exported from a Physics Editor tool
|
|
375
|
+
* @param {string} [id] an optional shape identifier within the given the json object
|
|
376
376
|
* @see https://www.codeandweb.com/physicseditor
|
|
377
|
-
* @
|
|
377
|
+
* @returns {number} how many shapes were added to the body
|
|
378
378
|
* @example
|
|
379
379
|
* // define the body based on the banana shape
|
|
380
380
|
* this.body.fromJSON(me.loader.getJSON("shapesdef").banana);
|
|
@@ -415,8 +415,8 @@ class Body {
|
|
|
415
415
|
* @memberOf me.Body
|
|
416
416
|
* @public
|
|
417
417
|
* @function
|
|
418
|
-
* @param {
|
|
419
|
-
* @
|
|
418
|
+
* @param {number} [index=0] the shape object at the specified index
|
|
419
|
+
* @returns {me.Polygon|me.Line|me.Ellipse} shape a shape object if defined
|
|
420
420
|
*/
|
|
421
421
|
getShape(index) {
|
|
422
422
|
return this.shapes[index || 0];
|
|
@@ -427,7 +427,7 @@ class Body {
|
|
|
427
427
|
* @name getBounds
|
|
428
428
|
* @memberOf me.Body
|
|
429
429
|
* @function
|
|
430
|
-
* @
|
|
430
|
+
* @returns {me.Bounds} bounding box Rectangle object
|
|
431
431
|
*/
|
|
432
432
|
getBounds() {
|
|
433
433
|
return this.bounds;
|
|
@@ -440,7 +440,7 @@ class Body {
|
|
|
440
440
|
* @public
|
|
441
441
|
* @function
|
|
442
442
|
* @param {me.Polygon|me.Line|me.Ellipse} shape a shape object
|
|
443
|
-
* @
|
|
443
|
+
* @returns {number} the shape array length
|
|
444
444
|
*/
|
|
445
445
|
removeShape(shape) {
|
|
446
446
|
// clear the current bounds
|
|
@@ -461,8 +461,8 @@ class Body {
|
|
|
461
461
|
* @memberOf me.Body
|
|
462
462
|
* @public
|
|
463
463
|
* @function
|
|
464
|
-
* @param {
|
|
465
|
-
* @
|
|
464
|
+
* @param {number} index the shape object at the specified index
|
|
465
|
+
* @returns {number} the shape array length
|
|
466
466
|
*/
|
|
467
467
|
removeShapeAt(index) {
|
|
468
468
|
return this.removeShape(this.getShape(index));
|
|
@@ -477,7 +477,7 @@ class Body {
|
|
|
477
477
|
* @public
|
|
478
478
|
* @function
|
|
479
479
|
* @see me.collision.types
|
|
480
|
-
* @param {
|
|
480
|
+
* @param {number} [bitmask = me.collision.types.ALL_OBJECT] the collision mask
|
|
481
481
|
* @example
|
|
482
482
|
* // filter collision detection with collision shapes, enemies and collectables
|
|
483
483
|
* myEntity.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
|
|
@@ -496,7 +496,7 @@ class Body {
|
|
|
496
496
|
* @public
|
|
497
497
|
* @function
|
|
498
498
|
* @see me.collision.types
|
|
499
|
-
* @param {
|
|
499
|
+
* @param {number} type the collision type
|
|
500
500
|
* @example
|
|
501
501
|
* // set the body collision type
|
|
502
502
|
* myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
|
|
@@ -558,7 +558,7 @@ class Body {
|
|
|
558
558
|
* @memberOf me.Body.prototype
|
|
559
559
|
* @function
|
|
560
560
|
* @param {Function} callback fnction to execute on each element
|
|
561
|
-
* @param {
|
|
561
|
+
* @param {object} [thisArg] value to use as this(i.e reference Object) when executing callback.
|
|
562
562
|
* @example
|
|
563
563
|
* // iterate through all shapes of the physic body
|
|
564
564
|
* mySprite.body.forEach((shape) => {
|
|
@@ -595,7 +595,7 @@ class Body {
|
|
|
595
595
|
* @memberOf me.Body
|
|
596
596
|
* @function
|
|
597
597
|
* @param {me.Vector2d} point
|
|
598
|
-
* @
|
|
598
|
+
* @returns {boolean} true if contains
|
|
599
599
|
*/
|
|
600
600
|
|
|
601
601
|
/**
|
|
@@ -603,9 +603,9 @@ class Body {
|
|
|
603
603
|
* @name contains
|
|
604
604
|
* @memberOf me.Body
|
|
605
605
|
* @function
|
|
606
|
-
* @param {
|
|
607
|
-
* @param {
|
|
608
|
-
* @
|
|
606
|
+
* @param {number} x x coordinate
|
|
607
|
+
* @param {number} y y coordinate
|
|
608
|
+
* @returns {boolean} true if contains
|
|
609
609
|
*/
|
|
610
610
|
contains() {
|
|
611
611
|
var _x, _y;
|
|
@@ -637,9 +637,9 @@ class Body {
|
|
|
637
637
|
* @name rotate
|
|
638
638
|
* @memberOf me.Body
|
|
639
639
|
* @function
|
|
640
|
-
* @param {
|
|
640
|
+
* @param {number} angle The angle to rotate (in radians)
|
|
641
641
|
* @param {me.Vector2d|me.ObservableVector2d} [v=me.Body.getBounds().center] an optional point to rotate around
|
|
642
|
-
* @
|
|
642
|
+
* @returns {me.Body} Reference to this object for method chaining
|
|
643
643
|
*/
|
|
644
644
|
rotate(angle, v = this.getBounds().center) {
|
|
645
645
|
this.bounds.clear();
|
|
@@ -664,8 +664,8 @@ class Body {
|
|
|
664
664
|
* @name setMaxVelocity
|
|
665
665
|
* @memberOf me.Body
|
|
666
666
|
* @function
|
|
667
|
-
* @param {
|
|
668
|
-
* @param {
|
|
667
|
+
* @param {number} x max velocity on x axis
|
|
668
|
+
* @param {number} y max velocity on y axis
|
|
669
669
|
* @protected
|
|
670
670
|
*/
|
|
671
671
|
setMaxVelocity(x, y) {
|
|
@@ -678,8 +678,8 @@ class Body {
|
|
|
678
678
|
* @name setFriction
|
|
679
679
|
* @memberOf me.Body
|
|
680
680
|
* @function
|
|
681
|
-
* @param {
|
|
682
|
-
* @param {
|
|
681
|
+
* @param {number} x horizontal friction
|
|
682
|
+
* @param {number} y vertical friction
|
|
683
683
|
* @protected
|
|
684
684
|
*/
|
|
685
685
|
setFriction(x = 0, y = 0) {
|
|
@@ -765,8 +765,8 @@ class Body {
|
|
|
765
765
|
* @ignore
|
|
766
766
|
* @memberOf me.Body
|
|
767
767
|
* @function
|
|
768
|
-
* @
|
|
769
|
-
* @
|
|
768
|
+
* @param {number} dt time since the last update in milliseconds.
|
|
769
|
+
* @returns {boolean} true if resulting velocity is different than 0
|
|
770
770
|
*/
|
|
771
771
|
update(dt) {
|
|
772
772
|
// update the velocity
|