melonjs 10.2.3 → 10.5.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.
- package/README.md +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
package/src/renderable/sprite.js
CHANGED
|
@@ -2,53 +2,46 @@ import Vector2d from "./../math/vector2.js";
|
|
|
2
2
|
import { renderer } from "./../video/video.js";
|
|
3
3
|
import pool from "./../system/pooling.js";
|
|
4
4
|
import loader from "./../loader/loader.js";
|
|
5
|
-
import {
|
|
5
|
+
import { TextureAtlas } from "./../video/texture.js";
|
|
6
6
|
import Renderable from "./renderable.js";
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
/**
|
|
10
9
|
* @classdesc
|
|
11
10
|
* An object to display a fixed or animated sprite on screen.
|
|
12
|
-
* @
|
|
13
|
-
* @extends me.Renderable
|
|
14
|
-
* @memberOf me
|
|
15
|
-
* @constructor
|
|
16
|
-
* @param {number} x the x coordinates of the sprite object
|
|
17
|
-
* @param {number} y the y coordinates of the sprite object
|
|
18
|
-
* @param {object} settings Configuration parameters for the Sprite object
|
|
19
|
-
* @param {me.Renderer.Texture|HTMLImageElement|HTMLCanvasElement|string} settings.image reference to a texture, spritesheet image or to a texture atlas
|
|
20
|
-
* @param {string} [settings.name=""] name of this object
|
|
21
|
-
* @param {string} [settings.region] region name of a specific region to use when using a texture atlas, see {@link me.Renderer.Texture}
|
|
22
|
-
* @param {number} [settings.framewidth] Width of a single frame within the spritesheet
|
|
23
|
-
* @param {number} [settings.frameheight] Height of a single frame within the spritesheet
|
|
24
|
-
* @param {string|me.Color} [settings.tint] a tint to be applied to this sprite
|
|
25
|
-
* @param {number} [settings.flipX] flip the sprite on the horizontal axis
|
|
26
|
-
* @param {number} [settings.flipY] flip the sprite on the vertical axis
|
|
27
|
-
* @param {me.Vector2d} [settings.anchorPoint={x:0.5, y:0.5}] Anchor point to draw the frame at (defaults to the center of the frame).
|
|
28
|
-
* @example
|
|
29
|
-
* // create a single sprite from a standalone image, with anchor in the center
|
|
30
|
-
* var sprite = new me.Sprite(0, 0, {
|
|
31
|
-
* image : "PlayerTexture",
|
|
32
|
-
* framewidth : 64,
|
|
33
|
-
* frameheight : 64,
|
|
34
|
-
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* // create a single sprite from a packed texture
|
|
38
|
-
* game.texture = new me.video.renderer.Texture(
|
|
39
|
-
* me.loader.getJSON("texture"),
|
|
40
|
-
* me.loader.getImage("texture")
|
|
41
|
-
* );
|
|
42
|
-
* var sprite = new me.Sprite(0, 0, {
|
|
43
|
-
* image : game.texture,
|
|
44
|
-
* region : "npc2.png",
|
|
45
|
-
* });
|
|
11
|
+
* @augments Renderable
|
|
46
12
|
*/
|
|
47
|
-
|
|
48
13
|
class Sprite extends Renderable {
|
|
49
|
-
|
|
50
14
|
/**
|
|
51
|
-
* @
|
|
15
|
+
* @param {number} x the x coordinates of the sprite object
|
|
16
|
+
* @param {number} y the y coordinates of the sprite object
|
|
17
|
+
* @param {object} settings Configuration parameters for the Sprite object
|
|
18
|
+
* @param {HTMLImageElement|HTMLCanvasElement|TextureAtlas|string} settings.image reference to spritesheet image, a texture atlas or to a texture atlas
|
|
19
|
+
* @param {string} [settings.name=""] name of this object
|
|
20
|
+
* @param {string} [settings.region] region name of a specific region to use when using a texture atlas, see {@link TextureAtlas}
|
|
21
|
+
* @param {number} [settings.framewidth] Width of a single frame within the spritesheet
|
|
22
|
+
* @param {number} [settings.frameheight] Height of a single frame within the spritesheet
|
|
23
|
+
* @param {string|Color} [settings.tint] a tint to be applied to this sprite
|
|
24
|
+
* @param {number} [settings.flipX] flip the sprite on the horizontal axis
|
|
25
|
+
* @param {number} [settings.flipY] flip the sprite on the vertical axis
|
|
26
|
+
* @param {Vector2d} [settings.anchorPoint={x:0.5, y:0.5}] Anchor point to draw the frame at (defaults to the center of the frame).
|
|
27
|
+
* @example
|
|
28
|
+
* // create a single sprite from a standalone image, with anchor in the center
|
|
29
|
+
* var sprite = new me.Sprite(0, 0, {
|
|
30
|
+
* image : "PlayerTexture",
|
|
31
|
+
* framewidth : 64,
|
|
32
|
+
* frameheight : 64,
|
|
33
|
+
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // create a single sprite from a packed texture
|
|
37
|
+
* game.texture = new me.TextureAtlas(
|
|
38
|
+
* me.loader.getJSON("texture"),
|
|
39
|
+
* me.loader.getImage("texture")
|
|
40
|
+
* );
|
|
41
|
+
* var sprite = new me.Sprite(0, 0, {
|
|
42
|
+
* image : game.texture,
|
|
43
|
+
* region : "npc2.png",
|
|
44
|
+
* });
|
|
52
45
|
*/
|
|
53
46
|
constructor(x, y, settings) {
|
|
54
47
|
|
|
@@ -60,7 +53,7 @@ class Sprite extends Renderable {
|
|
|
60
53
|
* @public
|
|
61
54
|
* @type {boolean}
|
|
62
55
|
* @default false
|
|
63
|
-
* @name
|
|
56
|
+
* @name Sprite#animationpause
|
|
64
57
|
*/
|
|
65
58
|
this.animationpause = false;
|
|
66
59
|
|
|
@@ -69,26 +62,26 @@ class Sprite extends Renderable {
|
|
|
69
62
|
* @public
|
|
70
63
|
* @type {number}
|
|
71
64
|
* @default 100
|
|
72
|
-
* @name
|
|
65
|
+
* @name Sprite#animationspeed
|
|
73
66
|
*/
|
|
74
67
|
this.animationspeed = 100;
|
|
75
68
|
|
|
76
69
|
/**
|
|
77
70
|
* global offset for the position to draw from on the source image.
|
|
78
71
|
* @public
|
|
79
|
-
* @type {
|
|
72
|
+
* @type {Vector2d}
|
|
80
73
|
* @default <0.0,0.0>
|
|
81
74
|
* @name offset
|
|
82
|
-
* @
|
|
75
|
+
* @memberof Sprite#
|
|
83
76
|
*/
|
|
84
77
|
this.offset = pool.pull("Vector2d", 0, 0);
|
|
85
78
|
|
|
86
79
|
/**
|
|
87
80
|
* The source texture object this sprite object is using
|
|
88
81
|
* @public
|
|
89
|
-
* @type {
|
|
82
|
+
* @type {TextureAtlas}
|
|
90
83
|
* @name source
|
|
91
|
-
* @
|
|
84
|
+
* @memberof Sprite#
|
|
92
85
|
*/
|
|
93
86
|
this.source = null;
|
|
94
87
|
|
|
@@ -128,7 +121,7 @@ class Sprite extends Renderable {
|
|
|
128
121
|
};
|
|
129
122
|
|
|
130
123
|
// set the proper image/texture to use
|
|
131
|
-
if (settings.image instanceof
|
|
124
|
+
if (settings.image instanceof TextureAtlas) {
|
|
132
125
|
this.source = settings.image;
|
|
133
126
|
this.image = this.source.getTexture();
|
|
134
127
|
this.textureAtlas = settings.image;
|
|
@@ -217,7 +210,7 @@ class Sprite extends Renderable {
|
|
|
217
210
|
/**
|
|
218
211
|
* return the flickering state of the object
|
|
219
212
|
* @name isFlickering
|
|
220
|
-
* @
|
|
213
|
+
* @memberof Sprite.prototype
|
|
221
214
|
* @function
|
|
222
215
|
* @returns {boolean}
|
|
223
216
|
*/
|
|
@@ -228,11 +221,11 @@ class Sprite extends Renderable {
|
|
|
228
221
|
/**
|
|
229
222
|
* make the object flicker
|
|
230
223
|
* @name flicker
|
|
231
|
-
* @
|
|
224
|
+
* @memberof Sprite.prototype
|
|
232
225
|
* @function
|
|
233
226
|
* @param {number} duration expressed in milliseconds
|
|
234
227
|
* @param {Function} callback Function to call when flickering ends
|
|
235
|
-
* @returns {
|
|
228
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
236
229
|
* @example
|
|
237
230
|
* // make the object flicker for 1 second
|
|
238
231
|
* // and then remove it
|
|
@@ -259,14 +252,14 @@ class Sprite extends Renderable {
|
|
|
259
252
|
* logic as per the following example :<br>
|
|
260
253
|
* <img src="images/spritesheet_grid.png"/>
|
|
261
254
|
* @name addAnimation
|
|
262
|
-
* @
|
|
255
|
+
* @memberof Sprite.prototype
|
|
263
256
|
* @function
|
|
264
257
|
* @param {string} name animation id
|
|
265
258
|
* @param {number[]|string[]|object[]} index list of sprite index or name
|
|
266
259
|
* defining the animation. Can also use objects to specify delay for each frame, see below
|
|
267
260
|
* @param {number} [animationspeed] cycling speed for animation in ms
|
|
268
261
|
* @returns {number} frame amount of frame added to the animation (delay between each frame).
|
|
269
|
-
* @see
|
|
262
|
+
* @see Sprite#animationspeed
|
|
270
263
|
* @example
|
|
271
264
|
* // walking animation
|
|
272
265
|
* this.addAnimation("walk", [ 0, 1, 2, 3, 4, 5 ]);
|
|
@@ -359,12 +352,12 @@ class Sprite extends Renderable {
|
|
|
359
352
|
* set the current animation
|
|
360
353
|
* this will always change the animation & set the frame to zero
|
|
361
354
|
* @name setCurrentAnimation
|
|
362
|
-
* @
|
|
355
|
+
* @memberof Sprite.prototype
|
|
363
356
|
* @function
|
|
364
357
|
* @param {string} name animation id
|
|
365
358
|
* @param {string|Function} [resetAnim] animation id to switch to when complete, or callback
|
|
366
359
|
* @param {boolean} [preserve_dt=false] if false will reset the elapsed time counter since last frame
|
|
367
|
-
* @returns {
|
|
360
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
368
361
|
* @example
|
|
369
362
|
* // set "walk" animation
|
|
370
363
|
* this.setCurrentAnimation("walk");
|
|
@@ -420,11 +413,11 @@ class Sprite extends Renderable {
|
|
|
420
413
|
/**
|
|
421
414
|
* reverse the given or current animation if none is specified
|
|
422
415
|
* @name reverseAnimation
|
|
423
|
-
* @
|
|
416
|
+
* @memberof Sprite.prototype
|
|
424
417
|
* @function
|
|
425
418
|
* @param {string} [name] animation id
|
|
426
|
-
* @returns {
|
|
427
|
-
* @see
|
|
419
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
420
|
+
* @see Sprite#animationspeed
|
|
428
421
|
*/
|
|
429
422
|
reverseAnimation(name) {
|
|
430
423
|
if (typeof name !== "undefined" && typeof this.anim[name] !== "undefined") {
|
|
@@ -439,7 +432,7 @@ class Sprite extends Renderable {
|
|
|
439
432
|
/**
|
|
440
433
|
* return true if the specified animation is the current one.
|
|
441
434
|
* @name isCurrentAnimation
|
|
442
|
-
* @
|
|
435
|
+
* @memberof Sprite.prototype
|
|
443
436
|
* @function
|
|
444
437
|
* @param {string} name animation id
|
|
445
438
|
* @returns {boolean}
|
|
@@ -454,12 +447,12 @@ class Sprite extends Renderable {
|
|
|
454
447
|
|
|
455
448
|
/**
|
|
456
449
|
* change the current texture atlas region for this sprite
|
|
457
|
-
* @see
|
|
450
|
+
* @see Texture.getRegion
|
|
458
451
|
* @name setRegion
|
|
459
|
-
* @
|
|
452
|
+
* @memberof Sprite.prototype
|
|
460
453
|
* @function
|
|
461
454
|
* @param {object} region typically returned through me.Texture.getRegion()
|
|
462
|
-
* @returns {
|
|
455
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
463
456
|
* @example
|
|
464
457
|
* // change the sprite to "shadedDark13.png";
|
|
465
458
|
* mySprite.setRegion(game.texture.getRegion("shadedDark13.png"));
|
|
@@ -488,10 +481,10 @@ class Sprite extends Renderable {
|
|
|
488
481
|
/**
|
|
489
482
|
* force the current animation frame index.
|
|
490
483
|
* @name setAnimationFrame
|
|
491
|
-
* @
|
|
484
|
+
* @memberof Sprite.prototype
|
|
492
485
|
* @function
|
|
493
486
|
* @param {number} [idx=0] animation frame index
|
|
494
|
-
* @returns {
|
|
487
|
+
* @returns {Sprite} Reference to this object for method chaining
|
|
495
488
|
* @example
|
|
496
489
|
* // reset the current animation to the first frame
|
|
497
490
|
* this.setAnimationFrame();
|
|
@@ -504,7 +497,7 @@ class Sprite extends Renderable {
|
|
|
504
497
|
/**
|
|
505
498
|
* return the current animation frame index.
|
|
506
499
|
* @name getCurrentAnimationFrame
|
|
507
|
-
* @
|
|
500
|
+
* @memberof Sprite.prototype
|
|
508
501
|
* @function
|
|
509
502
|
* @returns {number} current animation frame index
|
|
510
503
|
*/
|
|
@@ -515,7 +508,7 @@ class Sprite extends Renderable {
|
|
|
515
508
|
/**
|
|
516
509
|
* Returns the frame object by the index.
|
|
517
510
|
* @name getAnimationFrameObjectByIndex
|
|
518
|
-
* @
|
|
511
|
+
* @memberof Sprite.prototype
|
|
519
512
|
* @function
|
|
520
513
|
* @ignore
|
|
521
514
|
* @param {number} id the frame id
|
|
@@ -527,9 +520,9 @@ class Sprite extends Renderable {
|
|
|
527
520
|
|
|
528
521
|
/**
|
|
529
522
|
* update function. <br>
|
|
530
|
-
* automatically called by the game manager {@link
|
|
523
|
+
* automatically called by the game manager {@link game}
|
|
531
524
|
* @name update
|
|
532
|
-
* @
|
|
525
|
+
* @memberof Sprite.prototype
|
|
533
526
|
* @function
|
|
534
527
|
* @protected
|
|
535
528
|
* @param {number} dt time since the last update in milliseconds.
|
|
@@ -606,12 +599,12 @@ class Sprite extends Renderable {
|
|
|
606
599
|
|
|
607
600
|
/**
|
|
608
601
|
* sprite draw. <br>
|
|
609
|
-
* automatically called by the game manager {@link
|
|
602
|
+
* automatically called by the game manager {@link game}
|
|
610
603
|
* @name draw
|
|
611
|
-
* @
|
|
604
|
+
* @memberof Sprite.prototype
|
|
612
605
|
* @function
|
|
613
606
|
* @protected
|
|
614
|
-
* @param {
|
|
607
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
615
608
|
*/
|
|
616
609
|
draw(renderer) {
|
|
617
610
|
// do nothing if we are flickering
|
|
@@ -1,48 +1,42 @@
|
|
|
1
1
|
import Renderable from "./renderable.js";
|
|
2
2
|
import collision from "./../physics/collision.js";
|
|
3
3
|
import Body from "./../physics/body.js";
|
|
4
|
-
import Rect from "./../
|
|
4
|
+
import Rect from "./../geometries/rectangle.js";
|
|
5
5
|
import level from "./../level/level.js";
|
|
6
6
|
import { world, viewport } from "./../game.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* @classdesc
|
|
10
10
|
* trigger an event when colliding with another object
|
|
11
|
-
* @
|
|
12
|
-
* @extends me.Renderable
|
|
13
|
-
* @memberOf me
|
|
14
|
-
* @constructor
|
|
15
|
-
* @param {number} x the x coordinates of the trigger area
|
|
16
|
-
* @param {number} y the y coordinates of the trigger area
|
|
17
|
-
* @param {number} [settings.width] width of the trigger area
|
|
18
|
-
* @param {number} [settings.height] height of the trigger area
|
|
19
|
-
* @param {me.Rect[]|me.Polygon[]|me.Line[]|me.Ellipse[]} [settings.shapes] collision shape(s) that will trigger the event
|
|
20
|
-
* @param {string} [settings.duration] Fade duration (in ms)
|
|
21
|
-
* @param {string|me.Color} [settings.color] Fade color
|
|
22
|
-
* @param {string} [settings.event="level"] the type of event to trigger (only "level" supported for now)
|
|
23
|
-
* @param {string} [settings.to] level to load if level trigger
|
|
24
|
-
* @param {string|me.Container} [settings.container] Target container. See {@link me.level.load}
|
|
25
|
-
* @param {Function} [settings.onLoaded] Level loaded callback. See {@link me.level.load}
|
|
26
|
-
* @param {boolean} [settings.flatten] Flatten all objects into the target container. See {@link me.level.load}
|
|
27
|
-
* @param {boolean} [settings.setViewportBounds] Resize the viewport to match the level. See {@link me.level.load}
|
|
28
|
-
* @example
|
|
29
|
-
* me.game.world.addChild(new me.Trigger(
|
|
30
|
-
* x, y, {
|
|
31
|
-
* shapes: [new me.Rect(0, 0, 100, 100)],
|
|
32
|
-
* "duration" : 250,
|
|
33
|
-
* "color" : "#000",
|
|
34
|
-
* "to" : "mymap2"
|
|
35
|
-
* }
|
|
36
|
-
* ));
|
|
11
|
+
* @augments Renderable
|
|
37
12
|
*/
|
|
38
|
-
|
|
39
13
|
class Trigger extends Renderable {
|
|
40
|
-
|
|
41
14
|
/**
|
|
42
|
-
* @
|
|
15
|
+
* @param {number} x the x coordinates of the trigger area
|
|
16
|
+
* @param {number} y the y coordinates of the trigger area
|
|
17
|
+
* @param {number} [settings.width] width of the trigger area
|
|
18
|
+
* @param {number} [settings.height] height of the trigger area
|
|
19
|
+
* @param {Rect[]|Polygon[]|Line[]|Ellipse[]} [settings.shapes] collision shape(s) that will trigger the event
|
|
20
|
+
* @param {string} [settings.duration] Fade duration (in ms)
|
|
21
|
+
* @param {string|Color} [settings.color] Fade color
|
|
22
|
+
* @param {string} [settings.event="level"] the type of event to trigger (only "level" supported for now)
|
|
23
|
+
* @param {string} [settings.to] level to load if level trigger
|
|
24
|
+
* @param {string|Container} [settings.container] Target container. See {@link level.load}
|
|
25
|
+
* @param {Function} [settings.onLoaded] Level loaded callback. See {@link level.load}
|
|
26
|
+
* @param {boolean} [settings.flatten] Flatten all objects into the target container. See {@link level.load}
|
|
27
|
+
* @param {boolean} [settings.setViewportBounds] Resize the viewport to match the level. See {@link level.load}
|
|
28
|
+
* @example
|
|
29
|
+
* me.game.world.addChild(new me.Trigger(
|
|
30
|
+
* x, y, {
|
|
31
|
+
* shapes: [new me.Rect(0, 0, 100, 100)],
|
|
32
|
+
* "duration" : 250,
|
|
33
|
+
* "color" : "#000",
|
|
34
|
+
* "to" : "mymap2"
|
|
35
|
+
* }
|
|
36
|
+
* ));
|
|
43
37
|
*/
|
|
44
38
|
constructor(x, y, settings) {
|
|
45
|
-
|
|
39
|
+
// call the parent constructor
|
|
46
40
|
super(x, y, settings.width || 0, settings.height || 0);
|
|
47
41
|
|
|
48
42
|
// for backward compatibility
|
|
@@ -104,7 +98,7 @@ class Trigger extends Renderable {
|
|
|
104
98
|
/**
|
|
105
99
|
* trigger this event
|
|
106
100
|
* @name triggerEvent
|
|
107
|
-
* @
|
|
101
|
+
* @memberof Trigger
|
|
108
102
|
* @function
|
|
109
103
|
* @protected
|
|
110
104
|
*/
|
package/src/state/stage.js
CHANGED
|
@@ -15,20 +15,15 @@ var default_settings = {
|
|
|
15
15
|
* a default "Stage" object.
|
|
16
16
|
* every "stage" object (title screen, credits, ingame, etc...) to be managed
|
|
17
17
|
* through the state manager must inherit from this base class.
|
|
18
|
-
* @
|
|
19
|
-
* @extends me.Object
|
|
20
|
-
* @memberOf me
|
|
21
|
-
* @constructor
|
|
22
|
-
* @param {object} [options] The stage` parameters
|
|
23
|
-
* @param {me.Camera2d[]} [options.cameras=[new me.Camera2d()]] a list of cameras (experimental)
|
|
24
|
-
* @param {Function} [options.onResetEvent] called by the state manager when reseting the object
|
|
25
|
-
* @param {Function} [options.onDestroyEvent] called by the state manager before switching to another state
|
|
26
|
-
* @see me.state
|
|
18
|
+
* @see state
|
|
27
19
|
*/
|
|
28
20
|
class Stage {
|
|
29
21
|
|
|
30
22
|
/**
|
|
31
|
-
* @
|
|
23
|
+
* @param {object} [settings] The stage` parameters
|
|
24
|
+
* @param {Camera2d[]} [settings.cameras=[new me.Camera2d()]] a list of cameras (experimental)
|
|
25
|
+
* @param {Function} [settings.onResetEvent] called by the state manager when reseting the object
|
|
26
|
+
* @param {Function} [settings.onDestroyEvent] called by the state manager before switching to another state
|
|
32
27
|
*/
|
|
33
28
|
constructor(settings) {
|
|
34
29
|
/**
|
|
@@ -38,7 +33,7 @@ class Stage {
|
|
|
38
33
|
* @public
|
|
39
34
|
* @type {Map}
|
|
40
35
|
* @name cameras
|
|
41
|
-
* @
|
|
36
|
+
* @memberof Stage
|
|
42
37
|
*/
|
|
43
38
|
this.cameras = new Map();
|
|
44
39
|
|
|
@@ -46,7 +41,7 @@ class Stage {
|
|
|
46
41
|
* The given constructor options
|
|
47
42
|
* @public
|
|
48
43
|
* @name settings
|
|
49
|
-
* @
|
|
44
|
+
* @memberof Stage
|
|
50
45
|
* @type {object}
|
|
51
46
|
*/
|
|
52
47
|
this.settings = Object.assign(default_settings, settings || {});
|
|
@@ -84,7 +79,7 @@ class Stage {
|
|
|
84
79
|
/**
|
|
85
80
|
* update function
|
|
86
81
|
* @name update
|
|
87
|
-
* @
|
|
82
|
+
* @memberof Stage
|
|
88
83
|
* @ignore
|
|
89
84
|
* @function
|
|
90
85
|
* @param {number} dt time since the last update in milliseconds.
|
|
@@ -108,10 +103,10 @@ class Stage {
|
|
|
108
103
|
/**
|
|
109
104
|
* draw the current stage
|
|
110
105
|
* @name draw
|
|
111
|
-
* @
|
|
106
|
+
* @memberof Stage
|
|
112
107
|
* @ignore
|
|
113
108
|
* @function
|
|
114
|
-
* @param {
|
|
109
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
115
110
|
*/
|
|
116
111
|
draw(renderer) {
|
|
117
112
|
// iterate through all cameras
|
|
@@ -137,10 +132,10 @@ class Stage {
|
|
|
137
132
|
* called by the state manager when reseting the object
|
|
138
133
|
* this is typically where you will load a level, add renderables, etc...
|
|
139
134
|
* @name onResetEvent
|
|
140
|
-
* @
|
|
135
|
+
* @memberof Stage
|
|
141
136
|
* @function
|
|
142
137
|
* @param {object} [...arguments] optional arguments passed when switching state
|
|
143
|
-
* @see
|
|
138
|
+
* @see state#change
|
|
144
139
|
*/
|
|
145
140
|
onResetEvent() {
|
|
146
141
|
// execute onResetEvent function if given through the constructor
|
|
@@ -154,7 +149,7 @@ class Stage {
|
|
|
154
149
|
* onDestroyEvent function<br>
|
|
155
150
|
* called by the state manager before switching to another state
|
|
156
151
|
* @name onDestroyEvent
|
|
157
|
-
* @
|
|
152
|
+
* @memberof Stage
|
|
158
153
|
* @function
|
|
159
154
|
*/
|
|
160
155
|
onDestroyEvent() {
|
package/src/state/state.js
CHANGED
|
@@ -150,7 +150,6 @@ event.on(event.BOOT, () => {
|
|
|
150
150
|
/**
|
|
151
151
|
* a State Manager (state machine)
|
|
152
152
|
* @namespace state
|
|
153
|
-
* @memberOf me
|
|
154
153
|
*/
|
|
155
154
|
|
|
156
155
|
var state = {
|
|
@@ -159,7 +158,7 @@ var state = {
|
|
|
159
158
|
* default state ID for Loading Stage
|
|
160
159
|
* @constant
|
|
161
160
|
* @name LOADING
|
|
162
|
-
* @
|
|
161
|
+
* @memberof state
|
|
163
162
|
*/
|
|
164
163
|
LOADING : 0,
|
|
165
164
|
|
|
@@ -167,7 +166,7 @@ var state = {
|
|
|
167
166
|
* default state ID for Menu Stage
|
|
168
167
|
* @constant
|
|
169
168
|
* @name MENU
|
|
170
|
-
* @
|
|
169
|
+
* @memberof state
|
|
171
170
|
*/
|
|
172
171
|
MENU : 1,
|
|
173
172
|
|
|
@@ -175,7 +174,7 @@ var state = {
|
|
|
175
174
|
* default state ID for "Ready" Stage
|
|
176
175
|
* @constant
|
|
177
176
|
* @name READY
|
|
178
|
-
* @
|
|
177
|
+
* @memberof state
|
|
179
178
|
*/
|
|
180
179
|
READY : 2,
|
|
181
180
|
|
|
@@ -183,7 +182,7 @@ var state = {
|
|
|
183
182
|
* default state ID for Play Stage
|
|
184
183
|
* @constant
|
|
185
184
|
* @name PLAY
|
|
186
|
-
* @
|
|
185
|
+
* @memberof state
|
|
187
186
|
*/
|
|
188
187
|
PLAY : 3,
|
|
189
188
|
|
|
@@ -191,7 +190,7 @@ var state = {
|
|
|
191
190
|
* default state ID for Game Over Stage
|
|
192
191
|
* @constant
|
|
193
192
|
* @name GAMEOVER
|
|
194
|
-
* @
|
|
193
|
+
* @memberof state
|
|
195
194
|
*/
|
|
196
195
|
GAMEOVER : 4,
|
|
197
196
|
|
|
@@ -199,7 +198,7 @@ var state = {
|
|
|
199
198
|
* default state ID for Game End Stage
|
|
200
199
|
* @constant
|
|
201
200
|
* @name GAME_END
|
|
202
|
-
* @
|
|
201
|
+
* @memberof state
|
|
203
202
|
*/
|
|
204
203
|
GAME_END : 5,
|
|
205
204
|
|
|
@@ -207,7 +206,7 @@ var state = {
|
|
|
207
206
|
* default state ID for High Score Stage
|
|
208
207
|
* @constant
|
|
209
208
|
* @name SCORE
|
|
210
|
-
* @
|
|
209
|
+
* @memberof state
|
|
211
210
|
*/
|
|
212
211
|
SCORE : 6,
|
|
213
212
|
|
|
@@ -215,7 +214,7 @@ var state = {
|
|
|
215
214
|
* default state ID for Credits Stage
|
|
216
215
|
* @constant
|
|
217
216
|
* @name CREDITS
|
|
218
|
-
* @
|
|
217
|
+
* @memberof state
|
|
219
218
|
*/
|
|
220
219
|
CREDITS : 7,
|
|
221
220
|
|
|
@@ -223,7 +222,7 @@ var state = {
|
|
|
223
222
|
* default state ID for Settings Stage
|
|
224
223
|
* @constant
|
|
225
224
|
* @name SETTINGS
|
|
226
|
-
* @
|
|
225
|
+
* @memberof state
|
|
227
226
|
*/
|
|
228
227
|
SETTINGS : 8,
|
|
229
228
|
|
|
@@ -232,7 +231,7 @@ var state = {
|
|
|
232
231
|
* (the default stage is the one running as soon as melonJS is started)
|
|
233
232
|
* @constant
|
|
234
233
|
* @name SETTINGS
|
|
235
|
-
* @
|
|
234
|
+
* @memberof state
|
|
236
235
|
*/
|
|
237
236
|
DEFAULT : 9,
|
|
238
237
|
|
|
@@ -240,7 +239,7 @@ var state = {
|
|
|
240
239
|
* default state ID for user defined constants<br>
|
|
241
240
|
* @constant
|
|
242
241
|
* @name USER
|
|
243
|
-
* @
|
|
242
|
+
* @memberof state
|
|
244
243
|
* @example
|
|
245
244
|
* var STATE_INFO = me.state.USER + 0;
|
|
246
245
|
* var STATE_WARN = me.state.USER + 1;
|
|
@@ -252,7 +251,7 @@ var state = {
|
|
|
252
251
|
/**
|
|
253
252
|
* Stop the current screen object.
|
|
254
253
|
* @name stop
|
|
255
|
-
* @
|
|
254
|
+
* @memberof state
|
|
256
255
|
* @public
|
|
257
256
|
* @function
|
|
258
257
|
* @param {boolean} [pauseTrack=false] pause current track on screen stop.
|
|
@@ -279,7 +278,7 @@ var state = {
|
|
|
279
278
|
/**
|
|
280
279
|
* pause the current screen object
|
|
281
280
|
* @name pause
|
|
282
|
-
* @
|
|
281
|
+
* @memberof state
|
|
283
282
|
* @public
|
|
284
283
|
* @function
|
|
285
284
|
* @param {boolean} [music=false] pause current music track on screen pause
|
|
@@ -305,7 +304,7 @@ var state = {
|
|
|
305
304
|
/**
|
|
306
305
|
* Restart the screen object from a full stop.
|
|
307
306
|
* @name restart
|
|
308
|
-
* @
|
|
307
|
+
* @memberof state
|
|
309
308
|
* @public
|
|
310
309
|
* @function
|
|
311
310
|
* @param {boolean} [music=false] resume current music track on screen resume
|
|
@@ -333,7 +332,7 @@ var state = {
|
|
|
333
332
|
/**
|
|
334
333
|
* resume the screen object
|
|
335
334
|
* @name resume
|
|
336
|
-
* @
|
|
335
|
+
* @memberof state
|
|
337
336
|
* @public
|
|
338
337
|
* @function
|
|
339
338
|
* @param {boolean} [music=false] resume current music track on screen resume
|
|
@@ -358,7 +357,7 @@ var state = {
|
|
|
358
357
|
/**
|
|
359
358
|
* return the running state of the state manager
|
|
360
359
|
* @name isRunning
|
|
361
|
-
* @
|
|
360
|
+
* @memberof state
|
|
362
361
|
* @public
|
|
363
362
|
* @function
|
|
364
363
|
* @returns {boolean} true if a "process is running"
|
|
@@ -370,7 +369,7 @@ var state = {
|
|
|
370
369
|
/**
|
|
371
370
|
* Return the pause state of the state manager
|
|
372
371
|
* @name isPaused
|
|
373
|
-
* @
|
|
372
|
+
* @memberof state
|
|
374
373
|
* @public
|
|
375
374
|
* @function
|
|
376
375
|
* @returns {boolean} true if the game is paused
|
|
@@ -382,11 +381,11 @@ var state = {
|
|
|
382
381
|
/**
|
|
383
382
|
* associate the specified state with a Stage
|
|
384
383
|
* @name set
|
|
385
|
-
* @
|
|
384
|
+
* @memberof state
|
|
386
385
|
* @public
|
|
387
386
|
* @function
|
|
388
387
|
* @param {number} state State ID (see constants)
|
|
389
|
-
* @param {
|
|
388
|
+
* @param {Stage} stage Instantiated Stage to associate with state ID
|
|
390
389
|
* @param {boolean} [start = false] if true the state will be changed immediately after adding it.
|
|
391
390
|
* @example
|
|
392
391
|
* class MenuButton extends me.GUI_Object {
|
|
@@ -442,10 +441,10 @@ var state = {
|
|
|
442
441
|
* return a reference to the current screen object<br>
|
|
443
442
|
* useful to call a object specific method
|
|
444
443
|
* @name current
|
|
445
|
-
* @
|
|
444
|
+
* @memberof state
|
|
446
445
|
* @public
|
|
447
446
|
* @function
|
|
448
|
-
* @returns {
|
|
447
|
+
* @returns {Stage}
|
|
449
448
|
*/
|
|
450
449
|
current() {
|
|
451
450
|
if (typeof _stages[_state] !== "undefined") {
|
|
@@ -456,11 +455,11 @@ var state = {
|
|
|
456
455
|
/**
|
|
457
456
|
* specify a global transition effect
|
|
458
457
|
* @name transition
|
|
459
|
-
* @
|
|
458
|
+
* @memberof state
|
|
460
459
|
* @public
|
|
461
460
|
* @function
|
|
462
461
|
* @param {string} effect (only "fade" is supported for now)
|
|
463
|
-
* @param {
|
|
462
|
+
* @param {Color|string} color a CSS color value
|
|
464
463
|
* @param {number} [duration=1000] expressed in milliseconds
|
|
465
464
|
*/
|
|
466
465
|
transition(effect, color, duration) {
|
|
@@ -473,7 +472,7 @@ var state = {
|
|
|
473
472
|
/**
|
|
474
473
|
* enable/disable transition for a specific state (by default enabled for all)
|
|
475
474
|
* @name setTransition
|
|
476
|
-
* @
|
|
475
|
+
* @memberof state
|
|
477
476
|
* @public
|
|
478
477
|
* @function
|
|
479
478
|
* @param {number} state State ID (see constants)
|
|
@@ -486,7 +485,7 @@ var state = {
|
|
|
486
485
|
/**
|
|
487
486
|
* change the game/app state
|
|
488
487
|
* @name change
|
|
489
|
-
* @
|
|
488
|
+
* @memberof state
|
|
490
489
|
* @public
|
|
491
490
|
* @function
|
|
492
491
|
* @param {number} state State ID (see constants)
|
|
@@ -541,7 +540,7 @@ var state = {
|
|
|
541
540
|
/**
|
|
542
541
|
* return true if the specified state is the current one
|
|
543
542
|
* @name isCurrent
|
|
544
|
-
* @
|
|
543
|
+
* @memberof state
|
|
545
544
|
* @public
|
|
546
545
|
* @function
|
|
547
546
|
* @param {number} state State ID (see constants)
|