melonjs 10.11.0 → 12.0.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 (39) hide show
  1. package/README.md +2 -0
  2. package/dist/melonjs.js +2949 -2795
  3. package/dist/melonjs.min.js +4 -4
  4. package/dist/melonjs.module.d.ts +208 -135
  5. package/dist/melonjs.module.js +2917 -2772
  6. package/package.json +11 -10
  7. package/src/audio/audio.js +5 -5
  8. package/src/entity/entity.js +5 -7
  9. package/src/geometries/ellipse.js +1 -1
  10. package/src/geometries/path2d.js +4 -4
  11. package/src/geometries/poly.js +1 -2
  12. package/src/geometries/rectangle.js +1 -1
  13. package/src/loader/loadingscreen.js +17 -103
  14. package/src/loader/melonjs_logo.png +0 -0
  15. package/src/physics/body.js +3 -4
  16. package/src/physics/collision.js +1 -12
  17. package/src/physics/detector.js +6 -52
  18. package/src/physics/response.js +48 -0
  19. package/src/physics/sat.js +1 -1
  20. package/src/polyfill/index.js +4 -0
  21. package/src/renderable/GUI.js +6 -4
  22. package/src/renderable/colorlayer.js +9 -7
  23. package/src/renderable/container.js +12 -10
  24. package/src/renderable/dragndrop.js +1 -1
  25. package/src/renderable/imagelayer.js +5 -5
  26. package/src/renderable/light2d.js +47 -14
  27. package/src/renderable/renderable.js +6 -6
  28. package/src/renderable/sprite.js +4 -4
  29. package/src/renderable/trigger.js +9 -2
  30. package/src/state/state.js +19 -3
  31. package/src/system/device.js +3 -67
  32. package/src/system/dom.js +69 -0
  33. package/src/system/event.js +11 -0
  34. package/src/system/pooling.js +1 -1
  35. package/src/text/bitmaptext.js +1 -2
  36. package/src/text/text.js +7 -5
  37. package/src/text/textmetrics.js +1 -2
  38. package/src/utils/string.js +0 -24
  39. package/src/video/texture/atlas.js +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "melonjs",
3
- "version": "10.11.0",
3
+ "version": "12.0.0",
4
4
  "description": "melonJS Game Engine",
5
5
  "homepage": "http://www.melonjs.org/",
6
6
  "keywords": [
@@ -55,33 +55,34 @@
55
55
  ],
56
56
  "dependencies": {
57
57
  "@teppeis/multimaps": "^2.0.0",
58
- "core-js": "^3.23.0",
58
+ "core-js": "^3.23.3",
59
59
  "earcut": "2.2.3",
60
60
  "eventemitter3": "^4.0.7",
61
61
  "howler": "2.2.3"
62
62
  },
63
63
  "devDependencies": {
64
- "@melonjs/webdoc-theme": "^1.1.0",
64
+ "@melonjs/webdoc-theme": "^1.1.1",
65
65
  "@rollup/plugin-buble": "^0.21.3",
66
- "@rollup/plugin-commonjs": "^22.0.0",
66
+ "@rollup/plugin-commonjs": "^22.0.1",
67
+ "@rollup/plugin-image": "^2.1.1",
67
68
  "@rollup/plugin-node-resolve": "^13.3.0",
68
69
  "@rollup/plugin-replace": "^4.0.0",
69
70
  "@types/offscreencanvas": "^2019.7.0",
70
71
  "@webdoc/cli": "^1.6.6",
71
72
  "del-cli": "^4.0.1",
72
- "eslint": "^8.17.0",
73
+ "eslint": "^8.18.0",
73
74
  "jasmine-core": "^4.2.0",
74
- "karma": "^6.3.20",
75
+ "karma": "^6.4.0",
75
76
  "karma-chrome-launcher": "^3.1.1",
76
77
  "karma-coverage": "^2.2.0",
77
78
  "karma-html-detailed-reporter": "^2.1.0",
78
- "karma-jasmine": "^5.0.1",
79
+ "karma-jasmine": "^5.1.0",
79
80
  "karma-nyan-reporter": "0.2.5",
80
- "rollup": "^2.75.6",
81
+ "rollup": "^2.75.7",
81
82
  "rollup-plugin-bundle-size": "^1.0.3",
82
83
  "rollup-plugin-string": "^3.0.0",
83
84
  "terser": "^5.14.1",
84
- "typescript": "^4.7.3"
85
+ "typescript": "^4.7.4"
85
86
  },
86
87
  "scripts": {
87
88
  "build": "npm run lint && rollup -c --silent",
@@ -90,7 +91,7 @@
90
91
  "lint": "eslint src rollup.config.js",
91
92
  "test": "npm run test-node && karma start tests/karma.conf.cjs",
92
93
  "test-node": "node build/melonjs.module.js",
93
- "doc": "mkdirp docs && webdoc --quiet --site-root docs -R README.md",
94
+ "doc": "mkdirp docs && webdoc --quiet --site-root melonJS/docs -R README.md",
94
95
  "serve": "python3 -m http.server",
95
96
  "prepublishOnly": "npm run dist && npm run test",
96
97
  "clean": "del-cli --force build/*.js dist/*.js dist/*.d.ts docs src/**/*.d.ts",
@@ -11,31 +11,31 @@ import loader from "./../loader/loader.js";
11
11
  * audio channel list
12
12
  * @ignore
13
13
  */
14
- var audioTracks = {};
14
+ let audioTracks = {};
15
15
 
16
16
  /**
17
17
  * current active track
18
18
  * @ignore
19
19
  */
20
- var current_track_id = null;
20
+ let current_track_id = null;
21
21
 
22
22
  /**
23
23
  * error retry counter
24
24
  * @ignore
25
25
  */
26
- var retry_counter = 0;
26
+ let retry_counter = 0;
27
27
 
28
28
  /**
29
29
  * list of active audio formats
30
30
  * @ignore
31
31
  */
32
- var audioExts = [];
32
+ let audioExts = [];
33
33
 
34
34
  /**
35
35
  * event listener callback on load error
36
36
  * @ignore
37
37
  */
38
- var soundLoadError = function (sound_name, onerror_cb) {
38
+ let soundLoadError = function (sound_name, onerror_cb) {
39
39
  // check the retry counter
40
40
  if (retry_counter++ > 3) {
41
41
  // something went wrong
@@ -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) {
@@ -1,10 +1,10 @@
1
1
  import { world, viewport } from "./../game.js";
2
2
  import { renderer } from "./../video/video.js";
3
3
  import * as event from "./../system/event.js";
4
- import {nextPowerOfTwo} from "./../math/math.js";
5
- import pool from "./../system/pooling.js";
6
4
  import Renderable from "./../renderable/renderable.js";
5
+ import Sprite from "./../renderable/sprite.js";
7
6
  import Stage from "./../state/stage.js";
7
+ import melonjs_logo from "./melonjs_logo.png";
8
8
 
9
9
 
10
10
  // a basic progress bar object
@@ -61,70 +61,22 @@ class ProgressBar extends Renderable {
61
61
 
62
62
  };
63
63
 
64
- // the melonJS Logo
65
- class IconLogo extends Renderable {
66
- /**
67
- * @ignore
68
- */
64
+ /**
65
+ * the melonJS Logo
66
+ * @ignore
67
+ */
68
+ class IconLogo extends Sprite {
69
69
  constructor(x, y) {
70
- super(x, y, 100, 85);
71
-
72
- this.iconTexture = pool.pull("CanvasTexture",
73
- renderer.WebGLVersion > 1 ? this.width : nextPowerOfTwo(this.width),
74
- renderer.WebGLVersion > 1 ? this.height : nextPowerOfTwo(this.height),
75
- { offscreenCanvas: true }
76
- );
77
-
78
- var context = this.iconTexture.context;
79
-
80
- context.beginPath();
81
- context.moveTo(0.7, 48.9);
82
- context.bezierCurveTo(10.8, 68.9, 38.4, 75.8, 62.2, 64.5);
83
- context.bezierCurveTo(86.1, 53.1, 97.2, 27.7, 87.0, 7.7);
84
- context.lineTo(87.0, 7.7);
85
- context.bezierCurveTo(89.9, 15.4, 73.9, 30.2, 50.5, 41.4);
86
- context.bezierCurveTo(27.1, 52.5, 5.2, 55.8, 0.7, 48.9);
87
- context.lineTo(0.7, 48.9);
88
- context.closePath();
89
- context.fillStyle = "rgb(255, 255, 255)";
90
- context.fill();
91
-
92
- context.beginPath();
93
- context.moveTo(84.0, 7.0);
94
- context.bezierCurveTo(87.6, 14.7, 72.5, 30.2, 50.2, 41.6);
95
- context.bezierCurveTo(27.9, 53.0, 6.9, 55.9, 3.2, 48.2);
96
- context.bezierCurveTo(-0.5, 40.4, 14.6, 24.9, 36.9, 13.5);
97
- context.bezierCurveTo(59.2, 2.2, 80.3, -0.8, 84.0, 7.0);
98
- context.lineTo(84.0, 7.0);
99
- context.closePath();
100
- context.lineWidth = 5.3;
101
- context.strokeStyle = "rgb(255, 255, 255)";
102
- context.lineJoin = "miter";
103
- context.miterLimit = 4.0;
104
- context.stroke();
105
-
106
- this.anchorPoint.set(0.5, 0.5);
107
- }
108
-
109
- /**
110
- * @ignore
111
- */
112
- draw(renderer) {
113
- renderer.drawImage(this.iconTexture.canvas, renderer.getWidth() / 2, this.pos.y);
70
+ // TODO: create a sprite or texture from a Base64 encoded image
71
+ var image = new Image();
72
+ image.src = melonjs_logo;
73
+ super(x, y, {
74
+ image : image,
75
+ framewidth : 256,
76
+ frameheight : 256
77
+ });
114
78
  }
115
-
116
- /**
117
- * Destroy function
118
- * @ignore
119
- */
120
- destroy() {
121
- // call the parent destroy method
122
- super.destroy(arguments);
123
- pool.push(this.iconTexture);
124
- this.iconTexture = undefined;
125
- }
126
- };
127
-
79
+ }
128
80
 
129
81
  /**
130
82
  * a default loading screen
@@ -152,47 +104,9 @@ class DefaultLoadingScreen extends Stage {
152
104
  // melonJS logo
153
105
  world.addChild(new IconLogo(
154
106
  renderer.getWidth() / 2,
155
- (renderer.getHeight() / 2) - (barHeight * 2) - 35
107
+ (renderer.getHeight() / 2)
156
108
 
157
109
  ), 2);
158
-
159
- var logo1 = pool.pull("Text",
160
- renderer.getWidth() / 2,
161
- (renderer.getHeight() / 2) + 16, {
162
- font: "century gothic",
163
- size: 32,
164
- fillStyle: "white",
165
- textAlign: "left",
166
- textBaseline : "top",
167
- text: "melon",
168
- offScreenCanvas: renderer.WebGLVersion >= 1
169
- }
170
- );
171
- logo1.anchorPoint.set(0, 0);
172
-
173
- var logo2 = pool.pull("Text",
174
- renderer.getWidth() / 2,
175
- (renderer.getHeight() / 2) + 16, {
176
- font: "century gothic",
177
- size: 32,
178
- fillStyle: "#55aa00",
179
- textAlign: "left",
180
- textBaseline : "top",
181
- bold: true,
182
- text: "JS",
183
- offScreenCanvas: renderer.WebGLVersion >= 1
184
- }
185
- );
186
- logo2.anchorPoint.set(0, 0);
187
-
188
- // adjust position of both text
189
- var text_width = logo1.getBounds().width + logo2.getBounds().width;
190
- logo1.pos.x = renderer.getWidth() / 2 - text_width / 2;
191
- logo2.pos.x = logo1.pos.x + logo1.getBounds().width;
192
-
193
- // melonJS text
194
- world.addChild(logo1, 2);
195
- world.addChild(logo2, 2);
196
110
  }
197
111
  };
198
112
 
Binary file
@@ -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;
@@ -1,6 +1,10 @@
1
1
  // https://github.com/melonjs/melonJS/issues/1092
2
2
  import "core-js/proposals/global-this";
3
3
 
4
+ // es10 string trim functions
5
+ import "core-js/es/string/trim-left";
6
+ import "core-js/es/string/trim-right";
7
+
4
8
  // "built-in" polyfills
5
9
  import "./console.js";
6
10
  import "./performance.js";
@@ -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);