melonjs 10.5.2 → 10.7.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.
Files changed (67) hide show
  1. package/README.md +4 -6
  2. package/dist/melonjs.js +37470 -36394
  3. package/dist/melonjs.min.js +22 -22
  4. package/dist/melonjs.module.d.ts +606 -426
  5. package/dist/melonjs.module.js +8114 -7033
  6. package/package.json +15 -13
  7. package/src/camera/camera2d.js +11 -10
  8. package/src/game.js +5 -5
  9. package/src/geometries/ellipse.js +1 -1
  10. package/src/geometries/poly.js +1 -1
  11. package/src/geometries/rectangle.js +15 -0
  12. package/src/index.js +5 -5
  13. package/src/input/gamepad.js +12 -10
  14. package/src/input/keyboard.js +5 -3
  15. package/src/input/pointer.js +1 -1
  16. package/src/input/pointerevent.js +3 -4
  17. package/src/level/tiled/TMXLayer.js +1 -1
  18. package/src/level/tiled/TMXTileMap.js +1 -1
  19. package/src/level/tiled/TMXUtils.js +1 -1
  20. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  21. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  22. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  23. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  24. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  25. package/src/loader/loader.js +1 -1
  26. package/src/loader/loadingscreen.js +1 -1
  27. package/src/math/color.js +1 -1
  28. package/src/math/matrix2.js +2 -2
  29. package/src/math/matrix3.js +67 -66
  30. package/src/math/observable_vector2.js +1 -1
  31. package/src/math/observable_vector3.js +1 -1
  32. package/src/math/vector2.js +1 -1
  33. package/src/math/vector3.js +1 -1
  34. package/src/particles/emitter.js +120 -429
  35. package/src/particles/particle.js +51 -52
  36. package/src/particles/settings.js +310 -0
  37. package/src/physics/body.js +7 -7
  38. package/src/polyfill/console.js +7 -7
  39. package/src/polyfill/index.js +7 -0
  40. package/src/polyfill/performance.js +20 -0
  41. package/src/polyfill/requestAnimationFrame.js +10 -10
  42. package/src/renderable/colorlayer.js +1 -1
  43. package/src/renderable/container.js +11 -1
  44. package/src/renderable/imagelayer.js +3 -3
  45. package/src/renderable/nineslicesprite.js +6 -3
  46. package/src/renderable/renderable.js +18 -1
  47. package/src/renderable/sprite.js +2 -2
  48. package/src/state/state.js +13 -13
  49. package/src/system/device.js +141 -128
  50. package/src/system/event.js +10 -10
  51. package/src/system/pooling.js +150 -155
  52. package/src/system/timer.js +1 -1
  53. package/src/text/bitmaptext.js +35 -91
  54. package/src/text/text.js +82 -145
  55. package/src/text/textmetrics.js +168 -0
  56. package/src/text/textstyle.js +14 -0
  57. package/src/utils/agent.js +4 -4
  58. package/src/utils/function.js +2 -2
  59. package/src/utils/utils.js +10 -5
  60. package/src/video/canvas/canvas_renderer.js +34 -4
  61. package/src/video/renderer.js +3 -5
  62. package/src/video/texture.js +1 -1
  63. package/src/video/video.js +11 -11
  64. package/src/video/webgl/buffer/vertex.js +0 -3
  65. package/src/video/webgl/glshader.js +1 -3
  66. package/src/video/webgl/webgl_renderer.js +50 -22
  67. package/src/particles/particlecontainer.js +0 -95
@@ -17,6 +17,7 @@ export class BitmapText extends Renderable {
17
17
  * @param {string} [settings.textBaseline="top"] the text baseline
18
18
  * @param {number} [settings.lineHeight=1.0] line spacing height
19
19
  * @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] anchor point to draw the text at
20
+ * @param {number} [settings.wordWrapWidth] the maximum length in CSS pixel for a single segment of text
20
21
  * @param {(string|string[])} [settings.text] a string, or an array of strings
21
22
  * @example
22
23
  * // Use me.loader.preload or me.loader.load to load assets
@@ -42,6 +43,7 @@ export class BitmapText extends Renderable {
42
43
  textBaseline?: string;
43
44
  lineHeight?: number;
44
45
  anchorPoint?: Vector2d;
46
+ wordWrapWidth?: number;
45
47
  text?: (string | string[]);
46
48
  });
47
49
  /**
@@ -50,8 +52,6 @@ export class BitmapText extends Renderable {
50
52
  * @public
51
53
  * @type {string}
52
54
  * @default "left"
53
- * @name textAlign
54
- * @memberof BitmapText
55
55
  */
56
56
  public textAlign: string;
57
57
  /**
@@ -60,8 +60,6 @@ export class BitmapText extends Renderable {
60
60
  * @public
61
61
  * @type {string}
62
62
  * @default "top"
63
- * @name textBaseline
64
- * @memberof BitmapText
65
63
  */
66
64
  public textBaseline: string;
67
65
  /**
@@ -70,10 +68,16 @@ export class BitmapText extends Renderable {
70
68
  * @public
71
69
  * @type {number}
72
70
  * @default 1.0
73
- * @name lineHeight
74
- * @memberof BitmapText
75
71
  */
76
72
  public lineHeight: number;
73
+ /**
74
+ * the maximum length in CSS pixel for a single segment of text.
75
+ * (use -1 to disable word wrapping)
76
+ * @public
77
+ * @type {number}
78
+ * @default -1
79
+ */
80
+ public wordWrapWidth: number;
77
81
  /**
78
82
  * the text to be displayed
79
83
  * @private
@@ -94,11 +98,9 @@ export class BitmapText extends Renderable {
94
98
  * @private
95
99
  */
96
100
  private fontData;
101
+ metrics: TextMetrics;
97
102
  /**
98
103
  * change the font settings
99
- * @name set
100
- * @memberof BitmapText.prototype
101
- * @function
102
104
  * @param {string} textAlign ("left", "center", "right")
103
105
  * @param {number} [scale]
104
106
  * @returns {BitmapText} this object for chaining
@@ -106,51 +108,32 @@ export class BitmapText extends Renderable {
106
108
  set(textAlign: string, scale?: number): BitmapText;
107
109
  /**
108
110
  * change the text to be displayed
109
- * @name setText
110
- * @memberof BitmapText.prototype
111
- * @function
112
111
  * @param {number|string|string[]} value a string, or an array of strings
113
112
  * @returns {BitmapText} this object for chaining
114
113
  */
115
- setText(value: number | string | string[]): BitmapText;
114
+ setText(value?: number | string | string[]): BitmapText;
116
115
  public set fillStyle(arg: Color);
117
116
  /**
118
117
  * defines the color used to tint the bitmap text
119
118
  * @public
120
119
  * @type {Color}
121
- * @name fillStyle
122
120
  * @see Renderable#tint
123
- * @memberof BitmapText
124
121
  */
125
122
  public get fillStyle(): Color;
126
123
  /**
127
124
  * change the font display size
128
- * @name resize
129
- * @memberof BitmapText.prototype
130
- * @function
131
125
  * @param {number} scale ratio
132
126
  * @returns {BitmapText} this object for chaining
133
127
  */
134
128
  resize(scale: number): BitmapText;
135
129
  /**
136
130
  * measure the given text size in pixels
137
- * @name measureText
138
- * @memberof BitmapText.prototype
139
- * @function
140
131
  * @param {string} [text]
141
- * @param {Rect} [ret] a object in which to store the text metrics
142
132
  * @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
143
133
  */
144
- measureText(text?: string, ret?: Rect): TextMetrics;
145
- /**
146
- * @ignore
147
- */
148
- update(): boolean;
134
+ measureText(text?: string): TextMetrics;
149
135
  /**
150
136
  * draw the bitmap font
151
- * @name draw
152
- * @memberof BitmapText.prototype
153
- * @function
154
137
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
155
138
  * @param {string} [text]
156
139
  * @param {number} [x]
@@ -247,7 +230,7 @@ export class Body {
247
230
  * @see collision.types
248
231
  * @example
249
232
  * // set the body collision type
250
- * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
233
+ * body.collisionType = me.collision.types.PLAYER_OBJECT;
251
234
  */
252
235
  public collisionType: number;
253
236
  vel: Vector2d;
@@ -384,17 +367,17 @@ export class Body {
384
367
  */
385
368
  removeShapeAt(index: number): number;
386
369
  /**
387
- * By default all entities are able to collide with all other entities, <br>
370
+ * By default all physic bodies are able to collide with all other bodies, <br>
388
371
  * but it's also possible to specify 'collision filters' to provide a finer <br>
389
- * control over which entities can collide with each other.
372
+ * control over which body can collide with each other.
390
373
  * @see collision.types
391
374
  * @param {number} [bitmask = collision.types.ALL_OBJECT] the collision mask
392
375
  * @example
393
376
  * // filter collision detection with collision shapes, enemies and collectables
394
- * myEntity.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
377
+ * body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
395
378
  * ...
396
379
  * // disable collision detection with all other objects
397
- * myEntity.body.setCollisionMask(me.collision.types.NO_OBJECT);
380
+ * body.setCollisionMask(me.collision.types.NO_OBJECT);
398
381
  */
399
382
  setCollisionMask(bitmask?: number): void;
400
383
  /**
@@ -403,7 +386,7 @@ export class Body {
403
386
  * @param {number} type the collision type
404
387
  * @example
405
388
  * // set the body collision type
406
- * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
389
+ * body.collisionType = me.collision.types.PLAYER_OBJECT;
407
390
  */
408
391
  setCollisionType(type: number): void;
409
392
  /**
@@ -472,7 +455,7 @@ export class Body {
472
455
  * Updates the parent's position as well as computes the new body's velocity based
473
456
  * on the values of force/friction/gravity. Velocity chages are proportional to the
474
457
  * me.timer.tick value (which can be used to scale velocities). The approach to moving the
475
- * parent Entity is to compute new values of the Body.vel property then add them to
458
+ * parent renderable is to compute new values of the Body.vel property then add them to
476
459
  * the parent.pos value thus changing the postion the amount of Body.vel each time the
477
460
  * update call is made. <br>
478
461
  * Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set) <br>
@@ -949,7 +932,7 @@ export class Camera2d extends Renderable {
949
932
  */
950
933
  moveTo(x: number, y: number): void;
951
934
  /** @ignore */
952
- updateTarget(): boolean;
935
+ updateTarget(): void;
953
936
  /** @ignore */
954
937
  update(dt: any): boolean;
955
938
  /**
@@ -1096,11 +1079,21 @@ export class CanvasRenderer extends Renderer {
1096
1079
  */
1097
1080
  resetTransform(): void;
1098
1081
  /**
1099
- * Set a blend mode for the given context
1082
+ * set a blend mode for the given context. <br>
1083
+ * Supported blend mode between Canvas and WebGL remderer : <br>
1084
+ * - "normal" : this is the default mode and draws new content on top of the existing content <br>
1085
+ * <img src="images/normal-blendmode.png" width="510"/> <br>
1086
+ * - "multiply" : the pixels of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result. <br>
1087
+ * <img src="images/multiply-blendmode.png" width="510"/> <br>
1088
+ * - "additive or lighter" : where both content overlap the color is determined by adding color values. <br>
1089
+ * <img src="images/lighter-blendmode.png" width="510"/> <br>
1090
+ * - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
1091
+ * <img src="images/screen-blendmode.png" width="510"/> <br>
1100
1092
  * @name setBlendMode
1093
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
1101
1094
  * @memberof CanvasRenderer.prototype
1102
1095
  * @function
1103
- * @param {string} [mode="normal"] blend mode : "normal", "multiply"
1096
+ * @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter, "additive", "screen"
1104
1097
  * @param {CanvasRenderingContext2D} [context]
1105
1098
  */
1106
1099
  setBlendMode(mode?: string, context?: CanvasRenderingContext2D): void;
@@ -4060,17 +4053,18 @@ export class ObservableVector3d extends Vector3d {
4060
4053
  /**
4061
4054
  * @classdesc
4062
4055
  * Single Particle Object.
4063
- * @class Particle
4064
4056
  * @augments Renderable
4065
- * @param {ParticleEmitter} particle emitter
4066
4057
  */
4067
4058
  export class Particle extends Renderable {
4059
+ /**
4060
+ * @param {ParticleEmitter} emitter the particle emitter
4061
+ */
4062
+ constructor(emitter: ParticleEmitter);
4068
4063
  /**
4069
4064
  * @ignore
4070
4065
  */
4071
- constructor(emitter: any);
4072
- vel: Vector2d;
4073
4066
  onResetEvent(emitter: any, newInstance?: boolean): void;
4067
+ vel: Vector2d;
4074
4068
  image: any;
4075
4069
  life: any;
4076
4070
  startLife: any;
@@ -4082,50 +4076,319 @@ export class Particle extends Renderable {
4082
4076
  onlyInViewport: any;
4083
4077
  _deltaInv: number;
4084
4078
  angle: number;
4085
- /**
4086
- * @ignore
4087
- */
4088
- preDraw(renderer: any): void;
4089
4079
  /**
4090
4080
  * @ignore
4091
4081
  */
4092
4082
  draw(renderer: any): void;
4093
4083
  }
4094
4084
  /**
4085
+ * @classdesc
4095
4086
  * Particle Emitter Object.
4096
- * @class
4097
- * @augments Rect
4098
- * @param {number} x x-position of the particle emitter
4099
- * @param {number} y y-position of the particle emitter
4100
- * @param {object} settings An object containing the settings for the particle emitter. See {@link ParticleEmitterSettings}
4101
- * @example
4102
- * // Create a basic emitter at position 100, 100
4103
- * var emitter = new me.ParticleEmitter(100, 100);
4104
- *
4105
- * // Adjust the emitter properties
4106
- * emitter.totalParticles = 200;
4107
- * emitter.minLife = 1000;
4108
- * emitter.maxLife = 3000;
4109
- * emitter.z = 10;
4110
- *
4111
- * // Add the emitter to the game world
4112
- * me.game.world.addChild(emitter);
4113
- *
4114
- * // Launch all particles one time and stop, like a explosion
4115
- * emitter.burstParticles();
4116
- *
4117
- * // Launch constantly the particles, like a fountain
4118
- * emitter.streamParticles();
4119
- *
4120
- * // At the end, remove emitter from the game world
4121
- * // call this in onDestroyEvent function
4122
- * me.game.world.removeChild(emitter);
4087
+ * @augments Container
4123
4088
  */
4124
- export class ParticleEmitter extends Rect {
4089
+ export class ParticleEmitter extends Container {
4125
4090
  /**
4126
- * @ignore
4091
+ * @param {number} x x position of the particle emitter
4092
+ * @param {number} y y position of the particle emitter
4093
+ * @param {ParticleEmitterSettings} [settings=ParticleEmitterSettings] the settings for the particle emitter.
4094
+ * @example
4095
+ * // Create a basic emitter at position 100, 100
4096
+ * var emitter = new ParticleEmitter(100, 100);
4097
+ *
4098
+ * // Adjust the emitter properties
4099
+ * emitter.totalParticles = 200;
4100
+ * emitter.minLife = 1000;
4101
+ * emitter.maxLife = 3000;
4102
+ * emitter.z = 10;
4103
+ *
4104
+ * // Add the emitter to the game world
4105
+ * me.game.world.addChild(emitter);
4106
+ *
4107
+ * // Launch all particles one time and stop, like a explosion
4108
+ * emitter.burstParticles();
4109
+ *
4110
+ * // Launch constantly the particles, like a fountain
4111
+ * emitter.streamParticles();
4112
+ *
4113
+ * // At the end, remove emitter from the game world
4114
+ * // call this in onDestroyEvent function
4115
+ * me.game.world.removeChild(emitter);
4127
4116
  */
4128
- constructor(x: any, y: any, settings: any);
4117
+ constructor(x: number, y: number, settings?: {
4118
+ /**
4119
+ * Width of the particle spawn area.
4120
+ * @type {number}
4121
+ * @name width
4122
+ * @memberof ParticleEmitterSettings
4123
+ * @default 1
4124
+ */
4125
+ width: number;
4126
+ /**
4127
+ * Height of the particle spawn area
4128
+ * @public
4129
+ * @type {number}
4130
+ * @name height
4131
+ * @memberof ParticleEmitterSettings
4132
+ * @default 1
4133
+ */
4134
+ height: number;
4135
+ /**
4136
+ * image used for particles texture
4137
+ * (by default melonJS will create an white 8x8 texture image)
4138
+ * @public
4139
+ * @type {HTMLCanvasElement}
4140
+ * @name image
4141
+ * @memberof ParticleEmitterSettings
4142
+ * @default undefined
4143
+ * @see ParticleEmitterSettings.textureSize
4144
+ */
4145
+ image: HTMLCanvasElement;
4146
+ /**
4147
+ * default texture size used for particles if no image is specified
4148
+ * (by default melonJS will create an white 8x8 texture image)
4149
+ * @public
4150
+ * @type {number}
4151
+ * @name textureSize
4152
+ * @memberof ParticleEmitterSettings
4153
+ * @default 8
4154
+ * @see ParticleEmitterSettings.image
4155
+ */
4156
+ textureSize: number;
4157
+ /**
4158
+ * tint to be applied to particles
4159
+ * @public
4160
+ * @type {string}
4161
+ * @name tint
4162
+ * @memberof ParticleEmitterSettings
4163
+ * @default "#fff"
4164
+ */
4165
+ tint: string;
4166
+ /**
4167
+ * Total number of particles in the emitter
4168
+ * @public
4169
+ * @type {number}
4170
+ * @name totalParticles
4171
+ * @default 50
4172
+ * @memberof ParticleEmitterSettings
4173
+ */
4174
+ totalParticles: number;
4175
+ /**
4176
+ * Start angle for particle launch in Radians
4177
+ * @public
4178
+ * @type {number}
4179
+ * @name angle
4180
+ * @default Math.PI / 2
4181
+ * @memberof ParticleEmitterSettings
4182
+ */
4183
+ angle: number;
4184
+ /**
4185
+ * Variation in the start angle for particle launch in Radians.
4186
+ * @public
4187
+ * @type {number}
4188
+ * @name angleVariation
4189
+ * @default 0
4190
+ * @memberof ParticleEmitterSettings
4191
+ */
4192
+ angleVariation: number;
4193
+ /**
4194
+ * Minimum time each particle lives once it is emitted in ms.
4195
+ * @public
4196
+ * @type {number}
4197
+ * @name minLife
4198
+ * @default 1000
4199
+ * @memberof ParticleEmitterSettings
4200
+ */
4201
+ minLife: number;
4202
+ /**
4203
+ * Maximum time each particle lives once it is emitted in ms.
4204
+ * @public
4205
+ * @type {number}
4206
+ * @name maxLife
4207
+ * @default 3000
4208
+ * @memberof ParticleEmitterSettings
4209
+ */
4210
+ maxLife: number;
4211
+ /**
4212
+ * Start speed of particles.<br>
4213
+ * @public
4214
+ * @type {number}
4215
+ * @name speed
4216
+ * @default 2
4217
+ * @memberof ParticleEmitterSettings
4218
+ */
4219
+ speed: number;
4220
+ /**
4221
+ * Variation in the start speed of particles
4222
+ * @public
4223
+ * @type {number}
4224
+ * @name speedVariation
4225
+ * @default 1
4226
+ * @memberof ParticleEmitterSettings
4227
+ */
4228
+ speedVariation: number;
4229
+ /**
4230
+ * Minimum start rotation for particles sprites in Radians
4231
+ * @public
4232
+ * @type {number}
4233
+ * @name minRotation
4234
+ * @default 0
4235
+ * @memberof ParticleEmitterSettings
4236
+ */
4237
+ minRotation: number;
4238
+ /**
4239
+ * Maximum start rotation for particles sprites in Radians
4240
+ * @public
4241
+ * @type {number}
4242
+ * @name maxRotation
4243
+ * @default 0
4244
+ * @memberof ParticleEmitterSettings
4245
+ */
4246
+ maxRotation: number;
4247
+ /**
4248
+ * Minimum start scale ratio for particles (1 = no scaling)
4249
+ * @public
4250
+ * @type {number}
4251
+ * @name minStartScale
4252
+ * @default 1
4253
+ * @memberof ParticleEmitterSettings
4254
+ */
4255
+ minStartScale: number;
4256
+ /**
4257
+ * Maximum start scale ratio for particles (1 = no scaling)
4258
+ * @public
4259
+ * @type {number}
4260
+ * @name maxStartScale
4261
+ * @default 1
4262
+ * @memberof ParticleEmitterSettings
4263
+ */
4264
+ maxStartScale: number;
4265
+ /**
4266
+ * Minimum end scale ratio for particles
4267
+ * @public
4268
+ * @type {number}
4269
+ * @name minEndScale
4270
+ * @default 0
4271
+ * @memberof ParticleEmitterSettings
4272
+ */
4273
+ minEndScale: number;
4274
+ /**
4275
+ * Maximum end scale ratio for particles
4276
+ * @public
4277
+ * @type {number}
4278
+ * @name maxEndScale
4279
+ * @default 0
4280
+ * @memberof ParticleEmitterSettings
4281
+ */
4282
+ maxEndScale: number;
4283
+ /**
4284
+ * Vertical force (Gravity) for each particle
4285
+ * @public
4286
+ * @type {number}
4287
+ * @name gravity
4288
+ * @default 0
4289
+ * @memberof ParticleEmitterSettings
4290
+ * @see game.world.gravity
4291
+ */
4292
+ gravity: number;
4293
+ /**
4294
+ * Horizontal force (like a Wind) for each particle
4295
+ * @public
4296
+ * @type {number}
4297
+ * @name wind
4298
+ * @default 0
4299
+ * @memberof ParticleEmitterSettings
4300
+ */
4301
+ wind: number;
4302
+ /**
4303
+ * Update the rotation of particle in accordance the particle trajectory.<br>
4304
+ * The particle sprite should aim at zero angle (draw from left to right).<br>
4305
+ * Override the particle minRotation and maxRotation.<br>
4306
+ * @public
4307
+ * @type {boolean}
4308
+ * @name followTrajectory
4309
+ * @default false
4310
+ * @memberof ParticleEmitterSettings
4311
+ */
4312
+ followTrajectory: boolean;
4313
+ /**
4314
+ * Enable the Texture Additive by composite operation ("additive" blendMode)
4315
+ * @public
4316
+ * @type {boolean}
4317
+ * @name textureAdditive
4318
+ * @default false
4319
+ * @memberof ParticleEmitterSettings
4320
+ * @see ParticleEmitterSettings.blendMode
4321
+ */
4322
+ textureAdditive: boolean;
4323
+ /**
4324
+ * the blend mode to be applied when rendering particles.
4325
+ * (note: this will superseed the `textureAdditive` setting if different than "normal")
4326
+ * @public
4327
+ * @type {string}
4328
+ * @name blendMode
4329
+ * @default normal
4330
+ * @memberof ParticleEmitterSettings
4331
+ * @see CanvasRenderer#setBlendMode
4332
+ * @see WebGLRenderer#setBlendMode
4333
+ */
4334
+ blendMode: string;
4335
+ /**
4336
+ * Update particles only in the viewport, remove it when out of viewport.
4337
+ * @public
4338
+ * @type {boolean}
4339
+ * @name onlyInViewport
4340
+ * @default true
4341
+ * @memberof ParticleEmitterSettings
4342
+ */
4343
+ onlyInViewport: boolean;
4344
+ /**
4345
+ * Render particles in screen space.
4346
+ * @public
4347
+ * @type {boolean}
4348
+ * @name floating
4349
+ * @default false
4350
+ * @memberof ParticleEmitterSettings
4351
+ */
4352
+ floating: boolean;
4353
+ /**
4354
+ * Maximum number of particles launched each time in this emitter (used only if emitter is Stream).
4355
+ * @public
4356
+ * @type {number}
4357
+ * @name maxParticles
4358
+ * @default 10
4359
+ * @memberof ParticleEmitterSettings
4360
+ */
4361
+ maxParticles: number;
4362
+ /**
4363
+ * How often a particle is emitted in ms (used only if emitter is a Stream).
4364
+ * @public
4365
+ * @type {number}
4366
+ * @name frequency
4367
+ * @default 100
4368
+ * @memberof ParticleEmitterSettings
4369
+ */
4370
+ frequency: number;
4371
+ /**
4372
+ * Duration that the emitter releases particles in ms (used only if emitter is Stream).
4373
+ * After this period, the emitter stop the launch of particles.
4374
+ * @public
4375
+ * @type {number}
4376
+ * @name duration
4377
+ * @default Infinity
4378
+ * @memberof ParticleEmitterSettings
4379
+ */
4380
+ duration: number;
4381
+ /**
4382
+ * Skip n frames after updating the particle system once.
4383
+ * This can be used to reduce the performance impact of emitters with many particles.
4384
+ * @public
4385
+ * @type {number}
4386
+ * @name framesToSkip
4387
+ * @default 0
4388
+ * @memberof ParticleEmitterSettings
4389
+ */
4390
+ framesToSkip: number;
4391
+ });
4129
4392
  /** @ignore */
4130
4393
  _stream: boolean;
4131
4394
  /** @ignore */
@@ -4134,95 +4397,43 @@ export class ParticleEmitter extends Rect {
4134
4397
  _durationTimer: number;
4135
4398
  /** @ignore */
4136
4399
  _enabled: boolean;
4137
- alwaysUpdate: boolean;
4138
- autoSort: boolean;
4139
- container: ParticleContainer;
4140
- /**
4141
- * @ignore
4142
- */
4143
- set z(arg: number);
4144
- /**
4145
- * @ignore
4146
- */
4147
- get z(): number;
4148
- set floating(arg: boolean);
4149
- /**
4150
- * Floating property for particles, value is forwarded to the particle container <br>
4151
- * @type {boolean}
4152
- * @name floating
4153
- * @memberof ParticleEmitter
4154
- */
4155
- get floating(): boolean;
4156
- /**
4157
- * @ignore
4158
- */
4159
- onActivateEvent(): void;
4160
- /**
4161
- * @ignore
4162
- */
4163
- onDeactivateEvent(): void;
4400
+ _updateCount: number;
4401
+ settings: {};
4402
+ _dt: number;
4164
4403
  /**
4165
- * @ignore
4404
+ * Reset the emitter with particle emitter settings.
4405
+ * @param {object} settings [optional] object with emitter settings. See {@link ParticleEmitterSettings}
4166
4406
  */
4167
- destroy(): void;
4407
+ reset(settings?: object): void;
4168
4408
  /**
4169
- * returns a random point inside the bounds x axis of this emitter
4170
- * @name getRandomPointX
4171
- * @memberof ParticleEmitter
4172
- * @function
4409
+ * returns a random point on the x axis within the bounds of this emitter
4173
4410
  * @returns {number}
4174
4411
  */
4175
4412
  getRandomPointX(): number;
4176
4413
  /**
4177
- * returns a random point inside the bounds y axis of this emitter
4178
- * @name getRandomPointY
4179
- * @memberof ParticleEmitter
4180
- * @function
4414
+ * returns a random point on the y axis within the bounds this emitter
4181
4415
  * @returns {number}
4182
4416
  */
4183
4417
  getRandomPointY(): number;
4184
- /**
4185
- * Reset the emitter with default values.<br>
4186
- * @function
4187
- * @param {object} settings [optional] object with emitter settings. See {@link ParticleEmitterSettings}
4188
- * @name reset
4189
- * @memberof ParticleEmitter
4190
- */
4191
- reset(settings: object): void;
4192
4418
  /** @ignore */
4193
4419
  addParticles(count: any): void;
4194
4420
  /**
4195
- * Emitter is of type stream and is launching particles <br>
4196
- * @function
4421
+ * Emitter is of type stream and is launching particles
4197
4422
  * @returns {boolean} Emitter is Stream and is launching particles
4198
- * @name isRunning
4199
- * @memberof ParticleEmitter
4200
4423
  */
4201
4424
  isRunning(): boolean;
4202
4425
  /**
4203
- * Launch particles from emitter constantly <br>
4204
- * Particles example: Fountains
4426
+ * Launch particles from emitter constantly (e.g. for stream)
4205
4427
  * @param {number} duration [optional] time that the emitter releases particles in ms
4206
- * @function
4207
- * @name streamParticles
4208
- * @memberof ParticleEmitter
4209
4428
  */
4210
4429
  streamParticles(duration: number): void;
4211
- frequency: any;
4212
4430
  /**
4213
- * Stop the emitter from generating new particles (used only if emitter is Stream) <br>
4214
- * @function
4215
- * @name stopStream
4216
- * @memberof ParticleEmitter
4431
+ * Stop the emitter from generating new particles (used only if emitter is Stream)
4217
4432
  */
4218
4433
  stopStream(): void;
4219
4434
  /**
4220
- * Launch all particles from emitter and stop <br>
4221
- * Particles example: Explosions <br>
4435
+ * Launch all particles from emitter and stop (e.g. for explosion)
4222
4436
  * @param {number} total [optional] number of particles to launch
4223
- * @function
4224
- * @name burstParticles
4225
- * @memberof ParticleEmitter
4226
4437
  */
4227
4438
  burstParticles(total: number): void;
4228
4439
  /**
@@ -4231,32 +4442,35 @@ export class ParticleEmitter extends Rect {
4231
4442
  update(dt: any): boolean;
4232
4443
  }
4233
4444
  export namespace ParticleEmitterSettings {
4234
- export const width: number;
4235
- export const height: number;
4236
- export { pixel as image };
4237
- export const totalParticles: number;
4238
- export const angle: number;
4239
- export const angleVariation: number;
4240
- export const minLife: number;
4241
- export const maxLife: number;
4242
- export const speed: number;
4243
- export const speedVariation: number;
4244
- export const minRotation: number;
4245
- export const maxRotation: number;
4246
- export const minStartScale: number;
4247
- export const maxStartScale: number;
4248
- export const minEndScale: number;
4249
- export const maxEndScale: number;
4250
- export const gravity: number;
4251
- export const wind: number;
4252
- export const followTrajectory: boolean;
4253
- export const textureAdditive: boolean;
4254
- export const onlyInViewport: boolean;
4255
- export const floating: boolean;
4256
- export const maxParticles: number;
4257
- export const frequency: number;
4258
- export const duration: number;
4259
- export const framesToSkip: number;
4445
+ const width: number;
4446
+ const height: number;
4447
+ const image: HTMLCanvasElement;
4448
+ const textureSize: number;
4449
+ const tint: string;
4450
+ const totalParticles: number;
4451
+ const angle: number;
4452
+ const angleVariation: number;
4453
+ const minLife: number;
4454
+ const maxLife: number;
4455
+ const speed: number;
4456
+ const speedVariation: number;
4457
+ const minRotation: number;
4458
+ const maxRotation: number;
4459
+ const minStartScale: number;
4460
+ const maxStartScale: number;
4461
+ const minEndScale: number;
4462
+ const maxEndScale: number;
4463
+ const gravity: number;
4464
+ const wind: number;
4465
+ const followTrajectory: boolean;
4466
+ const textureAdditive: boolean;
4467
+ const blendMode: string;
4468
+ const onlyInViewport: boolean;
4469
+ const floating: boolean;
4470
+ const maxParticles: number;
4471
+ const frequency: number;
4472
+ const duration: number;
4473
+ const framesToSkip: number;
4260
4474
  }
4261
4475
  /**
4262
4476
  * @classdesc
@@ -4950,6 +5164,16 @@ export class Rect extends Polygon {
4950
5164
  * @memberof Rect
4951
5165
  */
4952
5166
  public get centerY(): number;
5167
+ /**
5168
+ * center the rectangle position around the given coordinates
5169
+ * @name centerOn
5170
+ * @memberof Rect.prototype
5171
+ * @function
5172
+ * @param {number} x the x coordinate around which to center this rectangle
5173
+ * @param {number} x the y coordinate around which to center this rectangle
5174
+ * @returns {Rect} this rectangle
5175
+ */
5176
+ centerOn(x: number, y: any): Rect;
4953
5177
  /**
4954
5178
  * resize the rectangle
4955
5179
  * @name resize
@@ -5255,6 +5479,17 @@ export class Renderable extends Rect {
5255
5479
  * this.tint.setColor(255, 255, 255);
5256
5480
  */
5257
5481
  public tint: Color;
5482
+ /**
5483
+ * the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
5484
+ * @public
5485
+ * @type {string}
5486
+ * @name blendMode
5487
+ * @default "normal"
5488
+ * @see CanvasRenderer#setBlendMode
5489
+ * @see WebGLRenderer#setBlendMode
5490
+ * @memberof Renderable#
5491
+ */
5492
+ public blendMode: string;
5258
5493
  /**
5259
5494
  * The name of the renderable
5260
5495
  * @public
@@ -6913,6 +7148,7 @@ export class Text extends Renderable {
6913
7148
  * @param {number} [settings.lineHeight=1.0] line spacing height
6914
7149
  * @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] anchor point to draw the text at
6915
7150
  * @param {boolean} [settings.offScreenCanvas=false] whether to draw the font to an individual "cache" texture first
7151
+ * @param {number} [settings.wordWrapWidth] the maximum length in CSS pixel for a single segment of text
6916
7152
  * @param {(string|string[])} [settings.text=""] a string, or an array of strings
6917
7153
  * @example
6918
7154
  * var font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
@@ -6928,6 +7164,7 @@ export class Text extends Renderable {
6928
7164
  lineHeight?: number;
6929
7165
  anchorPoint?: Vector2d;
6930
7166
  offScreenCanvas?: boolean;
7167
+ wordWrapWidth?: number;
6931
7168
  text?: (string | string[]);
6932
7169
  });
6933
7170
  /** @ignore */
@@ -6939,7 +7176,6 @@ export class Text extends Renderable {
6939
7176
  * @public
6940
7177
  * @type {number}
6941
7178
  * @default 1
6942
- * @name Text#lineWidth
6943
7179
  */
6944
7180
  public lineWidth: number;
6945
7181
  /**
@@ -6948,7 +7184,6 @@ export class Text extends Renderable {
6948
7184
  * @public
6949
7185
  * @type {string}
6950
7186
  * @default "left"
6951
- * @name Text#textAlign
6952
7187
  */
6953
7188
  public textAlign: string;
6954
7189
  /**
@@ -6957,7 +7192,6 @@ export class Text extends Renderable {
6957
7192
  * @public
6958
7193
  * @type {string}
6959
7194
  * @default "top"
6960
- * @name Text#textBaseline
6961
7195
  */
6962
7196
  public textBaseline: string;
6963
7197
  /**
@@ -6966,7 +7200,6 @@ export class Text extends Renderable {
6966
7200
  * @public
6967
7201
  * @type {number}
6968
7202
  * @default 1.0
6969
- * @name Text#lineHeight
6970
7203
  */
6971
7204
  public lineHeight: number;
6972
7205
  /**
@@ -6976,9 +7209,16 @@ export class Text extends Renderable {
6976
7209
  * @public
6977
7210
  * @type {boolean}
6978
7211
  * @default false
6979
- * @name Text#offScreenCanvas
6980
7212
  */
6981
7213
  public offScreenCanvas: boolean;
7214
+ /**
7215
+ * the maximum length in CSS pixel for a single segment of text.
7216
+ * (use -1 to disable word wrapping)
7217
+ * @public
7218
+ * @type {number}
7219
+ * @default -1
7220
+ */
7221
+ public wordWrapWidth: number;
6982
7222
  /**
6983
7223
  * the text to be displayed
6984
7224
  * @private
@@ -6988,38 +7228,28 @@ export class Text extends Renderable {
6988
7228
  * the font size (in px)
6989
7229
  * @public
6990
7230
  * @type {number}
6991
- * @name fontSize
6992
7231
  * @default 10
6993
- * @memberof Text
6994
7232
  */
6995
7233
  public fontSize: number;
6996
7234
  canvas: HTMLCanvasElement | OffscreenCanvas;
6997
7235
  context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
7236
+ metrics: TextMetrics;
6998
7237
  /** @ignore */
6999
7238
  onDeactivateEvent(): void;
7000
7239
  glTextureUnit: any;
7001
7240
  /**
7002
7241
  * make the font bold
7003
- * @name bold
7004
- * @memberof Text.prototype
7005
- * @function
7006
7242
  * @returns {Text} this object for chaining
7007
7243
  */
7008
7244
  bold(): Text;
7009
7245
  font: any;
7010
7246
  /**
7011
7247
  * make the font italic
7012
- * @name italic
7013
- * @memberof Text.prototype
7014
- * @function
7015
7248
  * @returns {Text} this object for chaining
7016
7249
  */
7017
7250
  italic(): Text;
7018
7251
  /**
7019
7252
  * set the font family and size
7020
- * @name setFont
7021
- * @memberof Text.prototype
7022
- * @function
7023
7253
  * @param {string} font a CSS font name
7024
7254
  * @param {number|string} [size=10] size in px, or size + suffix (px, em, pt)
7025
7255
  * @returns {Text} this object for chaining
@@ -7030,33 +7260,19 @@ export class Text extends Renderable {
7030
7260
  setFont(font: string, size?: number | string): Text;
7031
7261
  /**
7032
7262
  * change the text to be displayed
7033
- * @name setText
7034
- * @memberof Text.prototype
7035
- * @function
7036
7263
  * @param {number|string|string[]} value a string, or an array of strings
7037
7264
  * @returns {Text} this object for chaining
7038
7265
  */
7039
7266
  setText(value?: number | string | string[]): Text;
7040
7267
  /**
7041
7268
  * measure the given text size in pixels
7042
- * @name measureText
7043
- * @memberof Text.prototype
7044
- * @function
7045
7269
  * @param {CanvasRenderer|WebGLRenderer} [renderer] reference to the active renderer
7046
7270
  * @param {string} [text] the text to be measured
7047
- * @param {Rect|Bounds} [ret] a object in which to store the text metrics
7048
- * @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
7271
+ * @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
7049
7272
  */
7050
- measureText(renderer?: CanvasRenderer | WebGLRenderer, text?: string, ret?: Rect | Bounds): TextMetrics;
7051
- /**
7052
- * @ignore
7053
- */
7054
- update(): boolean;
7273
+ measureText(renderer$1?: CanvasRenderer | WebGLRenderer, text?: string): TextMetrics;
7055
7274
  /**
7056
7275
  * draw a text at the specified coord
7057
- * @name draw
7058
- * @memberof Text.prototype
7059
- * @function
7060
7276
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
7061
7277
  * @param {string} [text]
7062
7278
  * @param {number} [x]
@@ -7068,9 +7284,6 @@ export class Text extends Renderable {
7068
7284
  * draw a stroke text at the specified coord, as defined <br>
7069
7285
  * by the `lineWidth` and `fillStroke` properties. <br>
7070
7286
  * Note : using drawStroke is not recommended for performance reasons
7071
- * @name drawStroke
7072
- * @memberof Text.prototype
7073
- * @function
7074
7287
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
7075
7288
  * @param {string} text
7076
7289
  * @param {number} x
@@ -7080,7 +7293,7 @@ export class Text extends Renderable {
7080
7293
  /**
7081
7294
  * @ignore
7082
7295
  */
7083
- _drawFont(context: any, text: any, x: any, y: any, stroke?: boolean): Bounds;
7296
+ _drawFont(context: any, text: any, x: any, y: any, stroke?: boolean): TextMetrics;
7084
7297
  /**
7085
7298
  * Destroy function
7086
7299
  * @ignore
@@ -8634,6 +8847,10 @@ export class WebGLRenderer extends Renderer {
8634
8847
  * @ignore
8635
8848
  */
8636
8849
  _scissorStack: any[];
8850
+ /**
8851
+ * @ignore
8852
+ */
8853
+ _blendStack: any[];
8637
8854
  /**
8638
8855
  * @ignore
8639
8856
  */
@@ -8799,14 +9016,25 @@ export class WebGLRenderer extends Renderer {
8799
9016
  */
8800
9017
  getContext(): WebGLRenderingContext;
8801
9018
  /**
8802
- * set a blend mode for the given context
9019
+ * set a blend mode for the given context. <br>
9020
+ * Supported blend mode between Canvas and WebGL remderer : <br>
9021
+ * - "normal" : this is the default mode and draws new content on top of the existing content <br>
9022
+ * <img src="images/normal-blendmode.png" width="510"/> <br>
9023
+ * - "multiply" : the pixels of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result. <br>
9024
+ * <img src="images/multiply-blendmode.png" width="510"/> <br>
9025
+ * - "additive or lighter" : where both content overlap the color is determined by adding color values. <br>
9026
+ * <img src="images/lighter-blendmode.png" width="510"/> <br>
9027
+ * - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
9028
+ * <img src="images/screen-blendmode.png" width="510"/> <br>
8803
9029
  * @name setBlendMode
9030
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
8804
9031
  * @memberof WebGLRenderer.prototype
8805
9032
  * @function
8806
- * @param {string} [mode="normal"] blend mode : "normal", "multiply"
9033
+ * @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter", "additive", "screen"
8807
9034
  * @param {WebGLRenderingContext} [gl]
8808
9035
  */
8809
9036
  setBlendMode(mode?: string, gl?: WebGLRenderingContext): void;
9037
+ currentBlendMode: any;
8810
9038
  /**
8811
9039
  * return a reference to the font 2d Context
8812
9040
  * @ignore
@@ -9161,7 +9389,7 @@ declare namespace device$1 {
9161
9389
  namespace turnOnPointerLock { }
9162
9390
  namespace turnOffPointerLock { }
9163
9391
  }
9164
- export var event: Readonly<{
9392
+ declare var event$1: Readonly<{
9165
9393
  __proto__: any;
9166
9394
  BOOT: string;
9167
9395
  STATE_PAUSE: string;
@@ -9194,8 +9422,8 @@ export var event: Readonly<{
9194
9422
  WINDOW_ONORIENTATION_CHANGE: string;
9195
9423
  WINDOW_ONSCROLL: string;
9196
9424
  VIEWPORT_ONCHANGE: string;
9197
- WEBGL_ONCONTEXT_LOST: string;
9198
- WEBGL_ONCONTEXT_RESTORED: string;
9425
+ ONCONTEXT_LOST: string;
9426
+ ONCONTEXT_RESTORED: string;
9199
9427
  emit: typeof emit;
9200
9428
  on: typeof on;
9201
9429
  once: typeof once;
@@ -10168,184 +10396,16 @@ export var plugin: any;
10168
10396
  * @namespace plugins
10169
10397
  */
10170
10398
  export var plugins: {};
10171
- export namespace pool {
10172
- /**
10173
- * register an object to the pool. <br>
10174
- * Pooling must be set to true if more than one such objects will be created. <br>
10175
- * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
10176
- * @function pool.register
10177
- * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
10178
- * @param {object} classObj corresponding Class to be instantiated
10179
- * @param {boolean} [recycling=false] enables object recycling for the specified class
10180
- * @example
10181
- * // implement CherryEntity
10182
- * class CherryEntity extends Spritesheet {
10183
- * onResetEvent() {
10184
- * // reset object mutable properties
10185
- * this.lifeBar = 100;
10186
- * }
10187
- * };
10188
- * // add our users defined entities in the object pool and enable object recycling
10189
- * me.pool.register("cherryentity", CherryEntity, true);
10190
- */
10191
- function register(className: string, classObj: any, recycling?: boolean): void;
10192
- /**
10193
- * register an object to the pool. <br>
10194
- * Pooling must be set to true if more than one such objects will be created. <br>
10195
- * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
10196
- * @function pool.register
10197
- * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
10198
- * @param {object} classObj corresponding Class to be instantiated
10199
- * @param {boolean} [recycling=false] enables object recycling for the specified class
10200
- * @example
10201
- * // implement CherryEntity
10202
- * class CherryEntity extends Spritesheet {
10203
- * onResetEvent() {
10204
- * // reset object mutable properties
10205
- * this.lifeBar = 100;
10206
- * }
10207
- * };
10208
- * // add our users defined entities in the object pool and enable object recycling
10209
- * me.pool.register("cherryentity", CherryEntity, true);
10210
- */
10211
- function register(className: string, classObj: any, recycling?: boolean): void;
10212
- /**
10213
- * Pull a new instance of the requested object (if added into the object pool)
10214
- * @function pool.pull
10215
- * @param {string} name as used in {@link pool.register}
10216
- * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
10217
- * @returns {object} the instance of the requested object
10218
- * @example
10219
- * me.pool.register("bullet", BulletEntity, true);
10220
- * me.pool.register("enemy", EnemyEntity, true);
10221
- * // ...
10222
- * // when we need to manually create a new bullet:
10223
- * var bullet = me.pool.pull("bullet", x, y, direction);
10224
- * // ...
10225
- * // params aren't a fixed number
10226
- * // when we need new enemy we can add more params, that the object construct requires:
10227
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
10228
- * // ...
10229
- * // when we want to destroy existing object, the remove
10230
- * // function will ensure the object can then be reallocated later
10231
- * me.game.world.removeChild(enemy);
10232
- * me.game.world.removeChild(bullet);
10233
- */
10234
- function pull(name: string, ...args: any[]): any;
10235
- /**
10236
- * Pull a new instance of the requested object (if added into the object pool)
10237
- * @function pool.pull
10238
- * @param {string} name as used in {@link pool.register}
10239
- * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
10240
- * @returns {object} the instance of the requested object
10241
- * @example
10242
- * me.pool.register("bullet", BulletEntity, true);
10243
- * me.pool.register("enemy", EnemyEntity, true);
10244
- * // ...
10245
- * // when we need to manually create a new bullet:
10246
- * var bullet = me.pool.pull("bullet", x, y, direction);
10247
- * // ...
10248
- * // params aren't a fixed number
10249
- * // when we need new enemy we can add more params, that the object construct requires:
10250
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
10251
- * // ...
10252
- * // when we want to destroy existing object, the remove
10253
- * // function will ensure the object can then be reallocated later
10254
- * me.game.world.removeChild(enemy);
10255
- * me.game.world.removeChild(bullet);
10256
- */
10257
- function pull(name: string, ...args: any[]): any;
10258
- /**
10259
- * purge the object pool from any inactive object <br>
10260
- * Object pooling must be enabled for this function to work<br>
10261
- * note: this will trigger the garbage collector
10262
- * @function pool.purge
10263
- */
10264
- function purge(): void;
10265
- /**
10266
- * purge the object pool from any inactive object <br>
10267
- * Object pooling must be enabled for this function to work<br>
10268
- * note: this will trigger the garbage collector
10269
- * @function pool.purge
10270
- */
10271
- function purge(): void;
10272
- /**
10273
- * Push back an object instance into the object pool <br>
10274
- * Object pooling for the object class must be enabled,
10275
- * and object must have been instantiated using {@link pool#pull},
10276
- * otherwise this function won't work
10277
- * @function pool.push
10278
- * @throws will throw an error if the object cannot be recycled
10279
- * @param {object} obj instance to be recycled
10280
- * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
10281
- * @returns {boolean} true if the object was successfully recycled in the object pool
10282
- */
10283
- function push(obj: any, throwOnError?: boolean): boolean;
10284
- /**
10285
- * Push back an object instance into the object pool <br>
10286
- * Object pooling for the object class must be enabled,
10287
- * and object must have been instantiated using {@link pool#pull},
10288
- * otherwise this function won't work
10289
- * @function pool.push
10290
- * @throws will throw an error if the object cannot be recycled
10291
- * @param {object} obj instance to be recycled
10292
- * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
10293
- * @returns {boolean} true if the object was successfully recycled in the object pool
10294
- */
10295
- function push(obj: any, throwOnError?: boolean): boolean;
10296
- /**
10297
- * Check if an object with the provided name is registered
10298
- * @function pool.exists
10299
- * @param {string} name of the registered object class
10300
- * @returns {boolean} true if the classname is registered
10301
- */
10302
- function exists(name: string): boolean;
10303
- /**
10304
- * Check if an object with the provided name is registered
10305
- * @function pool.exists
10306
- * @param {string} name of the registered object class
10307
- * @returns {boolean} true if the classname is registered
10308
- */
10309
- function exists(name: string): boolean;
10310
- /**
10311
- * Check if an object is poolable
10312
- * (was properly registered with the recycling feature enable)
10313
- * @function pool.poolable
10314
- * @see pool.register
10315
- * @param {object} obj object to be checked
10316
- * @returns {boolean} true if the object is poolable
10317
- * @example
10318
- * if (!me.pool.poolable(myCherryEntity)) {
10319
- * // object was not properly registered
10320
- * }
10321
- */
10322
- function poolable(obj: any): boolean;
10323
- /**
10324
- * Check if an object is poolable
10325
- * (was properly registered with the recycling feature enable)
10326
- * @function pool.poolable
10327
- * @see pool.register
10328
- * @param {object} obj object to be checked
10329
- * @returns {boolean} true if the object is poolable
10330
- * @example
10331
- * if (!me.pool.poolable(myCherryEntity)) {
10332
- * // object was not properly registered
10333
- * }
10334
- */
10335
- function poolable(obj: any): boolean;
10336
- /**
10337
- * returns the amount of object instance currently in the pool
10338
- * @function pool.getInstanceCount
10339
- * @returns {number} amount of object instance
10340
- */
10341
- function getInstanceCount(): number;
10342
- /**
10343
- * returns the amount of object instance currently in the pool
10344
- * @function pool.getInstanceCount
10345
- * @returns {number} amount of object instance
10346
- */
10347
- function getInstanceCount(): number;
10348
- }
10399
+ declare var pooling: Readonly<{
10400
+ __proto__: any;
10401
+ register: typeof register;
10402
+ pull: typeof pull;
10403
+ purge: typeof purge;
10404
+ push: typeof push;
10405
+ exists: typeof exists;
10406
+ poolable: typeof poolable;
10407
+ getInstanceCount: typeof getInstanceCount;
10408
+ }>;
10349
10409
  export namespace save {
10350
10410
  /**
10351
10411
  * Add new keys to localStorage and set them to the given default values if they do not exist
@@ -10416,7 +10476,7 @@ export namespace state {
10416
10476
  const DEFAULT: number;
10417
10477
  const USER: number;
10418
10478
  /**
10419
- * Stop the current screen object.
10479
+ * Stop the current stage.
10420
10480
  * @name stop
10421
10481
  * @memberof state
10422
10482
  * @public
@@ -10425,7 +10485,7 @@ export namespace state {
10425
10485
  */
10426
10486
  function stop(pauseTrack?: boolean): void;
10427
10487
  /**
10428
- * Stop the current screen object.
10488
+ * Stop the current stage.
10429
10489
  * @name stop
10430
10490
  * @memberof state
10431
10491
  * @public
@@ -10434,7 +10494,7 @@ export namespace state {
10434
10494
  */
10435
10495
  function stop(pauseTrack?: boolean): void;
10436
10496
  /**
10437
- * pause the current screen object
10497
+ * pause the current stage
10438
10498
  * @name pause
10439
10499
  * @memberof state
10440
10500
  * @public
@@ -10443,7 +10503,7 @@ export namespace state {
10443
10503
  */
10444
10504
  function pause(music?: boolean): void;
10445
10505
  /**
10446
- * pause the current screen object
10506
+ * pause the current stage
10447
10507
  * @name pause
10448
10508
  * @memberof state
10449
10509
  * @public
@@ -10452,7 +10512,7 @@ export namespace state {
10452
10512
  */
10453
10513
  function pause(music?: boolean): void;
10454
10514
  /**
10455
- * Restart the screen object from a full stop.
10515
+ * Restart the current stage from a full stop.
10456
10516
  * @name restart
10457
10517
  * @memberof state
10458
10518
  * @public
@@ -10461,7 +10521,7 @@ export namespace state {
10461
10521
  */
10462
10522
  function restart(music?: boolean): void;
10463
10523
  /**
10464
- * Restart the screen object from a full stop.
10524
+ * Restart the current stage from a full stop.
10465
10525
  * @name restart
10466
10526
  * @memberof state
10467
10527
  * @public
@@ -10470,7 +10530,7 @@ export namespace state {
10470
10530
  */
10471
10531
  function restart(music?: boolean): void;
10472
10532
  /**
10473
- * resume the screen object
10533
+ * resume the current stage
10474
10534
  * @name resume
10475
10535
  * @memberof state
10476
10536
  * @public
@@ -10479,7 +10539,7 @@ export namespace state {
10479
10539
  */
10480
10540
  function resume(music?: boolean): void;
10481
10541
  /**
10482
- * resume the screen object
10542
+ * resume the current stage
10483
10543
  * @name resume
10484
10544
  * @memberof state
10485
10545
  * @public
@@ -10618,7 +10678,7 @@ export namespace state {
10618
10678
  */
10619
10679
  function set(state: number, stage: Stage, start?: boolean): void;
10620
10680
  /**
10621
- * return a reference to the current screen object<br>
10681
+ * return a reference to the current stage<br>
10622
10682
  * useful to call a object specific method
10623
10683
  * @name current
10624
10684
  * @memberof state
@@ -10628,7 +10688,7 @@ export namespace state {
10628
10688
  */
10629
10689
  function current(): Stage;
10630
10690
  /**
10631
- * return a reference to the current screen object<br>
10691
+ * return a reference to the current stage<br>
10632
10692
  * useful to call a object specific method
10633
10693
  * @name current
10634
10694
  * @memberof state
@@ -10946,6 +11006,51 @@ export var video: Readonly<{
10946
11006
  * @param {string} version the version since when the lass,function or property is deprecated
10947
11007
  */
10948
11008
  export function warning(deprecated: string, replacement: string, version: string): void;
11009
+ /**
11010
+ * @classdesc
11011
+ * a Text Metrics object that contains helper for text manipulation
11012
+ * @augments Bounds
11013
+ */
11014
+ declare class TextMetrics extends Bounds {
11015
+ /**
11016
+ * @param {Text|BitmapText} ancestor the parent object that contains this TextMetrics object
11017
+ */
11018
+ constructor(ancestor: Text | BitmapText);
11019
+ /**
11020
+ * a reference to the parent object that contains this TextMetrics object
11021
+ * @public
11022
+ * @type {Renderable}
11023
+ * @default undefined
11024
+ */
11025
+ public ancestor: Renderable;
11026
+ /**
11027
+ * Returns the height of a segment of inline text in CSS pixels.
11028
+ * @returns {number} the height of a segment of inline text in CSS pixels.
11029
+ */
11030
+ lineHeight(): number;
11031
+ /**
11032
+ * Returns the width of the given segment of inline text in CSS pixels.
11033
+ * @param {string} text the text to be measured
11034
+ * @param {CanvasRenderingContext2D} [context] reference to an active 2d context for canvas rendering
11035
+ * @returns {number} the width of the given segment of inline text in CSS pixels.
11036
+ */
11037
+ lineWidth(text: string, context?: CanvasRenderingContext2D): number;
11038
+ /**
11039
+ * measure the given text size in CSS pixels
11040
+ * @param {string} text the text to be measured
11041
+ * @param {CanvasRenderingContext2D} [context] reference to an active 2d context for canvas rendering
11042
+ * @returns {TextMetrics} this
11043
+ */
11044
+ measureText(text: string, context?: CanvasRenderingContext2D): TextMetrics;
11045
+ /**
11046
+ * wrap the given text based on the given width
11047
+ * @param {string|string[]} text the text to be wrapped
11048
+ * @param {number} width maximum width of one segment of text in css pixel
11049
+ * @param {CanvasRenderingContext2D} [context] reference to an active 2d context for canvas rendering
11050
+ * @returns {string[]} an array of string representing wrapped text
11051
+ */
11052
+ wordWrap(text: string | string[], width: number, context?: CanvasRenderingContext2D): string[];
11053
+ }
10949
11054
  /**
10950
11055
  * @classdesc
10951
11056
  * a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
@@ -11383,31 +11488,6 @@ declare function round(num: number, dec?: number): number;
11383
11488
  * }
11384
11489
  */
11385
11490
  declare function toBeCloseTo(expected: number, actual: number, precision?: number): boolean;
11386
- /**
11387
- * @classdesc
11388
- * Particle Container Object.
11389
- * @class ParticleContainer
11390
- * @augments Container
11391
- * @param {ParticleEmitter} emitter the emitter which owns this container
11392
- */
11393
- declare class ParticleContainer extends Container {
11394
- /**
11395
- * @ignore
11396
- */
11397
- constructor(emitter: any);
11398
- _updateCount: number;
11399
- _dt: number;
11400
- _emitter: any;
11401
- /**
11402
- * @ignore
11403
- */
11404
- update(dt: any): boolean;
11405
- /**
11406
- * @ignore
11407
- */
11408
- draw(renderer: any, rect: any): void;
11409
- }
11410
- declare var pixel: HTMLCanvasElement | OffscreenCanvas;
11411
11491
  /**
11412
11492
  * @classdesc
11413
11493
  * a Vertex Buffer object
@@ -11951,7 +12031,6 @@ declare function releaseAllPointerEvents(region: Rect | Polygon | Line | Ellipse
11951
12031
  * @memberof input
11952
12032
  * @public
11953
12033
  * @function
11954
- * @param {Function} [success] callback if the request is successful
11955
12034
  * @returns {boolean} return true if the request was successfully submitted
11956
12035
  * @example
11957
12036
  * // register on the pointer lock change event
@@ -12127,6 +12206,107 @@ declare function setGamepadDeadzone(value: number): void;
12127
12206
  * @ignore
12128
12207
  */
12129
12208
  declare function addMapping(id: any, mapping: any): void;
12209
+ /**
12210
+ * This object is used for object pooling - a technique that might speed up your game if used properly.<br>
12211
+ * If some of your classes will be instantiated and removed a lot at a time, it is a
12212
+ * good idea to add the class to this object pool. A separate pool for that class
12213
+ * will be created, which will reuse objects of the class. That way they won't be instantiated
12214
+ * each time you need a new one (slowing your game), but stored into that pool and taking one
12215
+ * already instantiated when you need it.<br><br>
12216
+ * This object is also used by the engine to instantiate objects defined in the map,
12217
+ * which means, that on level loading the engine will try to instantiate every object
12218
+ * found in the map, based on the user defined name in each Object Properties<br>
12219
+ * <img src="images/object_properties.png"/><br>
12220
+ * @namespace pool
12221
+ */
12222
+ /**
12223
+ * register an object to the pool. <br>
12224
+ * Pooling must be set to true if more than one such objects will be created. <br>
12225
+ * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
12226
+ * @function pool.register
12227
+ * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
12228
+ * @param {object} classObj corresponding Class to be instantiated
12229
+ * @param {boolean} [recycling=false] enables object recycling for the specified class
12230
+ * @example
12231
+ * // implement CherryEntity
12232
+ * class CherryEntity extends Spritesheet {
12233
+ * onResetEvent() {
12234
+ * // reset object mutable properties
12235
+ * this.lifeBar = 100;
12236
+ * }
12237
+ * };
12238
+ * // add our users defined entities in the object pool and enable object recycling
12239
+ * me.pool.register("cherryentity", CherryEntity, true);
12240
+ */
12241
+ declare function register(className: string, classObj: object, recycling?: boolean): void;
12242
+ /**
12243
+ * Pull a new instance of the requested object (if added into the object pool)
12244
+ * @function pool.pull
12245
+ * @param {string} name as used in {@link pool.register}
12246
+ * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
12247
+ * @returns {object} the instance of the requested object
12248
+ * @example
12249
+ * me.pool.register("bullet", BulletEntity, true);
12250
+ * me.pool.register("enemy", EnemyEntity, true);
12251
+ * // ...
12252
+ * // when we need to manually create a new bullet:
12253
+ * var bullet = me.pool.pull("bullet", x, y, direction);
12254
+ * // ...
12255
+ * // params aren't a fixed number
12256
+ * // when we need new enemy we can add more params, that the object construct requires:
12257
+ * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
12258
+ * // ...
12259
+ * // when we want to destroy existing object, the remove
12260
+ * // function will ensure the object can then be reallocated later
12261
+ * me.game.world.removeChild(enemy);
12262
+ * me.game.world.removeChild(bullet);
12263
+ */
12264
+ declare function pull(name: string, ...args: any[]): object;
12265
+ /**
12266
+ * purge the object pool from any inactive object <br>
12267
+ * Object pooling must be enabled for this function to work<br>
12268
+ * note: this will trigger the garbage collector
12269
+ * @function pool.purge
12270
+ */
12271
+ declare function purge(): void;
12272
+ /**
12273
+ * Push back an object instance into the object pool <br>
12274
+ * Object pooling for the object class must be enabled,
12275
+ * and object must have been instantiated using {@link pool#pull},
12276
+ * otherwise this function won't work
12277
+ * @function pool.push
12278
+ * @throws will throw an error if the object cannot be recycled
12279
+ * @param {object} obj instance to be recycled
12280
+ * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
12281
+ * @returns {boolean} true if the object was successfully recycled in the object pool
12282
+ */
12283
+ declare function push(obj: object, throwOnError?: boolean): boolean;
12284
+ /**
12285
+ * Check if an object with the provided name is registered
12286
+ * @function pool.exists
12287
+ * @param {string} name of the registered object class
12288
+ * @returns {boolean} true if the classname is registered
12289
+ */
12290
+ declare function exists(name: string): boolean;
12291
+ /**
12292
+ * Check if an object is poolable
12293
+ * (was properly registered with the recycling feature enable)
12294
+ * @function pool.poolable
12295
+ * @see pool.register
12296
+ * @param {object} obj object to be checked
12297
+ * @returns {boolean} true if the object is poolable
12298
+ * @example
12299
+ * if (!me.pool.poolable(myCherryEntity)) {
12300
+ * // object was not properly registered
12301
+ * }
12302
+ */
12303
+ declare function poolable(obj: object): boolean;
12304
+ /**
12305
+ * returns the amount of object instance currently in the pool
12306
+ * @function pool.getInstanceCount
12307
+ * @returns {number} amount of object instance
12308
+ */
12309
+ declare function getInstanceCount(): number;
12130
12310
  declare var agentUtils: Readonly<{
12131
12311
  __proto__: any;
12132
12312
  prefixed: typeof prefixed;
@@ -12242,7 +12422,7 @@ declare function scale(x: number, y: number): void;
12242
12422
  * @name prefixed
12243
12423
  * @function
12244
12424
  * @param {string} name Property name
12245
- * @param {object} [obj=window] Object or element reference to access
12425
+ * @param {object} [obj=globalThis] Object or element reference to access
12246
12426
  * @returns {string} Value of property
12247
12427
  * @memberof utils.agent
12248
12428
  */
@@ -12254,7 +12434,7 @@ declare function prefixed(name: string, obj?: object): string;
12254
12434
  * @function
12255
12435
  * @param {string} name Property name
12256
12436
  * @param {string} value Property value
12257
- * @param {object} [obj=window] Object or element reference to access
12437
+ * @param {object} [obj=globalThis] Object or element reference to access
12258
12438
  * @returns {boolean} true if one of the vendor-prefixed property was found
12259
12439
  * @memberof utils.agent
12260
12440
  */
@@ -12419,4 +12599,4 @@ declare function defer(func: Function, thisArg: object, ...args: any[]): number;
12419
12599
  * @returns {Function} the function that will be throttled
12420
12600
  */
12421
12601
  declare function throttle(fn: Function, delay: number, no_trailing: any): Function;
12422
- export { Bounds$1 as Bounds, math as Math, device$1 as device, timer$1 as timer };
12602
+ export { Bounds$1 as Bounds, math as Math, device$1 as device, event$1 as event, pooling as pool, timer$1 as timer };