melonjs 10.5.0 → 10.6.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 (49) hide show
  1. package/README.md +4 -6
  2. package/dist/melonjs.js +4342 -4183
  3. package/dist/melonjs.min.js +14 -14
  4. package/dist/melonjs.module.d.ts +256 -317
  5. package/dist/melonjs.module.js +4651 -4506
  6. package/package.json +10 -10
  7. package/src/camera/camera2d.js +11 -10
  8. package/src/geometries/ellipse.js +1 -1
  9. package/src/geometries/poly.js +1 -1
  10. package/src/index.js +1 -1
  11. package/src/input/pointerevent.js +1 -1
  12. package/src/level/tiled/TMXLayer.js +1 -1
  13. package/src/level/tiled/TMXTileMap.js +1 -1
  14. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  15. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  16. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  17. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  18. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  19. package/src/loader/loadingscreen.js +1 -1
  20. package/src/math/color.js +1 -1
  21. package/src/math/matrix2.js +2 -2
  22. package/src/math/matrix3.js +1 -1
  23. package/src/math/observable_vector2.js +1 -1
  24. package/src/math/observable_vector3.js +1 -1
  25. package/src/math/vector2.js +1 -1
  26. package/src/math/vector3.js +1 -1
  27. package/src/particles/emitter.js +1 -1
  28. package/src/physics/body.js +7 -7
  29. package/src/renderable/colorlayer.js +1 -1
  30. package/src/renderable/container.js +11 -1
  31. package/src/renderable/dragndrop.js +2 -2
  32. package/src/renderable/imagelayer.js +1 -1
  33. package/src/renderable/nineslicesprite.js +6 -3
  34. package/src/renderable/renderable.js +20 -4
  35. package/src/renderable/sprite.js +2 -2
  36. package/src/state/state.js +6 -6
  37. package/src/system/pooling.js +150 -155
  38. package/src/text/bitmaptext.js +30 -86
  39. package/src/text/text.js +82 -145
  40. package/src/text/textmetrics.js +168 -0
  41. package/src/text/textstyle.js +14 -0
  42. package/src/video/canvas/canvas_renderer.js +21 -5
  43. package/src/video/renderer.js +1 -3
  44. package/src/video/texture.js +1 -1
  45. package/src/video/video.js +1 -1
  46. package/src/video/webgl/buffer/vertex.js +0 -3
  47. package/src/video/webgl/glshader.js +0 -2
  48. package/src/video/webgl/webgl_compositor.js +11 -0
  49. package/src/video/webgl/webgl_renderer.js +58 -19
@@ -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,47 +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;
134
+ measureText(text?: string): TextMetrics;
145
135
  /**
146
136
  * draw the bitmap font
147
- * @name draw
148
- * @memberof BitmapText.prototype
149
- * @function
150
137
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
151
138
  * @param {string} [text]
152
139
  * @param {number} [x]
@@ -243,7 +230,7 @@ export class Body {
243
230
  * @see collision.types
244
231
  * @example
245
232
  * // set the body collision type
246
- * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
233
+ * body.collisionType = me.collision.types.PLAYER_OBJECT;
247
234
  */
248
235
  public collisionType: number;
249
236
  vel: Vector2d;
@@ -380,17 +367,17 @@ export class Body {
380
367
  */
381
368
  removeShapeAt(index: number): number;
382
369
  /**
383
- * 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>
384
371
  * but it's also possible to specify 'collision filters' to provide a finer <br>
385
- * control over which entities can collide with each other.
372
+ * control over which body can collide with each other.
386
373
  * @see collision.types
387
374
  * @param {number} [bitmask = collision.types.ALL_OBJECT] the collision mask
388
375
  * @example
389
376
  * // filter collision detection with collision shapes, enemies and collectables
390
- * 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);
391
378
  * ...
392
379
  * // disable collision detection with all other objects
393
- * myEntity.body.setCollisionMask(me.collision.types.NO_OBJECT);
380
+ * body.setCollisionMask(me.collision.types.NO_OBJECT);
394
381
  */
395
382
  setCollisionMask(bitmask?: number): void;
396
383
  /**
@@ -399,7 +386,7 @@ export class Body {
399
386
  * @param {number} type the collision type
400
387
  * @example
401
388
  * // set the body collision type
402
- * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
389
+ * body.collisionType = me.collision.types.PLAYER_OBJECT;
403
390
  */
404
391
  setCollisionType(type: number): void;
405
392
  /**
@@ -468,7 +455,7 @@ export class Body {
468
455
  * Updates the parent's position as well as computes the new body's velocity based
469
456
  * on the values of force/friction/gravity. Velocity chages are proportional to the
470
457
  * me.timer.tick value (which can be used to scale velocities). The approach to moving the
471
- * 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
472
459
  * the parent.pos value thus changing the postion the amount of Body.vel each time the
473
460
  * update call is made. <br>
474
461
  * Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set) <br>
@@ -945,7 +932,7 @@ export class Camera2d extends Renderable {
945
932
  */
946
933
  moveTo(x: number, y: number): void;
947
934
  /** @ignore */
948
- updateTarget(): boolean;
935
+ updateTarget(): void;
949
936
  /** @ignore */
950
937
  update(dt: any): boolean;
951
938
  /**
@@ -1092,11 +1079,21 @@ export class CanvasRenderer extends Renderer {
1092
1079
  */
1093
1080
  resetTransform(): void;
1094
1081
  /**
1095
- * 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
+ * - "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>
1096
1092
  * @name setBlendMode
1093
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
1097
1094
  * @memberof CanvasRenderer.prototype
1098
1095
  * @function
1099
- * @param {string} [mode="normal"] blend mode : "normal", "multiply"
1096
+ * @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter, "screen"
1100
1097
  * @param {CanvasRenderingContext2D} [context]
1101
1098
  */
1102
1099
  setBlendMode(mode?: string, context?: CanvasRenderingContext2D): void;
@@ -2065,17 +2062,6 @@ export class Container extends Renderable {
2065
2062
  * @ignore
2066
2063
  */
2067
2064
  _sortY(a: any, b: any): number;
2068
- /**
2069
- * container update function. <br>
2070
- * automatically called by the game manager {@link game}
2071
- * @name update
2072
- * @memberof Container.prototype
2073
- * @function
2074
- * @protected
2075
- * @param {number} dt time since the last update in milliseconds.
2076
- * @returns {boolean} true if the Container is dirty
2077
- */
2078
- protected update(dt: number): boolean;
2079
2065
  /**
2080
2066
  * draw the container. <br>
2081
2067
  * automatically called by the game manager {@link game}
@@ -2140,9 +2126,9 @@ export class Draggable extends Renderable {
2140
2126
  * @name destroy
2141
2127
  * @memberof Draggable
2142
2128
  * @function
2143
- * @private
2129
+ * @ignore
2144
2130
  */
2145
- private destroy;
2131
+ destroy(): void;
2146
2132
  }
2147
2133
  /**
2148
2134
  * @classdesc
@@ -2224,9 +2210,9 @@ export class DropTarget extends Renderable {
2224
2210
  * @name destroy
2225
2211
  * @memberof DropTarget
2226
2212
  * @function
2227
- * @private
2213
+ * @ignore
2228
2214
  */
2229
- private destroy;
2215
+ destroy(): void;
2230
2216
  }
2231
2217
  /**
2232
2218
  * @classdesc
@@ -2879,16 +2865,6 @@ export class ImageLayer extends Renderable {
2879
2865
  * @ignore
2880
2866
  */
2881
2867
  preDraw(renderer: any): void;
2882
- /**
2883
- * draw the ImageLayer. <br>
2884
- * automatically called by the game manager {@link game}
2885
- * @name draw
2886
- * @memberof ImageLayer.prototype
2887
- * @function
2888
- * @protected
2889
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
2890
- */
2891
- protected draw(renderer: CanvasRenderer | WebGLRenderer): void;
2892
2868
  onDeactivateEvent(): void;
2893
2869
  /**
2894
2870
  * Destroy function<br>
@@ -4099,16 +4075,6 @@ export class Particle extends Renderable {
4099
4075
  onlyInViewport: any;
4100
4076
  _deltaInv: number;
4101
4077
  angle: number;
4102
- /**
4103
- * Update the Particle <br>
4104
- * This is automatically called by the game manager {@link game}
4105
- * @name update
4106
- * @memberof Particle
4107
- * @function
4108
- * @ignore
4109
- * @param {number} dt time since the last update in milliseconds
4110
- */
4111
- update(dt: number): boolean;
4112
4078
  /**
4113
4079
  * @ignore
4114
4080
  */
@@ -5282,6 +5248,17 @@ export class Renderable extends Rect {
5282
5248
  * this.tint.setColor(255, 255, 255);
5283
5249
  */
5284
5250
  public tint: Color;
5251
+ /**
5252
+ * the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
5253
+ * @public
5254
+ * @type {string}
5255
+ * @name blendMode
5256
+ * @default "normal"
5257
+ * @see CanvasRenderer#setBlendMode
5258
+ * @see WebGLRenderer#setBlendMode
5259
+ * @memberof Renderable#
5260
+ */
5261
+ public blendMode: string;
5285
5262
  /**
5286
5263
  * The name of the renderable
5287
5264
  * @public
@@ -5465,7 +5442,7 @@ export class Renderable extends Rect {
5465
5442
  * @param {number} dt time since the last update in milliseconds.
5466
5443
  * @returns {boolean} true if the renderable is dirty
5467
5444
  */
5468
- protected update(): boolean;
5445
+ protected update(dt: number): boolean;
5469
5446
  /**
5470
5447
  * update the renderable's bounding rect (private)
5471
5448
  * @ignore
@@ -5513,7 +5490,7 @@ export class Renderable extends Rect {
5513
5490
  * @protected
5514
5491
  * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
5515
5492
  */
5516
- protected draw(): void;
5493
+ protected draw(renderer: CanvasRenderer | WebGLRenderer): void;
5517
5494
  /**
5518
5495
  * restore the rendering context after drawing. <br>
5519
5496
  * automatically called by the game manager {@link game}
@@ -6103,32 +6080,11 @@ export class Sprite extends Renderable {
6103
6080
  * @returns {number} if using number indices. Returns {object} containing frame data if using texture atlas
6104
6081
  */
6105
6082
  getAnimationFrameObjectByIndex(id: number): number;
6106
- /**
6107
- * update function. <br>
6108
- * automatically called by the game manager {@link game}
6109
- * @name update
6110
- * @memberof Sprite.prototype
6111
- * @function
6112
- * @protected
6113
- * @param {number} dt time since the last update in milliseconds.
6114
- * @returns {boolean} true if the Sprite is dirty
6115
- */
6116
- protected update(dt: number): boolean;
6117
6083
  /**
6118
6084
  * Destroy function<br>
6119
6085
  * @ignore
6120
6086
  */
6121
6087
  destroy(): void;
6122
- /**
6123
- * sprite draw. <br>
6124
- * automatically called by the game manager {@link game}
6125
- * @name draw
6126
- * @memberof Sprite.prototype
6127
- * @function
6128
- * @protected
6129
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
6130
- */
6131
- protected draw(renderer: CanvasRenderer | WebGLRenderer): void;
6132
6088
  }
6133
6089
  /**
6134
6090
  * @classdesc
@@ -6961,6 +6917,7 @@ export class Text extends Renderable {
6961
6917
  * @param {number} [settings.lineHeight=1.0] line spacing height
6962
6918
  * @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] anchor point to draw the text at
6963
6919
  * @param {boolean} [settings.offScreenCanvas=false] whether to draw the font to an individual "cache" texture first
6920
+ * @param {number} [settings.wordWrapWidth] the maximum length in CSS pixel for a single segment of text
6964
6921
  * @param {(string|string[])} [settings.text=""] a string, or an array of strings
6965
6922
  * @example
6966
6923
  * var font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
@@ -6976,6 +6933,7 @@ export class Text extends Renderable {
6976
6933
  lineHeight?: number;
6977
6934
  anchorPoint?: Vector2d;
6978
6935
  offScreenCanvas?: boolean;
6936
+ wordWrapWidth?: number;
6979
6937
  text?: (string | string[]);
6980
6938
  });
6981
6939
  /** @ignore */
@@ -6987,7 +6945,6 @@ export class Text extends Renderable {
6987
6945
  * @public
6988
6946
  * @type {number}
6989
6947
  * @default 1
6990
- * @name Text#lineWidth
6991
6948
  */
6992
6949
  public lineWidth: number;
6993
6950
  /**
@@ -6996,7 +6953,6 @@ export class Text extends Renderable {
6996
6953
  * @public
6997
6954
  * @type {string}
6998
6955
  * @default "left"
6999
- * @name Text#textAlign
7000
6956
  */
7001
6957
  public textAlign: string;
7002
6958
  /**
@@ -7005,7 +6961,6 @@ export class Text extends Renderable {
7005
6961
  * @public
7006
6962
  * @type {string}
7007
6963
  * @default "top"
7008
- * @name Text#textBaseline
7009
6964
  */
7010
6965
  public textBaseline: string;
7011
6966
  /**
@@ -7014,7 +6969,6 @@ export class Text extends Renderable {
7014
6969
  * @public
7015
6970
  * @type {number}
7016
6971
  * @default 1.0
7017
- * @name Text#lineHeight
7018
6972
  */
7019
6973
  public lineHeight: number;
7020
6974
  /**
@@ -7024,9 +6978,16 @@ export class Text extends Renderable {
7024
6978
  * @public
7025
6979
  * @type {boolean}
7026
6980
  * @default false
7027
- * @name Text#offScreenCanvas
7028
6981
  */
7029
6982
  public offScreenCanvas: boolean;
6983
+ /**
6984
+ * the maximum length in CSS pixel for a single segment of text.
6985
+ * (use -1 to disable word wrapping)
6986
+ * @public
6987
+ * @type {number}
6988
+ * @default -1
6989
+ */
6990
+ public wordWrapWidth: number;
7030
6991
  /**
7031
6992
  * the text to be displayed
7032
6993
  * @private
@@ -7036,38 +6997,28 @@ export class Text extends Renderable {
7036
6997
  * the font size (in px)
7037
6998
  * @public
7038
6999
  * @type {number}
7039
- * @name fontSize
7040
7000
  * @default 10
7041
- * @memberof Text
7042
7001
  */
7043
7002
  public fontSize: number;
7044
7003
  canvas: HTMLCanvasElement | OffscreenCanvas;
7045
7004
  context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
7005
+ metrics: TextMetrics;
7046
7006
  /** @ignore */
7047
7007
  onDeactivateEvent(): void;
7048
7008
  glTextureUnit: any;
7049
7009
  /**
7050
7010
  * make the font bold
7051
- * @name bold
7052
- * @memberof Text.prototype
7053
- * @function
7054
7011
  * @returns {Text} this object for chaining
7055
7012
  */
7056
7013
  bold(): Text;
7057
7014
  font: any;
7058
7015
  /**
7059
7016
  * make the font italic
7060
- * @name italic
7061
- * @memberof Text.prototype
7062
- * @function
7063
7017
  * @returns {Text} this object for chaining
7064
7018
  */
7065
7019
  italic(): Text;
7066
7020
  /**
7067
7021
  * set the font family and size
7068
- * @name setFont
7069
- * @memberof Text.prototype
7070
- * @function
7071
7022
  * @param {string} font a CSS font name
7072
7023
  * @param {number|string} [size=10] size in px, or size + suffix (px, em, pt)
7073
7024
  * @returns {Text} this object for chaining
@@ -7078,29 +7029,19 @@ export class Text extends Renderable {
7078
7029
  setFont(font: string, size?: number | string): Text;
7079
7030
  /**
7080
7031
  * change the text to be displayed
7081
- * @name setText
7082
- * @memberof Text.prototype
7083
- * @function
7084
7032
  * @param {number|string|string[]} value a string, or an array of strings
7085
7033
  * @returns {Text} this object for chaining
7086
7034
  */
7087
7035
  setText(value?: number | string | string[]): Text;
7088
7036
  /**
7089
7037
  * measure the given text size in pixels
7090
- * @name measureText
7091
- * @memberof Text.prototype
7092
- * @function
7093
7038
  * @param {CanvasRenderer|WebGLRenderer} [renderer] reference to the active renderer
7094
7039
  * @param {string} [text] the text to be measured
7095
- * @param {Rect|Bounds} [ret] a object in which to store the text metrics
7096
- * @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
7040
+ * @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
7097
7041
  */
7098
- measureText(renderer?: CanvasRenderer | WebGLRenderer, text?: string, ret?: Rect | Bounds): TextMetrics;
7042
+ measureText(renderer$1?: CanvasRenderer | WebGLRenderer, text?: string): TextMetrics;
7099
7043
  /**
7100
7044
  * draw a text at the specified coord
7101
- * @name draw
7102
- * @memberof Text.prototype
7103
- * @function
7104
7045
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
7105
7046
  * @param {string} [text]
7106
7047
  * @param {number} [x]
@@ -7112,9 +7053,6 @@ export class Text extends Renderable {
7112
7053
  * draw a stroke text at the specified coord, as defined <br>
7113
7054
  * by the `lineWidth` and `fillStroke` properties. <br>
7114
7055
  * Note : using drawStroke is not recommended for performance reasons
7115
- * @name drawStroke
7116
- * @memberof Text.prototype
7117
- * @function
7118
7056
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
7119
7057
  * @param {string} text
7120
7058
  * @param {number} x
@@ -7124,7 +7062,7 @@ export class Text extends Renderable {
7124
7062
  /**
7125
7063
  * @ignore
7126
7064
  */
7127
- _drawFont(context: any, text: any, x: any, y: any, stroke?: boolean): Bounds;
7065
+ _drawFont(context: any, text: any, x: any, y: any, stroke?: boolean): TextMetrics;
7128
7066
  /**
7129
7067
  * Destroy function
7130
7068
  * @ignore
@@ -8516,6 +8454,14 @@ export class WebGLCompositor {
8516
8454
  * @ignore
8517
8455
  */
8518
8456
  uploadTexture(texture: any, w: any, h: any, b: any, force?: boolean): any;
8457
+ /**
8458
+ * set/change the current projection matrix
8459
+ * @name setProjection
8460
+ * @memberof WebGLCompositor
8461
+ * @function
8462
+ * @param {Matrix3d} matrix
8463
+ */
8464
+ setProjection(matrix: Matrix3d): void;
8519
8465
  /**
8520
8466
  * Select the shader to use for compositing
8521
8467
  * @name useShader
@@ -8670,6 +8616,10 @@ export class WebGLRenderer extends Renderer {
8670
8616
  * @ignore
8671
8617
  */
8672
8618
  _scissorStack: any[];
8619
+ /**
8620
+ * @ignore
8621
+ */
8622
+ _blendStack: any[];
8673
8623
  /**
8674
8624
  * @ignore
8675
8625
  */
@@ -8835,14 +8785,25 @@ export class WebGLRenderer extends Renderer {
8835
8785
  */
8836
8786
  getContext(): WebGLRenderingContext;
8837
8787
  /**
8838
- * set a blend mode for the given context
8788
+ * set a blend mode for the given context. <br>
8789
+ * Supported blend mode between Canvas and WebGL remderer : <br>
8790
+ * - "normal" : this is the default mode and draws new content on top of the existing content <br>
8791
+ * <img src="images/normal-blendmode.png" width="510"/> <br>
8792
+ * - "multiply" : the pixels of the top layer are multiplied with the corresponding pixel of the bottom layer. A darker picture is the result. <br>
8793
+ * <img src="images/multiply-blendmode.png" width="510"/> <br>
8794
+ * - "lighter" : where both content overlap the color is determined by adding color values. <br>
8795
+ * <img src="images/lighter-blendmode.png" width="510"/> <br>
8796
+ * - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
8797
+ * <img src="images/screen-blendmode.png" width="510"/> <br>
8839
8798
  * @name setBlendMode
8799
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
8840
8800
  * @memberof WebGLRenderer.prototype
8841
8801
  * @function
8842
- * @param {string} [mode="normal"] blend mode : "normal", "multiply"
8802
+ * @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter", "screen"
8843
8803
  * @param {WebGLRenderingContext} [gl]
8844
8804
  */
8845
8805
  setBlendMode(mode?: string, gl?: WebGLRenderingContext): void;
8806
+ currentBlendMode: any;
8846
8807
  /**
8847
8808
  * return a reference to the font 2d Context
8848
8809
  * @ignore
@@ -10204,184 +10165,16 @@ export var plugin: any;
10204
10165
  * @namespace plugins
10205
10166
  */
10206
10167
  export var plugins: {};
10207
- export namespace pool {
10208
- /**
10209
- * register an object to the pool. <br>
10210
- * Pooling must be set to true if more than one such objects will be created. <br>
10211
- * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
10212
- * @function pool.register
10213
- * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
10214
- * @param {object} classObj corresponding Class to be instantiated
10215
- * @param {boolean} [recycling=false] enables object recycling for the specified class
10216
- * @example
10217
- * // implement CherryEntity
10218
- * class CherryEntity extends Spritesheet {
10219
- * onResetEvent() {
10220
- * // reset object mutable properties
10221
- * this.lifeBar = 100;
10222
- * }
10223
- * };
10224
- * // add our users defined entities in the object pool and enable object recycling
10225
- * me.pool.register("cherryentity", CherryEntity, true);
10226
- */
10227
- function register(className: string, classObj: any, recycling?: boolean): void;
10228
- /**
10229
- * register an object to the pool. <br>
10230
- * Pooling must be set to true if more than one such objects will be created. <br>
10231
- * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
10232
- * @function pool.register
10233
- * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
10234
- * @param {object} classObj corresponding Class to be instantiated
10235
- * @param {boolean} [recycling=false] enables object recycling for the specified class
10236
- * @example
10237
- * // implement CherryEntity
10238
- * class CherryEntity extends Spritesheet {
10239
- * onResetEvent() {
10240
- * // reset object mutable properties
10241
- * this.lifeBar = 100;
10242
- * }
10243
- * };
10244
- * // add our users defined entities in the object pool and enable object recycling
10245
- * me.pool.register("cherryentity", CherryEntity, true);
10246
- */
10247
- function register(className: string, classObj: any, recycling?: boolean): void;
10248
- /**
10249
- * Pull a new instance of the requested object (if added into the object pool)
10250
- * @function pool.pull
10251
- * @param {string} name as used in {@link pool.register}
10252
- * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
10253
- * @returns {object} the instance of the requested object
10254
- * @example
10255
- * me.pool.register("bullet", BulletEntity, true);
10256
- * me.pool.register("enemy", EnemyEntity, true);
10257
- * // ...
10258
- * // when we need to manually create a new bullet:
10259
- * var bullet = me.pool.pull("bullet", x, y, direction);
10260
- * // ...
10261
- * // params aren't a fixed number
10262
- * // when we need new enemy we can add more params, that the object construct requires:
10263
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
10264
- * // ...
10265
- * // when we want to destroy existing object, the remove
10266
- * // function will ensure the object can then be reallocated later
10267
- * me.game.world.removeChild(enemy);
10268
- * me.game.world.removeChild(bullet);
10269
- */
10270
- function pull(name: string, ...args: any[]): any;
10271
- /**
10272
- * Pull a new instance of the requested object (if added into the object pool)
10273
- * @function pool.pull
10274
- * @param {string} name as used in {@link pool.register}
10275
- * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
10276
- * @returns {object} the instance of the requested object
10277
- * @example
10278
- * me.pool.register("bullet", BulletEntity, true);
10279
- * me.pool.register("enemy", EnemyEntity, true);
10280
- * // ...
10281
- * // when we need to manually create a new bullet:
10282
- * var bullet = me.pool.pull("bullet", x, y, direction);
10283
- * // ...
10284
- * // params aren't a fixed number
10285
- * // when we need new enemy we can add more params, that the object construct requires:
10286
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
10287
- * // ...
10288
- * // when we want to destroy existing object, the remove
10289
- * // function will ensure the object can then be reallocated later
10290
- * me.game.world.removeChild(enemy);
10291
- * me.game.world.removeChild(bullet);
10292
- */
10293
- function pull(name: string, ...args: any[]): any;
10294
- /**
10295
- * purge the object pool from any inactive object <br>
10296
- * Object pooling must be enabled for this function to work<br>
10297
- * note: this will trigger the garbage collector
10298
- * @function pool.purge
10299
- */
10300
- function purge(): void;
10301
- /**
10302
- * purge the object pool from any inactive object <br>
10303
- * Object pooling must be enabled for this function to work<br>
10304
- * note: this will trigger the garbage collector
10305
- * @function pool.purge
10306
- */
10307
- function purge(): void;
10308
- /**
10309
- * Push back an object instance into the object pool <br>
10310
- * Object pooling for the object class must be enabled,
10311
- * and object must have been instantiated using {@link pool#pull},
10312
- * otherwise this function won't work
10313
- * @function pool.push
10314
- * @throws will throw an error if the object cannot be recycled
10315
- * @param {object} obj instance to be recycled
10316
- * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
10317
- * @returns {boolean} true if the object was successfully recycled in the object pool
10318
- */
10319
- function push(obj: any, throwOnError?: boolean): boolean;
10320
- /**
10321
- * Push back an object instance into the object pool <br>
10322
- * Object pooling for the object class must be enabled,
10323
- * and object must have been instantiated using {@link pool#pull},
10324
- * otherwise this function won't work
10325
- * @function pool.push
10326
- * @throws will throw an error if the object cannot be recycled
10327
- * @param {object} obj instance to be recycled
10328
- * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
10329
- * @returns {boolean} true if the object was successfully recycled in the object pool
10330
- */
10331
- function push(obj: any, throwOnError?: boolean): boolean;
10332
- /**
10333
- * Check if an object with the provided name is registered
10334
- * @function pool.exists
10335
- * @param {string} name of the registered object class
10336
- * @returns {boolean} true if the classname is registered
10337
- */
10338
- function exists(name: string): boolean;
10339
- /**
10340
- * Check if an object with the provided name is registered
10341
- * @function pool.exists
10342
- * @param {string} name of the registered object class
10343
- * @returns {boolean} true if the classname is registered
10344
- */
10345
- function exists(name: string): boolean;
10346
- /**
10347
- * Check if an object is poolable
10348
- * (was properly registered with the recycling feature enable)
10349
- * @function pool.poolable
10350
- * @see pool.register
10351
- * @param {object} obj object to be checked
10352
- * @returns {boolean} true if the object is poolable
10353
- * @example
10354
- * if (!me.pool.poolable(myCherryEntity)) {
10355
- * // object was not properly registered
10356
- * }
10357
- */
10358
- function poolable(obj: any): boolean;
10359
- /**
10360
- * Check if an object is poolable
10361
- * (was properly registered with the recycling feature enable)
10362
- * @function pool.poolable
10363
- * @see pool.register
10364
- * @param {object} obj object to be checked
10365
- * @returns {boolean} true if the object is poolable
10366
- * @example
10367
- * if (!me.pool.poolable(myCherryEntity)) {
10368
- * // object was not properly registered
10369
- * }
10370
- */
10371
- function poolable(obj: any): boolean;
10372
- /**
10373
- * returns the amount of object instance currently in the pool
10374
- * @function pool.getInstanceCount
10375
- * @returns {number} amount of object instance
10376
- */
10377
- function getInstanceCount(): number;
10378
- /**
10379
- * returns the amount of object instance currently in the pool
10380
- * @function pool.getInstanceCount
10381
- * @returns {number} amount of object instance
10382
- */
10383
- function getInstanceCount(): number;
10384
- }
10168
+ declare var pooling: Readonly<{
10169
+ __proto__: any;
10170
+ register: typeof register;
10171
+ pull: typeof pull;
10172
+ purge: typeof purge;
10173
+ push: typeof push;
10174
+ exists: typeof exists;
10175
+ poolable: typeof poolable;
10176
+ getInstanceCount: typeof getInstanceCount;
10177
+ }>;
10385
10178
  export namespace save {
10386
10179
  /**
10387
10180
  * Add new keys to localStorage and set them to the given default values if they do not exist
@@ -10452,7 +10245,7 @@ export namespace state {
10452
10245
  const DEFAULT: number;
10453
10246
  const USER: number;
10454
10247
  /**
10455
- * Stop the current screen object.
10248
+ * Stop the current stage.
10456
10249
  * @name stop
10457
10250
  * @memberof state
10458
10251
  * @public
@@ -10461,7 +10254,7 @@ export namespace state {
10461
10254
  */
10462
10255
  function stop(pauseTrack?: boolean): void;
10463
10256
  /**
10464
- * Stop the current screen object.
10257
+ * Stop the current stage.
10465
10258
  * @name stop
10466
10259
  * @memberof state
10467
10260
  * @public
@@ -10470,7 +10263,7 @@ export namespace state {
10470
10263
  */
10471
10264
  function stop(pauseTrack?: boolean): void;
10472
10265
  /**
10473
- * pause the current screen object
10266
+ * pause the current stage
10474
10267
  * @name pause
10475
10268
  * @memberof state
10476
10269
  * @public
@@ -10479,7 +10272,7 @@ export namespace state {
10479
10272
  */
10480
10273
  function pause(music?: boolean): void;
10481
10274
  /**
10482
- * pause the current screen object
10275
+ * pause the current stage
10483
10276
  * @name pause
10484
10277
  * @memberof state
10485
10278
  * @public
@@ -10488,7 +10281,7 @@ export namespace state {
10488
10281
  */
10489
10282
  function pause(music?: boolean): void;
10490
10283
  /**
10491
- * Restart the screen object from a full stop.
10284
+ * Restart the current stage from a full stop.
10492
10285
  * @name restart
10493
10286
  * @memberof state
10494
10287
  * @public
@@ -10497,7 +10290,7 @@ export namespace state {
10497
10290
  */
10498
10291
  function restart(music?: boolean): void;
10499
10292
  /**
10500
- * Restart the screen object from a full stop.
10293
+ * Restart the current stage from a full stop.
10501
10294
  * @name restart
10502
10295
  * @memberof state
10503
10296
  * @public
@@ -10506,7 +10299,7 @@ export namespace state {
10506
10299
  */
10507
10300
  function restart(music?: boolean): void;
10508
10301
  /**
10509
- * resume the screen object
10302
+ * resume the current stage
10510
10303
  * @name resume
10511
10304
  * @memberof state
10512
10305
  * @public
@@ -10515,7 +10308,7 @@ export namespace state {
10515
10308
  */
10516
10309
  function resume(music?: boolean): void;
10517
10310
  /**
10518
- * resume the screen object
10311
+ * resume the current stage
10519
10312
  * @name resume
10520
10313
  * @memberof state
10521
10314
  * @public
@@ -10654,7 +10447,7 @@ export namespace state {
10654
10447
  */
10655
10448
  function set(state: number, stage: Stage, start?: boolean): void;
10656
10449
  /**
10657
- * return a reference to the current screen object<br>
10450
+ * return a reference to the current stage<br>
10658
10451
  * useful to call a object specific method
10659
10452
  * @name current
10660
10453
  * @memberof state
@@ -10664,7 +10457,7 @@ export namespace state {
10664
10457
  */
10665
10458
  function current(): Stage;
10666
10459
  /**
10667
- * return a reference to the current screen object<br>
10460
+ * return a reference to the current stage<br>
10668
10461
  * useful to call a object specific method
10669
10462
  * @name current
10670
10463
  * @memberof state
@@ -10982,6 +10775,51 @@ export var video: Readonly<{
10982
10775
  * @param {string} version the version since when the lass,function or property is deprecated
10983
10776
  */
10984
10777
  export function warning(deprecated: string, replacement: string, version: string): void;
10778
+ /**
10779
+ * @classdesc
10780
+ * a Text Metrics object that contains helper for text manipulation
10781
+ * @augments Bounds
10782
+ */
10783
+ declare class TextMetrics extends Bounds {
10784
+ /**
10785
+ * @param {Text|BitmapText} ancestor the parent object that contains this TextMetrics object
10786
+ */
10787
+ constructor(ancestor: Text | BitmapText);
10788
+ /**
10789
+ * a reference to the parent object that contains this TextMetrics object
10790
+ * @public
10791
+ * @type {Renderable}
10792
+ * @default undefined
10793
+ */
10794
+ public ancestor: Renderable;
10795
+ /**
10796
+ * Returns the height of a segment of inline text in CSS pixels.
10797
+ * @returns {number} the height of a segment of inline text in CSS pixels.
10798
+ */
10799
+ lineHeight(): number;
10800
+ /**
10801
+ * Returns the width of the given segment of inline text in CSS pixels.
10802
+ * @param {string} text the text to be measured
10803
+ * @param {CanvasRenderingContext2D} [context] reference to an active 2d context for canvas rendering
10804
+ * @returns {number} the width of the given segment of inline text in CSS pixels.
10805
+ */
10806
+ lineWidth(text: string, context?: CanvasRenderingContext2D): number;
10807
+ /**
10808
+ * measure the given text size in CSS pixels
10809
+ * @param {string} text the text to be measured
10810
+ * @param {CanvasRenderingContext2D} [context] reference to an active 2d context for canvas rendering
10811
+ * @returns {TextMetrics} this
10812
+ */
10813
+ measureText(text: string, context?: CanvasRenderingContext2D): TextMetrics;
10814
+ /**
10815
+ * wrap the given text based on the given width
10816
+ * @param {string|string[]} text the text to be wrapped
10817
+ * @param {number} width maximum width of one segment of text in css pixel
10818
+ * @param {CanvasRenderingContext2D} [context] reference to an active 2d context for canvas rendering
10819
+ * @returns {string[]} an array of string representing wrapped text
10820
+ */
10821
+ wordWrap(text: string | string[], width: number, context?: CanvasRenderingContext2D): string[];
10822
+ }
10985
10823
  /**
10986
10824
  * @classdesc
10987
10825
  * a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
@@ -12163,6 +12001,107 @@ declare function setGamepadDeadzone(value: number): void;
12163
12001
  * @ignore
12164
12002
  */
12165
12003
  declare function addMapping(id: any, mapping: any): void;
12004
+ /**
12005
+ * This object is used for object pooling - a technique that might speed up your game if used properly.<br>
12006
+ * If some of your classes will be instantiated and removed a lot at a time, it is a
12007
+ * good idea to add the class to this object pool. A separate pool for that class
12008
+ * will be created, which will reuse objects of the class. That way they won't be instantiated
12009
+ * each time you need a new one (slowing your game), but stored into that pool and taking one
12010
+ * already instantiated when you need it.<br><br>
12011
+ * This object is also used by the engine to instantiate objects defined in the map,
12012
+ * which means, that on level loading the engine will try to instantiate every object
12013
+ * found in the map, based on the user defined name in each Object Properties<br>
12014
+ * <img src="images/object_properties.png"/><br>
12015
+ * @namespace pool
12016
+ */
12017
+ /**
12018
+ * register an object to the pool. <br>
12019
+ * Pooling must be set to true if more than one such objects will be created. <br>
12020
+ * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
12021
+ * @function pool.register
12022
+ * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
12023
+ * @param {object} classObj corresponding Class to be instantiated
12024
+ * @param {boolean} [recycling=false] enables object recycling for the specified class
12025
+ * @example
12026
+ * // implement CherryEntity
12027
+ * class CherryEntity extends Spritesheet {
12028
+ * onResetEvent() {
12029
+ * // reset object mutable properties
12030
+ * this.lifeBar = 100;
12031
+ * }
12032
+ * };
12033
+ * // add our users defined entities in the object pool and enable object recycling
12034
+ * me.pool.register("cherryentity", CherryEntity, true);
12035
+ */
12036
+ declare function register(className: string, classObj: object, recycling?: boolean): void;
12037
+ /**
12038
+ * Pull a new instance of the requested object (if added into the object pool)
12039
+ * @function pool.pull
12040
+ * @param {string} name as used in {@link pool.register}
12041
+ * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
12042
+ * @returns {object} the instance of the requested object
12043
+ * @example
12044
+ * me.pool.register("bullet", BulletEntity, true);
12045
+ * me.pool.register("enemy", EnemyEntity, true);
12046
+ * // ...
12047
+ * // when we need to manually create a new bullet:
12048
+ * var bullet = me.pool.pull("bullet", x, y, direction);
12049
+ * // ...
12050
+ * // params aren't a fixed number
12051
+ * // when we need new enemy we can add more params, that the object construct requires:
12052
+ * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
12053
+ * // ...
12054
+ * // when we want to destroy existing object, the remove
12055
+ * // function will ensure the object can then be reallocated later
12056
+ * me.game.world.removeChild(enemy);
12057
+ * me.game.world.removeChild(bullet);
12058
+ */
12059
+ declare function pull(name: string, ...args: any[]): object;
12060
+ /**
12061
+ * purge the object pool from any inactive object <br>
12062
+ * Object pooling must be enabled for this function to work<br>
12063
+ * note: this will trigger the garbage collector
12064
+ * @function pool.purge
12065
+ */
12066
+ declare function purge(): void;
12067
+ /**
12068
+ * Push back an object instance into the object pool <br>
12069
+ * Object pooling for the object class must be enabled,
12070
+ * and object must have been instantiated using {@link pool#pull},
12071
+ * otherwise this function won't work
12072
+ * @function pool.push
12073
+ * @throws will throw an error if the object cannot be recycled
12074
+ * @param {object} obj instance to be recycled
12075
+ * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
12076
+ * @returns {boolean} true if the object was successfully recycled in the object pool
12077
+ */
12078
+ declare function push(obj: object, throwOnError?: boolean): boolean;
12079
+ /**
12080
+ * Check if an object with the provided name is registered
12081
+ * @function pool.exists
12082
+ * @param {string} name of the registered object class
12083
+ * @returns {boolean} true if the classname is registered
12084
+ */
12085
+ declare function exists(name: string): boolean;
12086
+ /**
12087
+ * Check if an object is poolable
12088
+ * (was properly registered with the recycling feature enable)
12089
+ * @function pool.poolable
12090
+ * @see pool.register
12091
+ * @param {object} obj object to be checked
12092
+ * @returns {boolean} true if the object is poolable
12093
+ * @example
12094
+ * if (!me.pool.poolable(myCherryEntity)) {
12095
+ * // object was not properly registered
12096
+ * }
12097
+ */
12098
+ declare function poolable(obj: object): boolean;
12099
+ /**
12100
+ * returns the amount of object instance currently in the pool
12101
+ * @function pool.getInstanceCount
12102
+ * @returns {number} amount of object instance
12103
+ */
12104
+ declare function getInstanceCount(): number;
12166
12105
  declare var agentUtils: Readonly<{
12167
12106
  __proto__: any;
12168
12107
  prefixed: typeof prefixed;
@@ -12455,4 +12394,4 @@ declare function defer(func: Function, thisArg: object, ...args: any[]): number;
12455
12394
  * @returns {Function} the function that will be throttled
12456
12395
  */
12457
12396
  declare function throttle(fn: Function, delay: number, no_trailing: any): Function;
12458
- export { Bounds$1 as Bounds, math as Math, device$1 as device, timer$1 as timer };
12397
+ export { Bounds$1 as Bounds, math as Math, device$1 as device, pooling as pool, timer$1 as timer };