melonjs 10.9.0 → 10.10.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.
@@ -64,6 +64,11 @@ class Renderer {
64
64
  */
65
65
  this.currentScissor = new Int32Array([ 0, 0, this.settings.width, this.settings.height ]);
66
66
 
67
+ /**
68
+ * @ignore
69
+ */
70
+ this.maskLevel = 0;
71
+
67
72
  /**
68
73
  * @ignore
69
74
  */
@@ -107,7 +112,7 @@ class Renderer {
107
112
  /**
108
113
  * prepare the framebuffer for drawing a new frame
109
114
  * @name clear
110
- * @memberof Renderer.prototype
115
+ * @memberof Renderer
111
116
  * @function
112
117
  */
113
118
  clear() {}
@@ -115,7 +120,7 @@ class Renderer {
115
120
  /**
116
121
  * Reset context state
117
122
  * @name reset
118
- * @memberof Renderer.prototype
123
+ * @memberof Renderer
119
124
  * @function
120
125
  */
121
126
  reset() {
@@ -128,12 +133,13 @@ class Renderer {
128
133
  this.currentScissor[1] = 0;
129
134
  this.currentScissor[2] = this.backBufferCanvas.width;
130
135
  this.currentScissor[3] = this.backBufferCanvas.height;
136
+ this.clearMask();
131
137
  }
132
138
 
133
139
  /**
134
140
  * return a reference to the system canvas
135
141
  * @name getCanvas
136
- * @memberof Renderer.prototype
142
+ * @memberof Renderer
137
143
  * @function
138
144
  * @returns {HTMLCanvasElement}
139
145
  */
@@ -144,7 +150,7 @@ class Renderer {
144
150
  /**
145
151
  * return a reference to the screen canvas
146
152
  * @name getScreenCanvas
147
- * @memberof Renderer.prototype
153
+ * @memberof Renderer
148
154
  * @function
149
155
  * @returns {HTMLCanvasElement}
150
156
  */
@@ -156,7 +162,7 @@ class Renderer {
156
162
  * return a reference to the screen canvas corresponding 2d Context<br>
157
163
  * (will return buffered context if double buffering is enabled, or a reference to the Screen Context)
158
164
  * @name getScreenContext
159
- * @memberof Renderer.prototype
165
+ * @memberof Renderer
160
166
  * @function
161
167
  * @returns {CanvasRenderingContext2D}
162
168
  */
@@ -167,7 +173,7 @@ class Renderer {
167
173
  /**
168
174
  * returns the current blend mode for this renderer
169
175
  * @name getBlendMode
170
- * @memberof Renderer.prototype
176
+ * @memberof Renderer
171
177
  * @function
172
178
  * @returns {string} blend mode
173
179
  */
@@ -179,7 +185,7 @@ class Renderer {
179
185
  * Returns the 2D Context object of the given Canvas<br>
180
186
  * Also configures anti-aliasing and blend modes based on constructor options.
181
187
  * @name getContext2d
182
- * @memberof Renderer.prototype
188
+ * @memberof Renderer
183
189
  * @function
184
190
  * @param {HTMLCanvasElement} canvas
185
191
  * @param {boolean} [transparent=true] use false to disable transparency
@@ -217,7 +223,7 @@ class Renderer {
217
223
  /**
218
224
  * return the width of the system Canvas
219
225
  * @name getWidth
220
- * @memberof Renderer.prototype
226
+ * @memberof Renderer
221
227
  * @function
222
228
  * @returns {number}
223
229
  */
@@ -228,7 +234,7 @@ class Renderer {
228
234
  /**
229
235
  * return the height of the system Canvas
230
236
  * @name getHeight
231
- * @memberof Renderer.prototype
237
+ * @memberof Renderer
232
238
  * @function
233
239
  * @returns {number} height of the system Canvas
234
240
  */
@@ -239,7 +245,7 @@ class Renderer {
239
245
  /**
240
246
  * get the current fill & stroke style color.
241
247
  * @name getColor
242
- * @memberof Renderer.prototype
248
+ * @memberof Renderer
243
249
  * @function
244
250
  * @returns {Color} current global color
245
251
  */
@@ -250,7 +256,7 @@ class Renderer {
250
256
  /**
251
257
  * return the current global alpha
252
258
  * @name globalAlpha
253
- * @memberof Renderer.prototype
259
+ * @memberof Renderer
254
260
  * @function
255
261
  * @returns {number}
256
262
  */
@@ -261,7 +267,7 @@ class Renderer {
261
267
  /**
262
268
  * check if the given rect or bounds overlaps with the renderer screen coordinates
263
269
  * @name overlaps
264
- * @memberof Renderer.prototype
270
+ * @memberof Renderer
265
271
  * @function
266
272
  * @param {Rect|Bounds} bounds
267
273
  * @returns {boolean} true if overlaps
@@ -277,7 +283,7 @@ class Renderer {
277
283
  /**
278
284
  * resizes the system canvas
279
285
  * @name resize
280
- * @memberof Renderer.prototype
286
+ * @memberof Renderer
281
287
  * @function
282
288
  * @param {number} width new width of the canvas
283
289
  * @param {number} height new height of the canvas
@@ -298,7 +304,7 @@ class Renderer {
298
304
  /**
299
305
  * enable/disable image smoothing (scaling interpolation) for the given context
300
306
  * @name setAntiAlias
301
- * @memberof Renderer.prototype
307
+ * @memberof Renderer
302
308
  * @function
303
309
  * @param {CanvasRenderingContext2D} context
304
310
  * @param {boolean} [enable=false]
@@ -328,7 +334,7 @@ class Renderer {
328
334
  /**
329
335
  * set/change the current projection matrix (WebGL only)
330
336
  * @name setProjection
331
- * @memberof Renderer.prototype
337
+ * @memberof Renderer
332
338
  * @function
333
339
  * @param {Matrix3d} matrix
334
340
  */
@@ -339,12 +345,16 @@ class Renderer {
339
345
  /**
340
346
  * stroke the given shape
341
347
  * @name stroke
342
- * @memberof Renderer.prototype
348
+ * @memberof Renderer
343
349
  * @function
344
350
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} shape a shape object to stroke
345
351
  * @param {boolean} [fill=false] fill the shape with the current color if true
346
352
  */
347
353
  stroke(shape, fill) {
354
+ if (shape instanceof RoundRect) {
355
+ this.strokeRoundRect(shape.left, shape.top, shape.width, shape.height, shape.radius, fill);
356
+ return;
357
+ }
348
358
  if (shape instanceof Rect || shape instanceof Bounds) {
349
359
  this.strokeRect(shape.left, shape.top, shape.width, shape.height, fill);
350
360
  return;
@@ -353,10 +363,6 @@ class Renderer {
353
363
  this.strokePolygon(shape, fill);
354
364
  return;
355
365
  }
356
- if (shape instanceof RoundRect) {
357
- this.strokeRoundRect(shape.left, shape.top, shape.width, shape.height, shape.radius, fill);
358
- return;
359
- }
360
366
  if (shape instanceof Ellipse) {
361
367
  this.strokeEllipse(
362
368
  shape.pos.x,
@@ -373,7 +379,7 @@ class Renderer {
373
379
  /**
374
380
  * fill the given shape
375
381
  * @name fill
376
- * @memberof Renderer.prototype
382
+ * @memberof Renderer
377
383
  * @function
378
384
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} shape a shape object to fill
379
385
  */
@@ -384,7 +390,7 @@ class Renderer {
384
390
  /**
385
391
  * tint the given image or canvas using the given color
386
392
  * @name tint
387
- * @memberof Renderer.prototype
393
+ * @memberof Renderer
388
394
  * @function
389
395
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} src the source image to be tinted
390
396
  * @param {Color|string} color the color that will be used to tint the image
@@ -415,9 +421,10 @@ class Renderer {
415
421
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
416
422
  * Mask are not preserved through renderer context save and restore.
417
423
  * @name setMask
418
- * @memberof Renderer.prototype
424
+ * @memberof Renderer
419
425
  * @function
420
426
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] the shape defining the mask to be applied
427
+ * @param {boolean} [invert=false] either the given shape should define what is visible (default) or the opposite
421
428
  */
422
429
  // eslint-disable-next-line no-unused-vars
423
430
  setMask(mask) {}
@@ -426,7 +433,7 @@ class Renderer {
426
433
  * disable (remove) the rendering mask set through setMask.
427
434
  * @name clearMask
428
435
  * @see Renderer#setMask
429
- * @memberof Renderer.prototype
436
+ * @memberof Renderer
430
437
  * @function
431
438
  */
432
439
  clearMask() {}
@@ -434,7 +441,7 @@ class Renderer {
434
441
  /**
435
442
  * set a coloring tint for sprite based renderables
436
443
  * @name setTint
437
- * @memberof Renderer.prototype
444
+ * @memberof Renderer
438
445
  * @function
439
446
  * @param {Color} tint the tint color
440
447
  * @param {number} [alpha] an alpha value to be applied to the tint
@@ -449,7 +456,7 @@ class Renderer {
449
456
  * clear the rendering tint set through setTint.
450
457
  * @name clearTint
451
458
  * @see Renderer#setTint
452
- * @memberof Renderer.prototype
459
+ * @memberof Renderer
453
460
  * @function
454
461
  */
455
462
  clearTint() {
@@ -1,11 +1,11 @@
1
- import Vector2d from "./../math/vector2.js";
2
- import WebGLRenderer from "./webgl/webgl_renderer.js";
3
- import TextureCache from "./texture_cache.js";
4
- import Sprite from "./../renderable/sprite.js";
5
- import { renderer } from "./video.js";
6
- import pool from "./../system/pooling.js";
7
- import loader from "./../loader/loader.js";
8
- import { ETA } from "./../math/math.js";
1
+ import Vector2d from "./../../math/vector2.js";
2
+ import WebGLRenderer from "./../webgl/webgl_renderer.js";
3
+ import TextureCache from "./../texture/cache.js";
4
+ import Sprite from "./../../renderable/sprite.js";
5
+ import { renderer } from "./../video.js";
6
+ import pool from "./../../system/pooling.js";
7
+ import loader from "./../../loader/loader.js";
8
+ import { ETA } from "./../../math/math.js";
9
9
 
10
10
  /**
11
11
  * create a simple 1 frame texture atlas based on the given parameters
@@ -1,7 +1,7 @@
1
- import { renderer } from "./video.js";
2
- import * as fileUtil from "./../utils/file.js";
3
- import { TextureAtlas, createAtlas } from "./texture.js";
4
- import { isPowerOfTwo} from "./../math/math.js";
1
+ import { renderer } from "./../video.js";
2
+ import * as fileUtil from "./../../utils/file.js";
3
+ import { TextureAtlas, createAtlas } from "./atlas.js";
4
+ import { isPowerOfTwo} from "./../../math/math.js";
5
5
  import {ArrayMultimap} from "@teppeis/multimaps";
6
6
 
7
7
 
@@ -0,0 +1,87 @@
1
+ import { createCanvas } from "./../video.js";
2
+
3
+ /**
4
+ * Creates a Canvas Texture of the given size
5
+ */
6
+ class CanvasTexture {
7
+ /**
8
+ * @param {number} width the desired width of the canvas
9
+ * @param {number} height the desired height of the canvas
10
+ * @param {number} [offscreenCanvas=true] if the the canvas should be an OffscreenCanvas
11
+ */
12
+ constructor(width, height, offscreenCanvas = true) {
13
+ /**
14
+ * the canvas created for this CanvasTexture
15
+ * @type {HTMLCanvasElement|OffscreenCanvas}
16
+ */
17
+ this.canvas = createCanvas(width, height, offscreenCanvas);
18
+
19
+ /**
20
+ * the rendering context of this CanvasTexture
21
+ * @type {CanvasRenderingContext2D}
22
+ */
23
+ this.context = this.canvas.getContext("2d");
24
+ }
25
+
26
+ /**
27
+ * @ignore
28
+ */
29
+ onResetEvent(width, height) {
30
+ this.clear();
31
+ this.resize(width, height);
32
+ }
33
+
34
+ /**
35
+ * Clears the content of the canvas texture
36
+ */
37
+ clear() {
38
+ this.context.setTransform(1, 0, 0, 1, 0, 0);
39
+ this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
40
+ }
41
+
42
+ /**
43
+ * Resizes the canvas texture to the given width and height.
44
+ * @param {number} width the desired width
45
+ * @param {number} height the desired height
46
+ */
47
+ resize(width, height) {
48
+ this.canvas.width = Math.round(width);
49
+ this.canvas.height = Math.round(height);
50
+ }
51
+
52
+ /**
53
+ * @ignore
54
+ */
55
+ destroy() {
56
+ this.context = undefined;
57
+ this.canvas = undefined;
58
+ }
59
+
60
+ /**
61
+ * The width of this canvas texture in pixels
62
+ * @public
63
+ * @type {number}
64
+ */
65
+ get width() {
66
+ return this.canvas.width;
67
+ }
68
+
69
+ set width(val) {
70
+ this.canvas.width = Math.round(val);
71
+ }
72
+
73
+ /**
74
+ * The height of this canvas texture in pixels
75
+ * @public
76
+ * @type {number}
77
+ */
78
+ get height() {
79
+ return this.canvas.height;
80
+ }
81
+
82
+ set height(val) {
83
+ this.canvas.height = Math.round(val);
84
+ }
85
+ }
86
+
87
+ export default CanvasTexture;