melonjs 10.11.0 → 10.12.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.
@@ -188,23 +188,21 @@ class Entity extends Renderable {
188
188
  }
189
189
 
190
190
  /**
191
- * object draw<br>
192
- * not to be called by the end user<br>
193
- * called by the game manager on each game loop
191
+ * draw this entity (automatically called by melonJS)
194
192
  * @name draw
195
193
  * @memberof Entity
196
194
  * @protected
197
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
198
- * @param {Rect} rect region to draw
195
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
196
+ * @param {Camera2d} [viewport] the viewport to (re)draw
199
197
  */
200
- draw(renderer, rect) {
198
+ draw(renderer, viewport) {
201
199
  var renderable = this.renderable;
202
200
  if (renderable instanceof Renderable) {
203
201
  // predraw (apply transforms)
204
202
  renderable.preDraw(renderer);
205
203
 
206
204
  // draw the object
207
- renderable.draw(renderer, rect);
205
+ renderable.draw(renderer, viewport);
208
206
 
209
207
  // postdraw (clean-up);
210
208
  renderable.postDraw(renderer);
@@ -154,7 +154,7 @@ class Ellipse {
154
154
  * @param {Matrix2d} matrix the transformation matrix
155
155
  * @returns {Polygon} Reference to this object for method chaining
156
156
  */
157
- transform(/* m */) {
157
+ transform(matrix) { // eslint-disable-line no-unused-vars
158
158
  // TODO
159
159
  return this;
160
160
  }
@@ -164,10 +164,10 @@ class Path2D {
164
164
  * adds a circular arc to the path with the given control points and radius, connected to the previous point by a straight line.
165
165
  * @name arcTo
166
166
  * @memberof Path2D
167
- * @param {number} x the x-axis coordinate of the first control point.
168
- * @param {number} y the y-axis coordinate of the first control point.
169
- * @param {number} x the x-axis coordinate of the second control point.
170
- * @param {number} y the y-axis coordinate of the second control point.
167
+ * @param {number} x1 the x-axis coordinate of the first control point.
168
+ * @param {number} y1 the y-axis coordinate of the first control point.
169
+ * @param {number} x2 the x-axis coordinate of the second control point.
170
+ * @param {number} y2 the y-axis coordinate of the second control point.
171
171
  * @param {number} radius the arc's radius. Must be positive.
172
172
  */
173
173
  arcTo(x1, y1, x2, y2, radius) {
@@ -10,10 +10,9 @@ import pool from "./../system/pooling.js";
10
10
  * (which means that all angles are less than 180 degrees), as described here below : <br>
11
11
  * <center><img src="images/convex_polygon.png"/></center><br>
12
12
  *
13
- * A polygon's `winding` is clockwise iff its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
13
+ * A polygon's `winding` is clockwise if its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding.
14
14
  */
15
15
  class Polygon {
16
-
17
16
  /**
18
17
  * @param {number} x origin point of the Polygon
19
18
  * @param {number} y origin point of the Polygon
@@ -176,7 +176,7 @@ class Rect extends Polygon {
176
176
  * @name centerOn
177
177
  * @memberof Rect
178
178
  * @param {number} x the x coordinate around which to center this rectangle
179
- * @param {number} x the y coordinate around which to center this rectangle
179
+ * @param {number} y the y coordinate around which to center this rectangle
180
180
  * @returns {Rect} this rectangle
181
181
  */
182
182
  centerOn(x, y) {
@@ -13,6 +13,7 @@ import { world } from "./../game.js";
13
13
  /**
14
14
  * @classdesc
15
15
  * a Generic Physic Body Object with some physic properties and behavior functionality, to as a member of a Renderable.
16
+ * @see Renderable.body
16
17
  */
17
18
  class Body {
18
19
  /**
@@ -438,7 +439,7 @@ class Body {
438
439
 
439
440
  /**
440
441
  * the built-in function to solve the collision response
441
- * @param {object} response the collision response object (see {@link collision.ResponseObject})
442
+ * @param {object} response the collision response object (see {@link ResponseObject})
442
443
  */
443
444
  respondToCollision(response) {
444
445
  // the overlap vector
@@ -573,7 +574,6 @@ class Body {
573
574
  * cap the body velocity (body.maxVel property) to the specified value<br>
574
575
  * @param {number} x max velocity on x axis
575
576
  * @param {number} y max velocity on y axis
576
- * @protected
577
577
  */
578
578
  setMaxVelocity(x, y) {
579
579
  this.maxVel.x = x;
@@ -584,7 +584,6 @@ class Body {
584
584
  * set the body default friction
585
585
  * @param {number} x horizontal friction
586
586
  * @param {number} y vertical friction
587
- * @protected
588
587
  */
589
588
  setFriction(x = 0, y = 0) {
590
589
  this.friction.x = x;
@@ -692,7 +691,7 @@ class Body {
692
691
  pool.push(this.friction);
693
692
  pool.push(this.maxVel);
694
693
  this.shapes.forEach((shape) => {
695
- pool.push(shape);
694
+ pool.push(shape, false);
696
695
  });
697
696
 
698
697
  // set to undefined
@@ -1,4 +1,4 @@
1
- import { rayCast, globalResponse } from "./detector.js";
1
+ import { rayCast } from "./detector.js";
2
2
 
3
3
  /**
4
4
  * Collision detection (and projection-based collision response) of 2D shapes.<br>
@@ -91,17 +91,6 @@ var collision = {
91
91
  ALL_OBJECT : 0xFFFFFFFF // all objects
92
92
  },
93
93
 
94
-
95
- /**
96
- * a global instance of a response object used for collision detection <br>
97
- * this object will be reused amongst collision detection call if not user-defined response is specified
98
- * @name response
99
- * @memberof collision
100
- * @public
101
- * @type {collision.ResponseObject}
102
- */
103
- response : globalResponse,
104
-
105
94
  /**
106
95
  * Checks for object colliding with the given line
107
96
  * @name rayCast
@@ -1,9 +1,10 @@
1
1
  import * as SAT from "./sat.js";
2
+ import ResponseObject from "./response.js";
2
3
  import Vector2d from "./../math/vector2.js";
3
4
  import { world } from "./../game.js";
4
5
 
5
6
  // a dummy object when using Line for raycasting
6
- var dummyObj = {
7
+ let dummyObj = {
7
8
  pos : new Vector2d(0, 0),
8
9
  ancestor : {
9
10
  _absPos : new Vector2d(0, 0),
@@ -13,6 +14,9 @@ var dummyObj = {
13
14
  }
14
15
  };
15
16
 
17
+ // the global response object used for collisions
18
+ let globalResponse = new ResponseObject();
19
+
16
20
  /**
17
21
  * a function used to determine if two objects should collide (based on both respective objects collision mask and type).<br>
18
22
  * you can redefine this function if you need any specific rules over what should collide with what.
@@ -33,64 +37,14 @@ function shouldCollide(a, b) {
33
37
  );
34
38
  };
35
39
 
36
- /**
37
- * @classdesc
38
- * An object representing the result of an intersection.
39
- * @property {Renderable} a The first object participating in the intersection
40
- * @property {Renderable} b The second object participating in the intersection
41
- * @property {number} overlap Magnitude of the overlap on the shortest colliding axis
42
- * @property {Vector2d} overlapV The overlap vector (i.e. `overlapN.scale(overlap, overlap)`). If this vector is subtracted from the position of a, a and b will no longer be colliding
43
- * @property {Vector2d} overlapN The shortest colliding axis (unit-vector)
44
- * @property {boolean} aInB Whether the first object is entirely inside the second
45
- * @property {boolean} bInA Whether the second object is entirely inside the first
46
- * @property {number} indexShapeA The index of the colliding shape for the object a body
47
- * @property {number} indexShapeB The index of the colliding shape for the object b body
48
- * @name ResponseObject
49
- * @memberof collision
50
- * @public
51
- */
52
- class ResponseObject {
53
- constructor() {
54
- this.a = null;
55
- this.b = null;
56
- this.overlapN = new Vector2d();
57
- this.overlapV = new Vector2d();
58
- this.aInB = true;
59
- this.bInA = true;
60
- this.indexShapeA = -1;
61
- this.indexShapeB = -1;
62
- this.overlap = Number.MAX_VALUE;
63
- }
64
-
65
- /**
66
- * Set some values of the response back to their defaults. <br>
67
- * Call this between tests if you are going to reuse a single <br>
68
- * Response object for multiple intersection tests <br>
69
- * (recommended as it will avoid allocating extra memory) <br>
70
- * @name clear
71
- * @memberof collision.ResponseObject
72
- * @public
73
- * @returns {object} this object for chaining
74
- */
75
- clear () {
76
- this.aInB = true;
77
- this.bInA = true;
78
- this.overlap = Number.MAX_VALUE;
79
- this.indexShapeA = -1;
80
- this.indexShapeB = -1;
81
- return this;
82
- }
83
- }
84
40
 
85
- // @ignore
86
- export var globalResponse = new ResponseObject();
87
41
 
88
42
  /**
89
43
  * find all the collisions for the specified object
90
44
  * @name collisionCheck
91
45
  * @ignore
92
46
  * @param {Renderable} objA object to be tested for collision
93
- * @param {collision.ResponseObject} [response=collision.response] a user defined response object that will be populated if they intersect.
47
+ * @param {ResponseObject} [response] a user defined response object that will be populated if they intersect.
94
48
  * @returns {boolean} in case of collision, false otherwise
95
49
  */
96
50
  export function collisionCheck(objA, response = globalResponse) {
@@ -0,0 +1,48 @@
1
+ import Vector2d from "./../math/vector2.js";
2
+
3
+ /**
4
+ * @classdesc
5
+ * An object representing the result of an intersection.
6
+ * @property {Renderable} a The first object participating in the intersection
7
+ * @property {Renderable} b The second object participating in the intersection
8
+ * @property {number} overlap Magnitude of the overlap on the shortest colliding axis
9
+ * @property {Vector2d} overlapV The overlap vector (i.e. `overlapN.scale(overlap, overlap)`). If this vector is subtracted from the position of a, a and b will no longer be colliding
10
+ * @property {Vector2d} overlapN The shortest colliding axis (unit-vector)
11
+ * @property {boolean} aInB Whether the first object is entirely inside the second
12
+ * @property {boolean} bInA Whether the second object is entirely inside the first
13
+ * @property {number} indexShapeA The index of the colliding shape for the object a body
14
+ * @property {number} indexShapeB The index of the colliding shape for the object b body
15
+ * @name ResponseObject
16
+ * @public
17
+ */
18
+ export default class ResponseObject {
19
+ constructor() {
20
+ this.a = null;
21
+ this.b = null;
22
+ this.overlapN = new Vector2d();
23
+ this.overlapV = new Vector2d();
24
+ this.aInB = true;
25
+ this.bInA = true;
26
+ this.indexShapeA = -1;
27
+ this.indexShapeB = -1;
28
+ this.overlap = Number.MAX_VALUE;
29
+ }
30
+
31
+ /**
32
+ * Set some values of the response back to their defaults. <br>
33
+ * Call this between tests if you are going to reuse a single <br>
34
+ * Response object for multiple intersection tests <br>
35
+ * (recommended as it will avoid allocating extra memory) <br>
36
+ * @name clear
37
+ * @public
38
+ * @returns {object} this object for chaining
39
+ */
40
+ clear () {
41
+ this.aInB = true;
42
+ this.bInA = true;
43
+ this.overlap = Number.MAX_VALUE;
44
+ this.indexShapeA = -1;
45
+ this.indexShapeB = -1;
46
+ return this;
47
+ }
48
+ }
@@ -458,7 +458,7 @@ export function testPolygonEllipse(a, polyA, b, ellipseB, response) {
458
458
  */
459
459
  export function testEllipsePolygon(a, ellipseA, b, polyB, response) {
460
460
  // Test the polygon against the circle.
461
- var result = this.testPolygonEllipse(b, polyB, a, ellipseA, response);
461
+ var result = testPolygonEllipse(b, polyB, a, ellipseA, response);
462
462
  if (result && response) {
463
463
  // Swap A and B in the response.
464
464
  var resa = response.a;
@@ -121,7 +121,7 @@ class GUI_Object extends Sprite {
121
121
  * @param {Pointer} event the event object
122
122
  * @returns {boolean} return false if we need to stop propagating the event
123
123
  */
124
- onClick(/* event */) {
124
+ onClick(event) { // eslint-disable-line no-unused-vars
125
125
  return false;
126
126
  }
127
127
 
@@ -142,7 +142,9 @@ class GUI_Object extends Sprite {
142
142
  * @public
143
143
  * @param {Pointer} event the event object
144
144
  */
145
- onOver(/* event */) {}
145
+ onOver(event) { // eslint-disable-line no-unused-vars
146
+ // to be extended
147
+ }
146
148
 
147
149
  /**
148
150
  * function callback for the pointerLeave event
@@ -162,8 +164,8 @@ class GUI_Object extends Sprite {
162
164
  * @public
163
165
  * @param {Pointer} event the event object
164
166
  */
165
- onOut(/* event */) {
166
-
167
+ onOut(event) { // eslint-disable-line no-unused-vars
168
+ // to be extended
167
169
  }
168
170
 
169
171
  /**
@@ -1,5 +1,4 @@
1
1
  import pool from "./../system/pooling.js";
2
- import { viewport } from "./../game.js";
3
2
  import Renderable from "./renderable.js";
4
3
 
5
4
 
@@ -41,15 +40,18 @@ class ColorLayer extends Renderable {
41
40
  }
42
41
 
43
42
  /**
44
- * draw the color layer
45
- * @ignore
43
+ * draw this color layer (automatically called by melonJS)
44
+ * @name draw
45
+ * @memberof ColorLayer
46
+ * @protected
47
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
48
+ * @param {Camera2d} [viewport] the viewport to (re)draw
46
49
  */
47
- draw(renderer, rect) {
48
- var vpos = viewport.pos;
50
+ draw(renderer, viewport) {
49
51
  renderer.save();
50
52
  renderer.clipRect(
51
- rect.left - vpos.x, rect.top - vpos.y,
52
- rect.width, rect.height
53
+ 0, 0,
54
+ viewport.width, viewport.height
53
55
  );
54
56
  renderer.clearColor(this.color);
55
57
  renderer.restore();
@@ -102,7 +102,7 @@ class Container extends Renderable {
102
102
  * @memberof Container#
103
103
  * @param {number} index added or removed child index
104
104
  */
105
- this.onChildChange = function (/* index */) {
105
+ this.onChildChange = function (index) { // eslint-disable-line no-unused-vars
106
106
  // to be extended
107
107
  };
108
108
 
@@ -187,8 +187,10 @@ class Container extends Renderable {
187
187
  * Adding a child to the container will automatically remove it from its other container.
188
188
  * Meaning a child can only have one parent. This is important if you add a renderable
189
189
  * to a container then add it to the me.game.world container it will move it out of the
190
- * orginal container. Then when the me.game.world.reset() is called the renderable
191
- * will not be in any container.
190
+ * orginal container. Then when the me.game.world.reset() is called the renderable
191
+ * will not be in any container. <br>
192
+ * if the given child implements a onActivateEvent method, that method will be called
193
+ * once the child is added to this container.
192
194
  * @name addChild
193
195
  * @memberof Container
194
196
  * @param {Renderable} child
@@ -630,7 +632,8 @@ class Container extends Renderable {
630
632
  }
631
633
 
632
634
  /**
633
- * Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
635
+ * Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed. <br>
636
+ * if the given child implements a onDeactivateEvent() method, that method will be called once the child is removed from this container.
634
637
  * @name removeChild
635
638
  * @memberof Container
636
639
  * @public
@@ -933,15 +936,14 @@ class Container extends Renderable {
933
936
  }
934
937
 
935
938
  /**
936
- * draw the container. <br>
937
- * automatically called by the game manager {@link game}
939
+ * draw this renderable (automatically called by melonJS)
938
940
  * @name draw
939
941
  * @memberof Container
940
942
  * @protected
941
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
942
- * @param {Rect|Bounds} [rect] the area or viewport to (re)draw
943
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
944
+ * @param {Camera2d} [viewport] the viewport to (re)draw
943
945
  */
944
- draw(renderer, rect) {
946
+ draw(renderer, viewport) {
945
947
  var isFloating = false;
946
948
  var bounds = this.getBounds();
947
949
 
@@ -983,7 +985,7 @@ class Container extends Renderable {
983
985
  obj.preDraw(renderer);
984
986
 
985
987
  // draw the object
986
- obj.draw(renderer, rect);
988
+ obj.draw(renderer, viewport);
987
989
 
988
990
  // postdraw (clean-up);
989
991
  obj.postDraw(renderer);
@@ -198,7 +198,7 @@ export class DropTarget extends Renderable {
198
198
  * @memberof DropTarget
199
199
  * @param {Draggable} draggable the draggable object that is dropped
200
200
  */
201
- drop() {
201
+ drop(draggable) { // eslint-disable-line no-unused-vars
202
202
 
203
203
  }
204
204
 
@@ -164,7 +164,7 @@ class ImageLayer extends Sprite {
164
164
  * @param {number} h new height
165
165
  */
166
166
  resize(w, h) {
167
- super.resize(
167
+ return super.resize(
168
168
  this.repeatX ? Infinity : w,
169
169
  this.repeatY ? Infinity : h
170
170
  );
@@ -243,14 +243,14 @@ class ImageLayer extends Sprite {
243
243
  }
244
244
 
245
245
  /**
246
- * draw the ImageLayer. <br>
247
- * automatically called by the game manager {@link game}
246
+ * draw this ImageLayer (automatically called by melonJS)
248
247
  * @name draw
249
248
  * @memberof ImageLayer
250
249
  * @protected
251
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
250
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
251
+ * @param {Camera2d} [viewport] the viewport to (re)draw
252
252
  */
253
- draw(renderer) {
253
+ draw(renderer, viewport) {
254
254
  var width = this.width,
255
255
  height = this.height,
256
256
  bw = viewport.bounds.width,
@@ -90,10 +90,14 @@ class Light2d extends Renderable {
90
90
  }
91
91
 
92
92
  /**
93
- * object draw (Called internally by the engine).
94
- * @ignore
93
+ * draw this Light2d (automatically called by melonJS)
94
+ * @name draw
95
+ * @memberof Light2d
96
+ * @protected
97
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
98
+ * @param {Camera2d} [viewport] the viewport to (re)draw
95
99
  */
96
- draw(renderer) {
100
+ draw(renderer, viewport) { // eslint-disable-line no-unused-vars
97
101
  renderer.drawImage(this.texture.canvas, this.getBounds().x, this.getBounds().y);
98
102
  }
99
103
 
@@ -735,14 +735,14 @@ class Renderable extends Rect {
735
735
  }
736
736
 
737
737
  /**
738
- * object draw. <br>
739
- * automatically called by the game manager {@link game}
738
+ * draw this renderable (automatically called by melonJS)
740
739
  * @name draw
741
740
  * @memberof Renderable
742
741
  * @protected
743
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
742
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
743
+ * @param {Camera2d} [viewport] the viewport to (re)draw
744
744
  */
745
- draw(renderer) { // eslint-disable-line no-unused-vars
745
+ draw(renderer, viewport) { // eslint-disable-line no-unused-vars
746
746
  // empty one !
747
747
  }
748
748
 
@@ -775,7 +775,7 @@ class Renderable extends Rect {
775
775
  * when this renderable body is colliding with another one
776
776
  * @name onCollision
777
777
  * @memberof Renderable
778
- * @param {collision.ResponseObject} response the collision response object
778
+ * @param {ResponseObject} response the collision response object
779
779
  * @param {Renderable} other the other renderable touching this one (a reference to response.a or response.b)
780
780
  * @returns {boolean} true if the object should respond to the collision (its position and velocity will be corrected)
781
781
  * @example
@@ -792,7 +792,7 @@ class Renderable extends Rect {
792
792
  * return true;
793
793
  * },
794
794
  */
795
- onCollision() {
795
+ onCollision(response, other) { // eslint-disable-line no-unused-vars
796
796
  return false;
797
797
  }
798
798
 
@@ -586,14 +586,14 @@ class Sprite extends Renderable {
586
586
  }
587
587
 
588
588
  /**
589
- * sprite draw. <br>
590
- * automatically called by the game manager {@link game}
589
+ * draw this srite (automatically called by melonJS)
591
590
  * @name draw
592
591
  * @memberof Sprite
593
592
  * @protected
594
- * @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
593
+ * @param {CanvasRenderer|WebGLRenderer} renderer a renderer instance
594
+ * @param {Camera2d} [viewport] the viewport to (re)draw
595
595
  */
596
- draw(renderer) {
596
+ draw(renderer, viewport) { // eslint-disable-line no-unused-vars
597
597
  // do nothing if we are flickering
598
598
  if (this._flicker.isFlickering) {
599
599
  this._flicker.state = !this._flicker.state;
@@ -129,8 +129,15 @@ class Trigger extends Renderable {
129
129
  }
130
130
  }
131
131
 
132
- /** @ignore */
133
- onCollision() {
132
+ /**
133
+ * onCollision callback, triggered in case of collision with this trigger
134
+ * @name onCollision
135
+ * @memberof Trigger
136
+ * @param {ResponseObject} response the collision response object
137
+ * @param {Renderable} other the other renderable touching this one (a reference to response.a or response.b)
138
+ * @returns {boolean} true if the object should respond to the collision (its position and velocity will be corrected)
139
+ */
140
+ onCollision(response, other) { // eslint-disable-line no-unused-vars
134
141
  if (this.name === "Trigger") {
135
142
  this.triggerEvent.apply(this);
136
143
  }
@@ -426,6 +426,24 @@ var state = {
426
426
  }
427
427
  },
428
428
 
429
+ /**
430
+ * returns the stage associated with the specified state
431
+ * (or the current one if none is specified)
432
+ * @name set
433
+ * @memberof state
434
+ * @public
435
+ * @param {number} [state] State ID (see constants)
436
+ * @returns {Stage}
437
+ */
438
+ get(state = _state) {
439
+ if (typeof _stages[state] !== "undefined") {
440
+ return _stages[state].stage;
441
+ } else {
442
+ return undefined;
443
+ }
444
+
445
+ },
446
+
429
447
  /**
430
448
  * return a reference to the current stage<br>
431
449
  * useful to call a object specific method
@@ -435,9 +453,7 @@ var state = {
435
453
  * @returns {Stage}
436
454
  */
437
455
  current() {
438
- if (typeof _stages[_state] !== "undefined") {
439
- return _stages[_state].stage;
440
- }
456
+ return this.get();
441
457
  },
442
458
 
443
459
  /**
@@ -167,7 +167,7 @@ class ObjectPool {
167
167
  return (typeof className !== "undefined") &&
168
168
  (typeof obj.onResetEvent === "function") &&
169
169
  (className in this.objectClass) &&
170
- (this.objectClass[className].pool !== "undefined");
170
+ (typeof this.objectClass[className].pool !== "undefined");
171
171
 
172
172
  }
173
173
 
package/src/text/text.js CHANGED
@@ -25,6 +25,9 @@ var getContext2d = function (renderer, text) {
25
25
  if (text.offScreenCanvas === true) {
26
26
  return text.canvasTexture.context;
27
27
  } else {
28
+ if (typeof renderer === "undefined") {
29
+ renderer = globalRenderer;
30
+ }
28
31
  return renderer.getFontContext();
29
32
  }
30
33
  };
@@ -333,11 +336,11 @@ class Text extends Renderable {
333
336
 
334
337
  /**
335
338
  * measure the given text size in pixels
336
- * @param {CanvasRenderer|WebGLRenderer} [renderer] reference to the active renderer
339
+ * @param {CanvasRenderer|WebGLRenderer} renderer reference to the active renderer
337
340
  * @param {string} [text] the text to be measured
338
341
  * @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
339
342
  */
340
- measureText(renderer = globalRenderer, text = this._text) {
343
+ measureText(renderer, text = this._text) {
341
344
  return this.metrics.measureText(text, getContext2d(renderer, this));
342
345
  }
343
346
 
@@ -350,7 +353,7 @@ class Text extends Renderable {
350
353
  * @param {number} [y]
351
354
  * @param {boolean} [stroke=false] draw stroke the the text if true
352
355
  */
353
- draw(renderer, text, x, y, stroke) {
356
+ draw(renderer, text, x = this.pos.x, y = this.pos.y, stroke = false) {
354
357
  // "hacky patch" for backward compatibilty
355
358
  if (typeof this.ancestor === "undefined") {
356
359
 
@@ -381,6 +381,8 @@ export class TextureAtlas {
381
381
  * add uvs mapping for the given region
382
382
  * @param {object} atlas the atlas dictionnary where the region is define
383
383
  * @param {object} name region (or frame) name
384
+ * @param {number} w the width of the region
385
+ * @param {number} h the height of the region
384
386
  * @returns {Float32Array} the created region UVs
385
387
  */
386
388
  addUVs(atlas, name, w, h) {