melonjs 10.6.1 → 10.8.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/dist/melonjs.js +37947 -36530
- package/dist/melonjs.min.js +22 -22
- package/dist/melonjs.module.d.ts +1352 -307
- package/dist/melonjs.module.js +2929 -1501
- package/package.json +14 -12
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/game.js +5 -5
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +30 -15
- package/src/geometries/roundrect.js +67 -0
- package/src/index.js +9 -5
- package/src/input/gamepad.js +12 -10
- package/src/input/keyboard.js +5 -3
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +3 -4
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +5 -5
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +67 -66
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +130 -430
- package/src/particles/particle.js +53 -53
- package/src/particles/settings.js +310 -0
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- package/src/polyfill/console.js +7 -7
- package/src/polyfill/index.js +7 -0
- package/src/polyfill/performance.js +20 -0
- package/src/polyfill/requestAnimationFrame.js +10 -10
- package/src/renderable/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +8 -8
- package/src/system/device.js +148 -133
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +156 -149
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.js +1 -1
- package/src/utils/agent.js +4 -4
- package/src/utils/function.js +2 -2
- package/src/utils/utils.js +10 -5
- package/src/video/canvas/canvas_renderer.js +104 -36
- package/src/video/renderer.js +28 -16
- package/src/video/texture.js +1 -1
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +30 -194
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +129 -186
- package/src/particles/particlecontainer.js +0 -95
|
@@ -1,103 +1,111 @@
|
|
|
1
|
-
import
|
|
1
|
+
import pool from "./../system/pooling.js";
|
|
2
2
|
import timer from "./../system/timer.js";
|
|
3
3
|
import { randomFloat, clamp } from "./../math/math.js";
|
|
4
4
|
import Renderable from "./../renderable/renderable.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* @classdesc
|
|
9
8
|
* Single Particle Object.
|
|
10
|
-
* @class Particle
|
|
11
9
|
* @augments Renderable
|
|
12
|
-
* @param {ParticleEmitter} particle emitter
|
|
13
10
|
*/
|
|
14
11
|
class Particle extends Renderable {
|
|
15
12
|
/**
|
|
16
|
-
* @
|
|
13
|
+
* @param {ParticleEmitter} emitter the particle emitter
|
|
17
14
|
*/
|
|
18
15
|
constructor(emitter) {
|
|
19
16
|
// Call the super constructor
|
|
20
17
|
super(
|
|
21
18
|
emitter.getRandomPointX(),
|
|
22
19
|
emitter.getRandomPointY(),
|
|
23
|
-
emitter.image.width,
|
|
24
|
-
emitter.image.height
|
|
20
|
+
emitter.settings.image.width,
|
|
21
|
+
emitter.settings.image.height
|
|
25
22
|
);
|
|
26
|
-
|
|
27
|
-
// particle velocity
|
|
28
|
-
this.vel = new Vector2d();
|
|
29
23
|
this.onResetEvent(emitter, true);
|
|
30
24
|
}
|
|
31
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
32
29
|
onResetEvent(emitter, newInstance = false) {
|
|
33
30
|
if (newInstance === false) {
|
|
34
|
-
|
|
31
|
+
this.pos.set(
|
|
35
32
|
emitter.getRandomPointX(),
|
|
36
|
-
emitter.getRandomPointY()
|
|
37
|
-
emitter.image.width,
|
|
38
|
-
emitter.image.height
|
|
33
|
+
emitter.getRandomPointY()
|
|
39
34
|
);
|
|
35
|
+
this.resize(
|
|
36
|
+
emitter.settings.image.width,
|
|
37
|
+
emitter.settings.image.height
|
|
38
|
+
);
|
|
39
|
+
this.currentTransform.identity();
|
|
40
|
+
} else {
|
|
41
|
+
// particle velocity
|
|
42
|
+
this.vel = pool.pull("Vector2d");
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
this.image = emitter.settings.image;
|
|
46
|
+
|
|
42
47
|
// Particle will always update
|
|
43
48
|
this.alwaysUpdate = true;
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
if (typeof emitter.settings.tint === "string") {
|
|
51
|
+
this.tint.parseCSS(emitter.settings.tint);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (emitter.settings.textureAdditive === true) {
|
|
55
|
+
this.blendMode = "additive";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (emitter.settings.blendMode !== "normal") {
|
|
59
|
+
this.blendMode = emitter.settings.blendMode;
|
|
60
|
+
}
|
|
47
61
|
|
|
48
62
|
// Set the start particle Angle and Speed as defined in emitter
|
|
49
|
-
var angle = emitter.angle + ((emitter.angleVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.angleVariation : 0);
|
|
50
|
-
var speed = emitter.speed + ((emitter.speedVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.speedVariation : 0);
|
|
63
|
+
var angle = emitter.settings.angle + ((emitter.settings.angleVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.settings.angleVariation : 0);
|
|
64
|
+
var speed = emitter.settings.speed + ((emitter.settings.speedVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.settings.speedVariation : 0);
|
|
51
65
|
|
|
52
66
|
// Set the start particle Velocity
|
|
53
67
|
this.vel.set(speed * Math.cos(angle), -speed * Math.sin(angle));
|
|
54
68
|
|
|
55
69
|
// Set the start particle Time of Life as defined in emitter
|
|
56
|
-
this.life = randomFloat(emitter.minLife, emitter.maxLife);
|
|
70
|
+
this.life = randomFloat(emitter.settings.minLife, emitter.settings.maxLife);
|
|
57
71
|
this.startLife = this.life;
|
|
58
72
|
|
|
59
73
|
// Set the start and end particle Scale as defined in emitter
|
|
60
74
|
// clamp the values as minimum and maximum scales range
|
|
61
75
|
this.startScale = clamp(
|
|
62
|
-
randomFloat(emitter.minStartScale, emitter.maxStartScale),
|
|
63
|
-
emitter.minStartScale,
|
|
64
|
-
emitter.maxStartScale
|
|
76
|
+
randomFloat(emitter.settings.minStartScale, emitter.settings.maxStartScale),
|
|
77
|
+
emitter.settings.minStartScale,
|
|
78
|
+
emitter.settings.maxStartScale
|
|
65
79
|
);
|
|
66
80
|
this.endScale = clamp(
|
|
67
|
-
randomFloat(emitter.minEndScale, emitter.maxEndScale),
|
|
68
|
-
emitter.minEndScale,
|
|
69
|
-
emitter.maxEndScale
|
|
81
|
+
randomFloat(emitter.settings.minEndScale, emitter.settings.maxEndScale),
|
|
82
|
+
emitter.settings.minEndScale,
|
|
83
|
+
emitter.settings.maxEndScale
|
|
70
84
|
);
|
|
71
85
|
|
|
72
86
|
// Set the particle Gravity and Wind (horizontal gravity) as defined in emitter
|
|
73
|
-
this.gravity = emitter.gravity;
|
|
74
|
-
this.wind = emitter.wind;
|
|
87
|
+
this.gravity = emitter.settings.gravity;
|
|
88
|
+
this.wind = emitter.settings.wind;
|
|
75
89
|
|
|
76
90
|
// Set if the particle update the rotation in accordance the trajectory
|
|
77
|
-
this.followTrajectory = emitter.followTrajectory;
|
|
91
|
+
this.followTrajectory = emitter.settings.followTrajectory;
|
|
78
92
|
|
|
79
93
|
// Set if the particle update only in Viewport
|
|
80
|
-
this.onlyInViewport = emitter.onlyInViewport;
|
|
81
|
-
|
|
82
|
-
// Set the particle Z Order
|
|
83
|
-
this.pos.z = emitter.z;
|
|
94
|
+
this.onlyInViewport = emitter.settings.onlyInViewport;
|
|
84
95
|
|
|
85
96
|
// cache inverse of the expected delta time
|
|
86
97
|
this._deltaInv = timer.maxfps / 1000;
|
|
87
98
|
|
|
88
99
|
// Set the start particle rotation as defined in emitter
|
|
89
100
|
// if the particle not follow trajectory
|
|
90
|
-
if (!emitter.followTrajectory) {
|
|
91
|
-
this.angle = randomFloat(emitter.minRotation, emitter.maxRotation);
|
|
101
|
+
if (!emitter.settings.followTrajectory) {
|
|
102
|
+
this.angle = randomFloat(emitter.settings.minRotation, emitter.settings.maxRotation);
|
|
92
103
|
}
|
|
93
104
|
}
|
|
94
105
|
|
|
95
106
|
/**
|
|
96
107
|
* Update the Particle <br>
|
|
97
108
|
* This is automatically called by the game manager {@link game}
|
|
98
|
-
* @name update
|
|
99
|
-
* @memberof Particle
|
|
100
|
-
* @function
|
|
101
109
|
* @ignore
|
|
102
110
|
* @param {number} dt time since the last update in milliseconds
|
|
103
111
|
*/
|
|
@@ -108,6 +116,11 @@ class Particle extends Renderable {
|
|
|
108
116
|
// Decrease particle life
|
|
109
117
|
this.life = this.life > dt ? this.life - dt : 0;
|
|
110
118
|
|
|
119
|
+
if (this.life <= 0) {
|
|
120
|
+
this.ancestor.removeChild(this);
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
111
124
|
// Calculate the particle Age Ratio
|
|
112
125
|
var ageRatio = this.life / this.startLife;
|
|
113
126
|
|
|
@@ -142,23 +155,10 @@ class Particle extends Renderable {
|
|
|
142
155
|
this.pos.x, this.pos.y, 1
|
|
143
156
|
).rotate(angle);
|
|
144
157
|
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* @ignore
|
|
151
|
-
*/
|
|
152
|
-
preDraw(renderer) {
|
|
153
|
-
|
|
154
|
-
// restore is called in postDraw
|
|
155
|
-
renderer.save();
|
|
156
|
-
|
|
157
|
-
// particle alpha value
|
|
158
|
-
renderer.setGlobalAlpha(renderer.globalAlpha() * this.alpha);
|
|
158
|
+
// mark as dirty if the particle is not dead yet
|
|
159
|
+
this.isDirty = this.inViewport || !this.onlyInViewport;
|
|
159
160
|
|
|
160
|
-
|
|
161
|
-
renderer.transform(this.currentTransform);
|
|
161
|
+
return super.update(dt);
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
/**
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ParticleEmitterSettings contains the default settings for ParticleEmitter
|
|
3
|
+
* @see ParticleEmitter
|
|
4
|
+
* @namespace ParticleEmitterSettings
|
|
5
|
+
*/
|
|
6
|
+
const ParticleEmitterSettings = {
|
|
7
|
+
/**
|
|
8
|
+
* Width of the particle spawn area.
|
|
9
|
+
* @type {number}
|
|
10
|
+
* @name width
|
|
11
|
+
* @memberof ParticleEmitterSettings
|
|
12
|
+
* @default 1
|
|
13
|
+
*/
|
|
14
|
+
width : 1,
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Height of the particle spawn area
|
|
18
|
+
* @public
|
|
19
|
+
* @type {number}
|
|
20
|
+
* @name height
|
|
21
|
+
* @memberof ParticleEmitterSettings
|
|
22
|
+
* @default 1
|
|
23
|
+
*/
|
|
24
|
+
height : 1,
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* image used for particles texture
|
|
28
|
+
* (by default melonJS will create an white 8x8 texture image)
|
|
29
|
+
* @public
|
|
30
|
+
* @type {HTMLCanvasElement}
|
|
31
|
+
* @name image
|
|
32
|
+
* @memberof ParticleEmitterSettings
|
|
33
|
+
* @default undefined
|
|
34
|
+
* @see ParticleEmitterSettings.textureSize
|
|
35
|
+
*/
|
|
36
|
+
image : undefined,
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* default texture size used for particles if no image is specified
|
|
40
|
+
* (by default melonJS will create an white 8x8 texture image)
|
|
41
|
+
* @public
|
|
42
|
+
* @type {number}
|
|
43
|
+
* @name textureSize
|
|
44
|
+
* @memberof ParticleEmitterSettings
|
|
45
|
+
* @default 8
|
|
46
|
+
* @see ParticleEmitterSettings.image
|
|
47
|
+
*/
|
|
48
|
+
textureSize : 8,
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* tint to be applied to particles
|
|
52
|
+
* @public
|
|
53
|
+
* @type {string}
|
|
54
|
+
* @name tint
|
|
55
|
+
* @memberof ParticleEmitterSettings
|
|
56
|
+
* @default "#fff"
|
|
57
|
+
*/
|
|
58
|
+
tint : "#fff",
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Total number of particles in the emitter
|
|
62
|
+
* @public
|
|
63
|
+
* @type {number}
|
|
64
|
+
* @name totalParticles
|
|
65
|
+
* @default 50
|
|
66
|
+
* @memberof ParticleEmitterSettings
|
|
67
|
+
*/
|
|
68
|
+
totalParticles : 50,
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Start angle for particle launch in Radians
|
|
72
|
+
* @public
|
|
73
|
+
* @type {number}
|
|
74
|
+
* @name angle
|
|
75
|
+
* @default Math.PI / 2
|
|
76
|
+
* @memberof ParticleEmitterSettings
|
|
77
|
+
*/
|
|
78
|
+
angle : Math.PI / 2,
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Variation in the start angle for particle launch in Radians.
|
|
82
|
+
* @public
|
|
83
|
+
* @type {number}
|
|
84
|
+
* @name angleVariation
|
|
85
|
+
* @default 0
|
|
86
|
+
* @memberof ParticleEmitterSettings
|
|
87
|
+
*/
|
|
88
|
+
angleVariation : 0,
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Minimum time each particle lives once it is emitted in ms.
|
|
92
|
+
* @public
|
|
93
|
+
* @type {number}
|
|
94
|
+
* @name minLife
|
|
95
|
+
* @default 1000
|
|
96
|
+
* @memberof ParticleEmitterSettings
|
|
97
|
+
*/
|
|
98
|
+
minLife : 1000,
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Maximum time each particle lives once it is emitted in ms.
|
|
102
|
+
* @public
|
|
103
|
+
* @type {number}
|
|
104
|
+
* @name maxLife
|
|
105
|
+
* @default 3000
|
|
106
|
+
* @memberof ParticleEmitterSettings
|
|
107
|
+
*/
|
|
108
|
+
maxLife : 3000,
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Start speed of particles.<br>
|
|
112
|
+
* @public
|
|
113
|
+
* @type {number}
|
|
114
|
+
* @name speed
|
|
115
|
+
* @default 2
|
|
116
|
+
* @memberof ParticleEmitterSettings
|
|
117
|
+
*/
|
|
118
|
+
speed : 2,
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Variation in the start speed of particles
|
|
122
|
+
* @public
|
|
123
|
+
* @type {number}
|
|
124
|
+
* @name speedVariation
|
|
125
|
+
* @default 1
|
|
126
|
+
* @memberof ParticleEmitterSettings
|
|
127
|
+
*/
|
|
128
|
+
speedVariation : 1,
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Minimum start rotation for particles sprites in Radians
|
|
132
|
+
* @public
|
|
133
|
+
* @type {number}
|
|
134
|
+
* @name minRotation
|
|
135
|
+
* @default 0
|
|
136
|
+
* @memberof ParticleEmitterSettings
|
|
137
|
+
*/
|
|
138
|
+
minRotation : 0,
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Maximum start rotation for particles sprites in Radians
|
|
142
|
+
* @public
|
|
143
|
+
* @type {number}
|
|
144
|
+
* @name maxRotation
|
|
145
|
+
* @default 0
|
|
146
|
+
* @memberof ParticleEmitterSettings
|
|
147
|
+
*/
|
|
148
|
+
maxRotation : 0,
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Minimum start scale ratio for particles (1 = no scaling)
|
|
152
|
+
* @public
|
|
153
|
+
* @type {number}
|
|
154
|
+
* @name minStartScale
|
|
155
|
+
* @default 1
|
|
156
|
+
* @memberof ParticleEmitterSettings
|
|
157
|
+
*/
|
|
158
|
+
minStartScale : 1,
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Maximum start scale ratio for particles (1 = no scaling)
|
|
162
|
+
* @public
|
|
163
|
+
* @type {number}
|
|
164
|
+
* @name maxStartScale
|
|
165
|
+
* @default 1
|
|
166
|
+
* @memberof ParticleEmitterSettings
|
|
167
|
+
*/
|
|
168
|
+
maxStartScale : 1,
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Minimum end scale ratio for particles
|
|
172
|
+
* @public
|
|
173
|
+
* @type {number}
|
|
174
|
+
* @name minEndScale
|
|
175
|
+
* @default 0
|
|
176
|
+
* @memberof ParticleEmitterSettings
|
|
177
|
+
*/
|
|
178
|
+
minEndScale : 0,
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Maximum end scale ratio for particles
|
|
182
|
+
* @public
|
|
183
|
+
* @type {number}
|
|
184
|
+
* @name maxEndScale
|
|
185
|
+
* @default 0
|
|
186
|
+
* @memberof ParticleEmitterSettings
|
|
187
|
+
*/
|
|
188
|
+
maxEndScale : 0,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Vertical force (Gravity) for each particle
|
|
192
|
+
* @public
|
|
193
|
+
* @type {number}
|
|
194
|
+
* @name gravity
|
|
195
|
+
* @default 0
|
|
196
|
+
* @memberof ParticleEmitterSettings
|
|
197
|
+
* @see game.world.gravity
|
|
198
|
+
*/
|
|
199
|
+
gravity : 0,
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Horizontal force (like a Wind) for each particle
|
|
203
|
+
* @public
|
|
204
|
+
* @type {number}
|
|
205
|
+
* @name wind
|
|
206
|
+
* @default 0
|
|
207
|
+
* @memberof ParticleEmitterSettings
|
|
208
|
+
*/
|
|
209
|
+
wind : 0,
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Update the rotation of particle in accordance the particle trajectory.<br>
|
|
213
|
+
* The particle sprite should aim at zero angle (draw from left to right).<br>
|
|
214
|
+
* Override the particle minRotation and maxRotation.<br>
|
|
215
|
+
* @public
|
|
216
|
+
* @type {boolean}
|
|
217
|
+
* @name followTrajectory
|
|
218
|
+
* @default false
|
|
219
|
+
* @memberof ParticleEmitterSettings
|
|
220
|
+
*/
|
|
221
|
+
followTrajectory : false,
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Enable the Texture Additive by composite operation ("additive" blendMode)
|
|
225
|
+
* @public
|
|
226
|
+
* @type {boolean}
|
|
227
|
+
* @name textureAdditive
|
|
228
|
+
* @default false
|
|
229
|
+
* @memberof ParticleEmitterSettings
|
|
230
|
+
* @see ParticleEmitterSettings.blendMode
|
|
231
|
+
*/
|
|
232
|
+
textureAdditive : false,
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* the blend mode to be applied when rendering particles.
|
|
236
|
+
* (note: this will superseed the `textureAdditive` setting if different than "normal")
|
|
237
|
+
* @public
|
|
238
|
+
* @type {string}
|
|
239
|
+
* @name blendMode
|
|
240
|
+
* @default normal
|
|
241
|
+
* @memberof ParticleEmitterSettings
|
|
242
|
+
* @see CanvasRenderer#setBlendMode
|
|
243
|
+
* @see WebGLRenderer#setBlendMode
|
|
244
|
+
*/
|
|
245
|
+
blendMode : "normal",
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Update particles only in the viewport, remove it when out of viewport.
|
|
249
|
+
* @public
|
|
250
|
+
* @type {boolean}
|
|
251
|
+
* @name onlyInViewport
|
|
252
|
+
* @default true
|
|
253
|
+
* @memberof ParticleEmitterSettings
|
|
254
|
+
*/
|
|
255
|
+
onlyInViewport : true,
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Render particles in screen space.
|
|
259
|
+
* @public
|
|
260
|
+
* @type {boolean}
|
|
261
|
+
* @name floating
|
|
262
|
+
* @default false
|
|
263
|
+
* @memberof ParticleEmitterSettings
|
|
264
|
+
*/
|
|
265
|
+
floating : false,
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Maximum number of particles launched each time in this emitter (used only if emitter is Stream).
|
|
269
|
+
* @public
|
|
270
|
+
* @type {number}
|
|
271
|
+
* @name maxParticles
|
|
272
|
+
* @default 10
|
|
273
|
+
* @memberof ParticleEmitterSettings
|
|
274
|
+
*/
|
|
275
|
+
maxParticles : 10,
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* How often a particle is emitted in ms (used only if emitter is a Stream).
|
|
279
|
+
* @public
|
|
280
|
+
* @type {number}
|
|
281
|
+
* @name frequency
|
|
282
|
+
* @default 100
|
|
283
|
+
* @memberof ParticleEmitterSettings
|
|
284
|
+
*/
|
|
285
|
+
frequency : 100,
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Duration that the emitter releases particles in ms (used only if emitter is Stream).
|
|
289
|
+
* After this period, the emitter stop the launch of particles.
|
|
290
|
+
* @public
|
|
291
|
+
* @type {number}
|
|
292
|
+
* @name duration
|
|
293
|
+
* @default Infinity
|
|
294
|
+
* @memberof ParticleEmitterSettings
|
|
295
|
+
*/
|
|
296
|
+
duration : Infinity,
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Skip n frames after updating the particle system once.
|
|
300
|
+
* This can be used to reduce the performance impact of emitters with many particles.
|
|
301
|
+
* @public
|
|
302
|
+
* @type {number}
|
|
303
|
+
* @name framesToSkip
|
|
304
|
+
* @default 0
|
|
305
|
+
* @memberof ParticleEmitterSettings
|
|
306
|
+
*/
|
|
307
|
+
framesToSkip : 0
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
export default ParticleEmitterSettings;
|
package/src/physics/body.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Vector2d from "./../math/vector2.js";
|
|
2
1
|
import Rect from "./../geometries/rectangle.js";
|
|
3
2
|
import Ellipse from "./../geometries/ellipse.js";
|
|
4
3
|
import Polygon from "./../geometries/poly.js";
|
|
5
4
|
import Bounds from "./bounds.js";
|
|
5
|
+
import pool from "./../system/pooling.js";
|
|
6
6
|
import collision from "./collision.js";
|
|
7
7
|
import * as arrayUtil from "./../utils/array.js";
|
|
8
8
|
import timer from "./../system/timer.js";
|
|
@@ -37,7 +37,7 @@ class Body {
|
|
|
37
37
|
* @public
|
|
38
38
|
* @type {Bounds}
|
|
39
39
|
*/
|
|
40
|
-
this.bounds =
|
|
40
|
+
this.bounds = pool.pull("Bounds");
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (typeof this.shapes === "undefined") {
|
|
@@ -71,55 +71,54 @@ class Body {
|
|
|
71
71
|
*/
|
|
72
72
|
this.collisionType = collision.types.ENEMY_OBJECT;
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* body velocity
|
|
76
|
-
* @public
|
|
77
|
-
* @type {Vector2d}
|
|
78
|
-
* @default <0,0>
|
|
79
|
-
*/
|
|
80
74
|
if (typeof this.vel === "undefined") {
|
|
81
|
-
|
|
75
|
+
/**
|
|
76
|
+
* body velocity
|
|
77
|
+
* @public
|
|
78
|
+
* @type {Vector2d}
|
|
79
|
+
* @default <0,0>
|
|
80
|
+
*/
|
|
81
|
+
this.vel = pool.pull("Vector2d");
|
|
82
82
|
}
|
|
83
83
|
this.vel.set(0, 0);
|
|
84
84
|
|
|
85
|
-
/**
|
|
86
|
-
* body force or acceleration (automatically) applied to the body.
|
|
87
|
-
* when defining a force, user should also define a max velocity
|
|
88
|
-
* @public
|
|
89
|
-
* @type {Vector2d}
|
|
90
|
-
* @default <0,0>
|
|
91
|
-
* @see Body.setMaxVelocity
|
|
92
|
-
* @example
|
|
93
|
-
* // define a default maximum acceleration, initial force and friction
|
|
94
|
-
* this.body.force.set(0, 0);
|
|
95
|
-
* this.body.friction.set(0.4, 0);
|
|
96
|
-
* this.body.setMaxVelocity(3, 15);
|
|
97
|
-
*
|
|
98
|
-
* // apply a postive or negative force when pressing left of right key
|
|
99
|
-
* update(dt) {
|
|
100
|
-
* if (me.input.isKeyPressed("left")) {
|
|
101
|
-
* this.body.force.x = -this.body.maxVel.x;
|
|
102
|
-
* } else if (me.input.isKeyPressed("right")) {
|
|
103
|
-
* this.body.force.x = this.body.maxVel.x;
|
|
104
|
-
* } else {
|
|
105
|
-
* this.body.force.x = 0;
|
|
106
|
-
* }
|
|
107
|
-
* }
|
|
108
|
-
*/
|
|
109
85
|
if (typeof this.force === "undefined") {
|
|
110
|
-
|
|
86
|
+
/**
|
|
87
|
+
* body force or acceleration (automatically) applied to the body.
|
|
88
|
+
* when defining a force, user should also define a max velocity
|
|
89
|
+
* @public
|
|
90
|
+
* @type {Vector2d}
|
|
91
|
+
* @default <0,0>
|
|
92
|
+
* @see Body.setMaxVelocity
|
|
93
|
+
* @example
|
|
94
|
+
* // define a default maximum acceleration, initial force and friction
|
|
95
|
+
* this.body.force.set(0, 0);
|
|
96
|
+
* this.body.friction.set(0.4, 0);
|
|
97
|
+
* this.body.setMaxVelocity(3, 15);
|
|
98
|
+
*
|
|
99
|
+
* // apply a postive or negative force when pressing left of right key
|
|
100
|
+
* update(dt) {
|
|
101
|
+
* if (me.input.isKeyPressed("left")) {
|
|
102
|
+
* this.body.force.x = -this.body.maxVel.x;
|
|
103
|
+
* } else if (me.input.isKeyPressed("right")) {
|
|
104
|
+
* this.body.force.x = this.body.maxVel.x;
|
|
105
|
+
* } else {
|
|
106
|
+
* this.body.force.x = 0;
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
*/
|
|
110
|
+
this.force = pool.pull("Vector2d");
|
|
111
111
|
}
|
|
112
112
|
this.force.set(0, 0);
|
|
113
113
|
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* body friction
|
|
117
|
-
* @public
|
|
118
|
-
* @type {Vector2d}
|
|
119
|
-
* @default <0,0>
|
|
120
|
-
*/
|
|
121
114
|
if (typeof this.friction === "undefined") {
|
|
122
|
-
|
|
115
|
+
/**
|
|
116
|
+
* body friction
|
|
117
|
+
* @public
|
|
118
|
+
* @type {Vector2d}
|
|
119
|
+
* @default <0,0>
|
|
120
|
+
*/
|
|
121
|
+
this.friction = pool.pull("Vector2d");
|
|
123
122
|
}
|
|
124
123
|
this.friction.set(0, 0);
|
|
125
124
|
|
|
@@ -140,14 +139,14 @@ class Body {
|
|
|
140
139
|
*/
|
|
141
140
|
this.mass = 1;
|
|
142
141
|
|
|
143
|
-
/**
|
|
144
|
-
* max velocity (to limit body velocity)
|
|
145
|
-
* @public
|
|
146
|
-
* @type {Vector2d}
|
|
147
|
-
* @default <490,490>
|
|
148
|
-
*/
|
|
149
142
|
if (typeof this.maxVel === "undefined") {
|
|
150
|
-
|
|
143
|
+
/**
|
|
144
|
+
* max velocity (to limit body velocity)
|
|
145
|
+
* @public
|
|
146
|
+
* @type {Vector2d}
|
|
147
|
+
* @default <490,490>
|
|
148
|
+
*/
|
|
149
|
+
this.maxVel = pool.pull("Vector2d");
|
|
151
150
|
}
|
|
152
151
|
// cap by default to half the default gravity force
|
|
153
152
|
this.maxVel.set(490, 490);
|
|
@@ -297,7 +296,7 @@ class Body {
|
|
|
297
296
|
polygon.setShape(0, 0, vertices);
|
|
298
297
|
} else {
|
|
299
298
|
// this will replace any other non polygon shape type if defined
|
|
300
|
-
this.shapes[index] =
|
|
299
|
+
this.shapes[index] = pool.pull("Polygon", 0, 0, vertices);
|
|
301
300
|
}
|
|
302
301
|
|
|
303
302
|
// update the body bounds to take in account the new vertices
|
|
@@ -686,11 +685,28 @@ class Body {
|
|
|
686
685
|
* @ignore
|
|
687
686
|
*/
|
|
688
687
|
destroy() {
|
|
688
|
+
// push back instance into object pool
|
|
689
|
+
pool.push(this.bounds);
|
|
690
|
+
pool.push(this.vel);
|
|
691
|
+
pool.push(this.force);
|
|
692
|
+
pool.push(this.friction);
|
|
693
|
+
pool.push(this.maxVel);
|
|
694
|
+
this.shapes.forEach((shape) => {
|
|
695
|
+
pool.push(shape);
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
// set to undefined
|
|
689
699
|
this.onBodyUpdate = undefined;
|
|
690
700
|
this.ancestor = undefined;
|
|
691
701
|
this.bounds = undefined;
|
|
692
|
-
this.
|
|
702
|
+
this.vel = undefined;
|
|
703
|
+
this.force = undefined;
|
|
704
|
+
this.friction = undefined;
|
|
705
|
+
this.maxVel = undefined;
|
|
693
706
|
this.shapes.length = 0;
|
|
707
|
+
|
|
708
|
+
// reset some variable to default
|
|
709
|
+
this.setStatic(false);
|
|
694
710
|
}
|
|
695
711
|
};
|
|
696
712
|
|