melonjs 10.5.1 → 10.6.1

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 (47) hide show
  1. package/README.md +4 -6
  2. package/dist/melonjs.js +4342 -4182
  3. package/dist/melonjs.min.js +14 -14
  4. package/dist/melonjs.module.d.ts +250 -267
  5. package/dist/melonjs.module.js +4752 -4606
  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/imagelayer.js +1 -1
  32. package/src/renderable/nineslicesprite.js +6 -3
  33. package/src/renderable/renderable.js +18 -1
  34. package/src/renderable/sprite.js +2 -2
  35. package/src/state/state.js +6 -6
  36. package/src/system/pooling.js +150 -155
  37. package/src/text/bitmaptext.js +35 -91
  38. package/src/text/text.js +82 -145
  39. package/src/text/textmetrics.js +168 -0
  40. package/src/text/textstyle.js +14 -0
  41. package/src/video/canvas/canvas_renderer.js +21 -5
  42. package/src/video/renderer.js +1 -3
  43. package/src/video/texture.js +1 -1
  44. package/src/video/webgl/buffer/vertex.js +0 -3
  45. package/src/video/webgl/glshader.js +0 -2
  46. package/src/video/webgl/webgl_compositor.js +11 -0
  47. 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,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
+ * - "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, "screen"
1104
1097
  * @param {CanvasRenderingContext2D} [context]
1105
1098
  */
1106
1099
  setBlendMode(mode?: string, context?: CanvasRenderingContext2D): void;
@@ -5255,6 +5248,17 @@ export class Renderable extends Rect {
5255
5248
  * this.tint.setColor(255, 255, 255);
5256
5249
  */
5257
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;
5258
5262
  /**
5259
5263
  * The name of the renderable
5260
5264
  * @public
@@ -6913,6 +6917,7 @@ export class Text extends Renderable {
6913
6917
  * @param {number} [settings.lineHeight=1.0] line spacing height
6914
6918
  * @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] anchor point to draw the text at
6915
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
6916
6921
  * @param {(string|string[])} [settings.text=""] a string, or an array of strings
6917
6922
  * @example
6918
6923
  * var font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
@@ -6928,6 +6933,7 @@ export class Text extends Renderable {
6928
6933
  lineHeight?: number;
6929
6934
  anchorPoint?: Vector2d;
6930
6935
  offScreenCanvas?: boolean;
6936
+ wordWrapWidth?: number;
6931
6937
  text?: (string | string[]);
6932
6938
  });
6933
6939
  /** @ignore */
@@ -6939,7 +6945,6 @@ export class Text extends Renderable {
6939
6945
  * @public
6940
6946
  * @type {number}
6941
6947
  * @default 1
6942
- * @name Text#lineWidth
6943
6948
  */
6944
6949
  public lineWidth: number;
6945
6950
  /**
@@ -6948,7 +6953,6 @@ export class Text extends Renderable {
6948
6953
  * @public
6949
6954
  * @type {string}
6950
6955
  * @default "left"
6951
- * @name Text#textAlign
6952
6956
  */
6953
6957
  public textAlign: string;
6954
6958
  /**
@@ -6957,7 +6961,6 @@ export class Text extends Renderable {
6957
6961
  * @public
6958
6962
  * @type {string}
6959
6963
  * @default "top"
6960
- * @name Text#textBaseline
6961
6964
  */
6962
6965
  public textBaseline: string;
6963
6966
  /**
@@ -6966,7 +6969,6 @@ export class Text extends Renderable {
6966
6969
  * @public
6967
6970
  * @type {number}
6968
6971
  * @default 1.0
6969
- * @name Text#lineHeight
6970
6972
  */
6971
6973
  public lineHeight: number;
6972
6974
  /**
@@ -6976,9 +6978,16 @@ export class Text extends Renderable {
6976
6978
  * @public
6977
6979
  * @type {boolean}
6978
6980
  * @default false
6979
- * @name Text#offScreenCanvas
6980
6981
  */
6981
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;
6982
6991
  /**
6983
6992
  * the text to be displayed
6984
6993
  * @private
@@ -6988,38 +6997,28 @@ export class Text extends Renderable {
6988
6997
  * the font size (in px)
6989
6998
  * @public
6990
6999
  * @type {number}
6991
- * @name fontSize
6992
7000
  * @default 10
6993
- * @memberof Text
6994
7001
  */
6995
7002
  public fontSize: number;
6996
7003
  canvas: HTMLCanvasElement | OffscreenCanvas;
6997
7004
  context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
7005
+ metrics: TextMetrics;
6998
7006
  /** @ignore */
6999
7007
  onDeactivateEvent(): void;
7000
7008
  glTextureUnit: any;
7001
7009
  /**
7002
7010
  * make the font bold
7003
- * @name bold
7004
- * @memberof Text.prototype
7005
- * @function
7006
7011
  * @returns {Text} this object for chaining
7007
7012
  */
7008
7013
  bold(): Text;
7009
7014
  font: any;
7010
7015
  /**
7011
7016
  * make the font italic
7012
- * @name italic
7013
- * @memberof Text.prototype
7014
- * @function
7015
7017
  * @returns {Text} this object for chaining
7016
7018
  */
7017
7019
  italic(): Text;
7018
7020
  /**
7019
7021
  * set the font family and size
7020
- * @name setFont
7021
- * @memberof Text.prototype
7022
- * @function
7023
7022
  * @param {string} font a CSS font name
7024
7023
  * @param {number|string} [size=10] size in px, or size + suffix (px, em, pt)
7025
7024
  * @returns {Text} this object for chaining
@@ -7030,33 +7029,19 @@ export class Text extends Renderable {
7030
7029
  setFont(font: string, size?: number | string): Text;
7031
7030
  /**
7032
7031
  * change the text to be displayed
7033
- * @name setText
7034
- * @memberof Text.prototype
7035
- * @function
7036
7032
  * @param {number|string|string[]} value a string, or an array of strings
7037
7033
  * @returns {Text} this object for chaining
7038
7034
  */
7039
7035
  setText(value?: number | string | string[]): Text;
7040
7036
  /**
7041
7037
  * measure the given text size in pixels
7042
- * @name measureText
7043
- * @memberof Text.prototype
7044
- * @function
7045
7038
  * @param {CanvasRenderer|WebGLRenderer} [renderer] reference to the active renderer
7046
7039
  * @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
7040
+ * @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
7049
7041
  */
7050
- measureText(renderer?: CanvasRenderer | WebGLRenderer, text?: string, ret?: Rect | Bounds): TextMetrics;
7051
- /**
7052
- * @ignore
7053
- */
7054
- update(): boolean;
7042
+ measureText(renderer$1?: CanvasRenderer | WebGLRenderer, text?: string): TextMetrics;
7055
7043
  /**
7056
7044
  * draw a text at the specified coord
7057
- * @name draw
7058
- * @memberof Text.prototype
7059
- * @function
7060
7045
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
7061
7046
  * @param {string} [text]
7062
7047
  * @param {number} [x]
@@ -7068,9 +7053,6 @@ export class Text extends Renderable {
7068
7053
  * draw a stroke text at the specified coord, as defined <br>
7069
7054
  * by the `lineWidth` and `fillStroke` properties. <br>
7070
7055
  * Note : using drawStroke is not recommended for performance reasons
7071
- * @name drawStroke
7072
- * @memberof Text.prototype
7073
- * @function
7074
7056
  * @param {CanvasRenderer|WebGLRenderer} renderer Reference to the destination renderer instance
7075
7057
  * @param {string} text
7076
7058
  * @param {number} x
@@ -7080,7 +7062,7 @@ export class Text extends Renderable {
7080
7062
  /**
7081
7063
  * @ignore
7082
7064
  */
7083
- _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;
7084
7066
  /**
7085
7067
  * Destroy function
7086
7068
  * @ignore
@@ -8472,6 +8454,14 @@ export class WebGLCompositor {
8472
8454
  * @ignore
8473
8455
  */
8474
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;
8475
8465
  /**
8476
8466
  * Select the shader to use for compositing
8477
8467
  * @name useShader
@@ -8626,6 +8616,10 @@ export class WebGLRenderer extends Renderer {
8626
8616
  * @ignore
8627
8617
  */
8628
8618
  _scissorStack: any[];
8619
+ /**
8620
+ * @ignore
8621
+ */
8622
+ _blendStack: any[];
8629
8623
  /**
8630
8624
  * @ignore
8631
8625
  */
@@ -8791,14 +8785,25 @@ export class WebGLRenderer extends Renderer {
8791
8785
  */
8792
8786
  getContext(): WebGLRenderingContext;
8793
8787
  /**
8794
- * 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>
8795
8798
  * @name setBlendMode
8799
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
8796
8800
  * @memberof WebGLRenderer.prototype
8797
8801
  * @function
8798
- * @param {string} [mode="normal"] blend mode : "normal", "multiply"
8802
+ * @param {string} [mode="normal"] blend mode : "normal", "multiply", "lighter", "screen"
8799
8803
  * @param {WebGLRenderingContext} [gl]
8800
8804
  */
8801
8805
  setBlendMode(mode?: string, gl?: WebGLRenderingContext): void;
8806
+ currentBlendMode: any;
8802
8807
  /**
8803
8808
  * return a reference to the font 2d Context
8804
8809
  * @ignore
@@ -10160,184 +10165,16 @@ export var plugin: any;
10160
10165
  * @namespace plugins
10161
10166
  */
10162
10167
  export var plugins: {};
10163
- export namespace pool {
10164
- /**
10165
- * register an object to the pool. <br>
10166
- * Pooling must be set to true if more than one such objects will be created. <br>
10167
- * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
10168
- * @function pool.register
10169
- * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
10170
- * @param {object} classObj corresponding Class to be instantiated
10171
- * @param {boolean} [recycling=false] enables object recycling for the specified class
10172
- * @example
10173
- * // implement CherryEntity
10174
- * class CherryEntity extends Spritesheet {
10175
- * onResetEvent() {
10176
- * // reset object mutable properties
10177
- * this.lifeBar = 100;
10178
- * }
10179
- * };
10180
- * // add our users defined entities in the object pool and enable object recycling
10181
- * me.pool.register("cherryentity", CherryEntity, true);
10182
- */
10183
- function register(className: string, classObj: any, recycling?: boolean): void;
10184
- /**
10185
- * register an object to the pool. <br>
10186
- * Pooling must be set to true if more than one such objects will be created. <br>
10187
- * (Note: for an object to be poolable, it must implements a `onResetEvent` method)
10188
- * @function pool.register
10189
- * @param {string} className as defined in the Name field of the Object Properties (in Tiled)
10190
- * @param {object} classObj corresponding Class to be instantiated
10191
- * @param {boolean} [recycling=false] enables object recycling for the specified class
10192
- * @example
10193
- * // implement CherryEntity
10194
- * class CherryEntity extends Spritesheet {
10195
- * onResetEvent() {
10196
- * // reset object mutable properties
10197
- * this.lifeBar = 100;
10198
- * }
10199
- * };
10200
- * // add our users defined entities in the object pool and enable object recycling
10201
- * me.pool.register("cherryentity", CherryEntity, true);
10202
- */
10203
- function register(className: string, classObj: any, recycling?: boolean): void;
10204
- /**
10205
- * Pull a new instance of the requested object (if added into the object pool)
10206
- * @function pool.pull
10207
- * @param {string} name as used in {@link pool.register}
10208
- * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
10209
- * @returns {object} the instance of the requested object
10210
- * @example
10211
- * me.pool.register("bullet", BulletEntity, true);
10212
- * me.pool.register("enemy", EnemyEntity, true);
10213
- * // ...
10214
- * // when we need to manually create a new bullet:
10215
- * var bullet = me.pool.pull("bullet", x, y, direction);
10216
- * // ...
10217
- * // params aren't a fixed number
10218
- * // when we need new enemy we can add more params, that the object construct requires:
10219
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
10220
- * // ...
10221
- * // when we want to destroy existing object, the remove
10222
- * // function will ensure the object can then be reallocated later
10223
- * me.game.world.removeChild(enemy);
10224
- * me.game.world.removeChild(bullet);
10225
- */
10226
- function pull(name: string, ...args: any[]): any;
10227
- /**
10228
- * Pull a new instance of the requested object (if added into the object pool)
10229
- * @function pool.pull
10230
- * @param {string} name as used in {@link pool.register}
10231
- * @param {object} [...arguments] arguments to be passed when instantiating/reinitializing the object
10232
- * @returns {object} the instance of the requested object
10233
- * @example
10234
- * me.pool.register("bullet", BulletEntity, true);
10235
- * me.pool.register("enemy", EnemyEntity, true);
10236
- * // ...
10237
- * // when we need to manually create a new bullet:
10238
- * var bullet = me.pool.pull("bullet", x, y, direction);
10239
- * // ...
10240
- * // params aren't a fixed number
10241
- * // when we need new enemy we can add more params, that the object construct requires:
10242
- * var enemy = me.pool.pull("enemy", x, y, direction, speed, power, life);
10243
- * // ...
10244
- * // when we want to destroy existing object, the remove
10245
- * // function will ensure the object can then be reallocated later
10246
- * me.game.world.removeChild(enemy);
10247
- * me.game.world.removeChild(bullet);
10248
- */
10249
- function pull(name: string, ...args: any[]): any;
10250
- /**
10251
- * purge the object pool from any inactive object <br>
10252
- * Object pooling must be enabled for this function to work<br>
10253
- * note: this will trigger the garbage collector
10254
- * @function pool.purge
10255
- */
10256
- function purge(): void;
10257
- /**
10258
- * purge the object pool from any inactive object <br>
10259
- * Object pooling must be enabled for this function to work<br>
10260
- * note: this will trigger the garbage collector
10261
- * @function pool.purge
10262
- */
10263
- function purge(): void;
10264
- /**
10265
- * Push back an object instance into the object pool <br>
10266
- * Object pooling for the object class must be enabled,
10267
- * and object must have been instantiated using {@link pool#pull},
10268
- * otherwise this function won't work
10269
- * @function pool.push
10270
- * @throws will throw an error if the object cannot be recycled
10271
- * @param {object} obj instance to be recycled
10272
- * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
10273
- * @returns {boolean} true if the object was successfully recycled in the object pool
10274
- */
10275
- function push(obj: any, throwOnError?: boolean): boolean;
10276
- /**
10277
- * Push back an object instance into the object pool <br>
10278
- * Object pooling for the object class must be enabled,
10279
- * and object must have been instantiated using {@link pool#pull},
10280
- * otherwise this function won't work
10281
- * @function pool.push
10282
- * @throws will throw an error if the object cannot be recycled
10283
- * @param {object} obj instance to be recycled
10284
- * @param {boolean} [throwOnError=true] throw an exception if the object cannot be recycled
10285
- * @returns {boolean} true if the object was successfully recycled in the object pool
10286
- */
10287
- function push(obj: any, throwOnError?: boolean): boolean;
10288
- /**
10289
- * Check if an object with the provided name is registered
10290
- * @function pool.exists
10291
- * @param {string} name of the registered object class
10292
- * @returns {boolean} true if the classname is registered
10293
- */
10294
- function exists(name: string): boolean;
10295
- /**
10296
- * Check if an object with the provided name is registered
10297
- * @function pool.exists
10298
- * @param {string} name of the registered object class
10299
- * @returns {boolean} true if the classname is registered
10300
- */
10301
- function exists(name: string): boolean;
10302
- /**
10303
- * Check if an object is poolable
10304
- * (was properly registered with the recycling feature enable)
10305
- * @function pool.poolable
10306
- * @see pool.register
10307
- * @param {object} obj object to be checked
10308
- * @returns {boolean} true if the object is poolable
10309
- * @example
10310
- * if (!me.pool.poolable(myCherryEntity)) {
10311
- * // object was not properly registered
10312
- * }
10313
- */
10314
- function poolable(obj: any): boolean;
10315
- /**
10316
- * Check if an object is poolable
10317
- * (was properly registered with the recycling feature enable)
10318
- * @function pool.poolable
10319
- * @see pool.register
10320
- * @param {object} obj object to be checked
10321
- * @returns {boolean} true if the object is poolable
10322
- * @example
10323
- * if (!me.pool.poolable(myCherryEntity)) {
10324
- * // object was not properly registered
10325
- * }
10326
- */
10327
- function poolable(obj: any): boolean;
10328
- /**
10329
- * returns the amount of object instance currently in the pool
10330
- * @function pool.getInstanceCount
10331
- * @returns {number} amount of object instance
10332
- */
10333
- function getInstanceCount(): number;
10334
- /**
10335
- * returns the amount of object instance currently in the pool
10336
- * @function pool.getInstanceCount
10337
- * @returns {number} amount of object instance
10338
- */
10339
- function getInstanceCount(): number;
10340
- }
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
+ }>;
10341
10178
  export namespace save {
10342
10179
  /**
10343
10180
  * Add new keys to localStorage and set them to the given default values if they do not exist
@@ -10408,7 +10245,7 @@ export namespace state {
10408
10245
  const DEFAULT: number;
10409
10246
  const USER: number;
10410
10247
  /**
10411
- * Stop the current screen object.
10248
+ * Stop the current stage.
10412
10249
  * @name stop
10413
10250
  * @memberof state
10414
10251
  * @public
@@ -10417,7 +10254,7 @@ export namespace state {
10417
10254
  */
10418
10255
  function stop(pauseTrack?: boolean): void;
10419
10256
  /**
10420
- * Stop the current screen object.
10257
+ * Stop the current stage.
10421
10258
  * @name stop
10422
10259
  * @memberof state
10423
10260
  * @public
@@ -10426,7 +10263,7 @@ export namespace state {
10426
10263
  */
10427
10264
  function stop(pauseTrack?: boolean): void;
10428
10265
  /**
10429
- * pause the current screen object
10266
+ * pause the current stage
10430
10267
  * @name pause
10431
10268
  * @memberof state
10432
10269
  * @public
@@ -10435,7 +10272,7 @@ export namespace state {
10435
10272
  */
10436
10273
  function pause(music?: boolean): void;
10437
10274
  /**
10438
- * pause the current screen object
10275
+ * pause the current stage
10439
10276
  * @name pause
10440
10277
  * @memberof state
10441
10278
  * @public
@@ -10444,7 +10281,7 @@ export namespace state {
10444
10281
  */
10445
10282
  function pause(music?: boolean): void;
10446
10283
  /**
10447
- * Restart the screen object from a full stop.
10284
+ * Restart the current stage from a full stop.
10448
10285
  * @name restart
10449
10286
  * @memberof state
10450
10287
  * @public
@@ -10453,7 +10290,7 @@ export namespace state {
10453
10290
  */
10454
10291
  function restart(music?: boolean): void;
10455
10292
  /**
10456
- * Restart the screen object from a full stop.
10293
+ * Restart the current stage from a full stop.
10457
10294
  * @name restart
10458
10295
  * @memberof state
10459
10296
  * @public
@@ -10462,7 +10299,7 @@ export namespace state {
10462
10299
  */
10463
10300
  function restart(music?: boolean): void;
10464
10301
  /**
10465
- * resume the screen object
10302
+ * resume the current stage
10466
10303
  * @name resume
10467
10304
  * @memberof state
10468
10305
  * @public
@@ -10471,7 +10308,7 @@ export namespace state {
10471
10308
  */
10472
10309
  function resume(music?: boolean): void;
10473
10310
  /**
10474
- * resume the screen object
10311
+ * resume the current stage
10475
10312
  * @name resume
10476
10313
  * @memberof state
10477
10314
  * @public
@@ -10610,7 +10447,7 @@ export namespace state {
10610
10447
  */
10611
10448
  function set(state: number, stage: Stage, start?: boolean): void;
10612
10449
  /**
10613
- * return a reference to the current screen object<br>
10450
+ * return a reference to the current stage<br>
10614
10451
  * useful to call a object specific method
10615
10452
  * @name current
10616
10453
  * @memberof state
@@ -10620,7 +10457,7 @@ export namespace state {
10620
10457
  */
10621
10458
  function current(): Stage;
10622
10459
  /**
10623
- * return a reference to the current screen object<br>
10460
+ * return a reference to the current stage<br>
10624
10461
  * useful to call a object specific method
10625
10462
  * @name current
10626
10463
  * @memberof state
@@ -10938,6 +10775,51 @@ export var video: Readonly<{
10938
10775
  * @param {string} version the version since when the lass,function or property is deprecated
10939
10776
  */
10940
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
+ }
10941
10823
  /**
10942
10824
  * @classdesc
10943
10825
  * a bound object contains methods for creating and manipulating axis-aligned bounding boxes (AABB).
@@ -12119,6 +12001,107 @@ declare function setGamepadDeadzone(value: number): void;
12119
12001
  * @ignore
12120
12002
  */
12121
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;
12122
12105
  declare var agentUtils: Readonly<{
12123
12106
  __proto__: any;
12124
12107
  prefixed: typeof prefixed;
@@ -12411,4 +12394,4 @@ declare function defer(func: Function, thisArg: object, ...args: any[]): number;
12411
12394
  * @returns {Function} the function that will be throttled
12412
12395
  */
12413
12396
  declare function throttle(fn: Function, delay: number, no_trailing: any): Function;
12414
- 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 };