melonjs 10.8.0 → 10.11.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/LICENSE.md +1 -1
- package/README.md +32 -25
- package/dist/melonjs.js +1833 -2267
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +642 -1416
- package/dist/melonjs.module.js +1778 -2237
- package/package.json +16 -16
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +1 -4
- package/src/game.js +2 -2
- package/src/geometries/ellipse.js +18 -27
- package/src/geometries/line.js +5 -8
- package/src/geometries/path2d.js +10 -20
- package/src/geometries/poly.js +28 -45
- package/src/geometries/rectangle.js +24 -36
- package/src/geometries/roundrect.js +96 -3
- package/src/index.js +7 -2
- package/src/input/gamepad.js +5 -16
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +9 -6
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +1 -4
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +16 -5
- package/src/math/color.js +10 -30
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +11 -12
- package/src/physics/body.js +1 -1
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +0 -1
- package/src/physics/detector.js +0 -4
- package/src/physics/quadtree.js +0 -7
- package/src/physics/sat.js +3 -3
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/index.js +1 -0
- package/src/polyfill/roundrect.js +237 -0
- package/src/renderable/GUI.js +5 -10
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/container.js +26 -54
- package/src/renderable/dragndrop.js +0 -9
- package/src/renderable/imagelayer.js +3 -7
- package/src/renderable/light2d.js +114 -0
- package/src/renderable/renderable.js +22 -43
- package/src/renderable/sprite.js +13 -25
- package/src/renderable/trigger.js +1 -1
- package/src/state/stage.js +72 -6
- package/src/state/state.js +3 -20
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +19 -8
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +19 -21
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +2 -5
- package/src/video/canvas/canvas_renderer.js +76 -103
- package/src/video/renderer.js +43 -50
- package/src/video/{texture.js → texture/atlas.js} +8 -8
- package/src/video/{texture_cache.js → texture/cache.js} +4 -5
- package/src/video/texture/canvas_texture.js +99 -0
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +4 -7
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +73 -97
|
@@ -227,7 +227,7 @@ class Renderable extends Rect {
|
|
|
227
227
|
* A mask limits rendering elements to the shape and position of the given mask object.
|
|
228
228
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
229
229
|
* @public
|
|
230
|
-
* @type {Rect|Polygon|Line|Ellipse}
|
|
230
|
+
* @type {Rect|RoundRect|Polygon|Line|Ellipse}
|
|
231
231
|
* @name mask
|
|
232
232
|
* @default undefined
|
|
233
233
|
* @memberof Renderable#
|
|
@@ -380,8 +380,7 @@ class Renderable extends Rect {
|
|
|
380
380
|
/**
|
|
381
381
|
* returns the bounding box for this renderable
|
|
382
382
|
* @name getBounds
|
|
383
|
-
* @memberof Renderable
|
|
384
|
-
* @function
|
|
383
|
+
* @memberof Renderable
|
|
385
384
|
* @returns {Bounds} bounding box Rectangle object
|
|
386
385
|
*/
|
|
387
386
|
getBounds() {
|
|
@@ -401,8 +400,7 @@ class Renderable extends Rect {
|
|
|
401
400
|
/**
|
|
402
401
|
* get the renderable alpha channel value<br>
|
|
403
402
|
* @name getOpacity
|
|
404
|
-
* @memberof Renderable
|
|
405
|
-
* @function
|
|
403
|
+
* @memberof Renderable
|
|
406
404
|
* @returns {number} current opacity value between 0 and 1
|
|
407
405
|
*/
|
|
408
406
|
getOpacity() {
|
|
@@ -412,8 +410,7 @@ class Renderable extends Rect {
|
|
|
412
410
|
/**
|
|
413
411
|
* set the renderable alpha channel value<br>
|
|
414
412
|
* @name setOpacity
|
|
415
|
-
* @memberof Renderable
|
|
416
|
-
* @function
|
|
413
|
+
* @memberof Renderable
|
|
417
414
|
* @param {number} alpha opacity value between 0.0 and 1.0
|
|
418
415
|
*/
|
|
419
416
|
setOpacity(alpha) {
|
|
@@ -431,8 +428,7 @@ class Renderable extends Rect {
|
|
|
431
428
|
* flip the renderable on the horizontal axis (around the center of the renderable)
|
|
432
429
|
* @see Matrix2d#scaleX
|
|
433
430
|
* @name flipX
|
|
434
|
-
* @memberof Renderable
|
|
435
|
-
* @function
|
|
431
|
+
* @memberof Renderable
|
|
436
432
|
* @param {boolean} [flip=true] `true` to flip this renderable.
|
|
437
433
|
* @returns {Renderable} Reference to this object for method chaining
|
|
438
434
|
*/
|
|
@@ -446,8 +442,7 @@ class Renderable extends Rect {
|
|
|
446
442
|
* flip the renderable on the vertical axis (around the center of the renderable)
|
|
447
443
|
* @see Matrix2d#scaleY
|
|
448
444
|
* @name flipY
|
|
449
|
-
* @memberof Renderable
|
|
450
|
-
* @function
|
|
445
|
+
* @memberof Renderable
|
|
451
446
|
* @param {boolean} [flip=true] `true` to flip this renderable.
|
|
452
447
|
* @returns {Renderable} Reference to this object for method chaining
|
|
453
448
|
*/
|
|
@@ -460,9 +455,8 @@ class Renderable extends Rect {
|
|
|
460
455
|
/**
|
|
461
456
|
* multiply the renderable currentTransform with the given matrix
|
|
462
457
|
* @name transform
|
|
463
|
-
* @memberof Renderable
|
|
458
|
+
* @memberof Renderable
|
|
464
459
|
* @see Renderable#currentTransform
|
|
465
|
-
* @function
|
|
466
460
|
* @param {Matrix2d} m the transformation matrix
|
|
467
461
|
* @returns {Renderable} Reference to this object for method chaining
|
|
468
462
|
*/
|
|
@@ -478,7 +472,6 @@ class Renderable extends Rect {
|
|
|
478
472
|
* return the angle to the specified target
|
|
479
473
|
* @name angleTo
|
|
480
474
|
* @memberof Renderable
|
|
481
|
-
* @function
|
|
482
475
|
* @param {Renderable|Vector2d|Vector3d} target
|
|
483
476
|
* @returns {number} angle in radians
|
|
484
477
|
*/
|
|
@@ -502,7 +495,6 @@ class Renderable extends Rect {
|
|
|
502
495
|
* return the distance to the specified target
|
|
503
496
|
* @name distanceTo
|
|
504
497
|
* @memberof Renderable
|
|
505
|
-
* @function
|
|
506
498
|
* @param {Renderable|Vector2d|Vector3d} target
|
|
507
499
|
* @returns {number} distance
|
|
508
500
|
*/
|
|
@@ -525,8 +517,7 @@ class Renderable extends Rect {
|
|
|
525
517
|
/**
|
|
526
518
|
* Rotate this renderable towards the given target.
|
|
527
519
|
* @name lookAt
|
|
528
|
-
* @memberof Renderable
|
|
529
|
-
* @function
|
|
520
|
+
* @memberof Renderable
|
|
530
521
|
* @param {Renderable|Vector2d|Vector3d} target the renderable or position to look at
|
|
531
522
|
* @returns {Renderable} Reference to this object for method chaining
|
|
532
523
|
*/
|
|
@@ -549,8 +540,7 @@ class Renderable extends Rect {
|
|
|
549
540
|
/**
|
|
550
541
|
* Rotate this renderable by the specified angle (in radians).
|
|
551
542
|
* @name rotate
|
|
552
|
-
* @memberof Renderable
|
|
553
|
-
* @function
|
|
543
|
+
* @memberof Renderable
|
|
554
544
|
* @param {number} angle The angle to rotate (in radians)
|
|
555
545
|
* @param {Vector2d|ObservableVector2d} [v] an optional point to rotate around
|
|
556
546
|
* @returns {Renderable} Reference to this object for method chaining
|
|
@@ -571,8 +561,7 @@ class Renderable extends Rect {
|
|
|
571
561
|
* is an image, the image.width and image.height properties are unaltered but the currentTransform
|
|
572
562
|
* member will be changed.
|
|
573
563
|
* @name scale
|
|
574
|
-
* @memberof Renderable
|
|
575
|
-
* @function
|
|
564
|
+
* @memberof Renderable
|
|
576
565
|
* @param {number} x a number representing the abscissa of the scaling vector.
|
|
577
566
|
* @param {number} [y=x] a number representing the ordinate of the scaling vector.
|
|
578
567
|
* @returns {Renderable} Reference to this object for method chaining
|
|
@@ -587,8 +576,7 @@ class Renderable extends Rect {
|
|
|
587
576
|
/**
|
|
588
577
|
* scale the renderable around his anchor point
|
|
589
578
|
* @name scaleV
|
|
590
|
-
* @memberof Renderable
|
|
591
|
-
* @function
|
|
579
|
+
* @memberof Renderable
|
|
592
580
|
* @param {Vector2d} v scaling vector
|
|
593
581
|
* @returns {Renderable} Reference to this object for method chaining
|
|
594
582
|
*/
|
|
@@ -601,8 +589,7 @@ class Renderable extends Rect {
|
|
|
601
589
|
* update function. <br>
|
|
602
590
|
* automatically called by the game manager {@link game}
|
|
603
591
|
* @name update
|
|
604
|
-
* @memberof Renderable
|
|
605
|
-
* @function
|
|
592
|
+
* @memberof Renderable
|
|
606
593
|
* @protected
|
|
607
594
|
* @param {number} dt time since the last update in milliseconds.
|
|
608
595
|
* @returns {boolean} true if the renderable is dirty
|
|
@@ -615,8 +602,7 @@ class Renderable extends Rect {
|
|
|
615
602
|
* update the bounding box for this shape.
|
|
616
603
|
* @ignore
|
|
617
604
|
* @name updateBounds
|
|
618
|
-
* @memberof Renderable
|
|
619
|
-
* @function
|
|
605
|
+
* @memberof Renderable
|
|
620
606
|
* @returns {Bounds} this shape bounding box Rectangle object
|
|
621
607
|
*/
|
|
622
608
|
updateBounds() {
|
|
@@ -629,8 +615,7 @@ class Renderable extends Rect {
|
|
|
629
615
|
* update the renderable's bounding rect (private)
|
|
630
616
|
* @ignore
|
|
631
617
|
* @name updateBoundsPos
|
|
632
|
-
* @memberof Renderable
|
|
633
|
-
* @function
|
|
618
|
+
* @memberof Renderable
|
|
634
619
|
*/
|
|
635
620
|
updateBoundsPos(newX, newY) {
|
|
636
621
|
var bounds = this.getBounds();
|
|
@@ -655,14 +640,14 @@ class Renderable extends Rect {
|
|
|
655
640
|
if (this.ancestor instanceof Container && this.floating !== true) {
|
|
656
641
|
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
657
642
|
}
|
|
658
|
-
|
|
643
|
+
|
|
644
|
+
this.isDirty = true;
|
|
659
645
|
}
|
|
660
646
|
|
|
661
647
|
/**
|
|
662
648
|
* return the renderable absolute position in the game world
|
|
663
649
|
* @name getAbsolutePosition
|
|
664
|
-
* @memberof Renderable
|
|
665
|
-
* @function
|
|
650
|
+
* @memberof Renderable
|
|
666
651
|
* @returns {Vector2d}
|
|
667
652
|
*/
|
|
668
653
|
getAbsolutePosition() {
|
|
@@ -681,8 +666,7 @@ class Renderable extends Rect {
|
|
|
681
666
|
* called when the anchor point value is changed
|
|
682
667
|
* @private
|
|
683
668
|
* @name onAnchorUpdate
|
|
684
|
-
* @memberof Renderable
|
|
685
|
-
* @function
|
|
669
|
+
* @memberof Renderable
|
|
686
670
|
* @param {number} x the new X value to be set for the anchor
|
|
687
671
|
* @param {number} y the new Y value to be set for the anchor
|
|
688
672
|
*/
|
|
@@ -699,8 +683,7 @@ class Renderable extends Rect {
|
|
|
699
683
|
* (apply defined transforms, anchor point). <br>
|
|
700
684
|
* automatically called by the game manager {@link game}
|
|
701
685
|
* @name preDraw
|
|
702
|
-
* @memberof Renderable
|
|
703
|
-
* @function
|
|
686
|
+
* @memberof Renderable
|
|
704
687
|
* @protected
|
|
705
688
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
706
689
|
*/
|
|
@@ -755,8 +738,7 @@ class Renderable extends Rect {
|
|
|
755
738
|
* object draw. <br>
|
|
756
739
|
* automatically called by the game manager {@link game}
|
|
757
740
|
* @name draw
|
|
758
|
-
* @memberof Renderable
|
|
759
|
-
* @function
|
|
741
|
+
* @memberof Renderable
|
|
760
742
|
* @protected
|
|
761
743
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
762
744
|
*/
|
|
@@ -768,8 +750,7 @@ class Renderable extends Rect {
|
|
|
768
750
|
* restore the rendering context after drawing. <br>
|
|
769
751
|
* automatically called by the game manager {@link game}
|
|
770
752
|
* @name postDraw
|
|
771
|
-
* @memberof Renderable
|
|
772
|
-
* @function
|
|
753
|
+
* @memberof Renderable
|
|
773
754
|
* @protected
|
|
774
755
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
775
756
|
*/
|
|
@@ -793,8 +774,7 @@ class Renderable extends Rect {
|
|
|
793
774
|
* onCollision callback, triggered in case of collision,
|
|
794
775
|
* when this renderable body is colliding with another one
|
|
795
776
|
* @name onCollision
|
|
796
|
-
* @memberof Renderable
|
|
797
|
-
* @function
|
|
777
|
+
* @memberof Renderable
|
|
798
778
|
* @param {collision.ResponseObject} response the collision response object
|
|
799
779
|
* @param {Renderable} other the other renderable touching this one (a reference to response.a or response.b)
|
|
800
780
|
* @returns {boolean} true if the object should respond to the collision (its position and velocity will be corrected)
|
|
@@ -871,7 +851,6 @@ class Renderable extends Rect {
|
|
|
871
851
|
* Called by engine before deleting the object
|
|
872
852
|
* @name onDestroyEvent
|
|
873
853
|
* @memberof Renderable
|
|
874
|
-
* @function
|
|
875
854
|
*/
|
|
876
855
|
onDestroyEvent() {
|
|
877
856
|
// to be extended !
|
package/src/renderable/sprite.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { renderer } from "./../video/video.js";
|
|
2
2
|
import pool from "./../system/pooling.js";
|
|
3
3
|
import loader from "./../loader/loader.js";
|
|
4
|
-
import { TextureAtlas } from "./../video/texture.js";
|
|
4
|
+
import { TextureAtlas } from "./../video/texture/atlas.js";
|
|
5
5
|
import Renderable from "./renderable.js";
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -209,8 +209,7 @@ class Sprite extends Renderable {
|
|
|
209
209
|
/**
|
|
210
210
|
* return the flickering state of the object
|
|
211
211
|
* @name isFlickering
|
|
212
|
-
* @memberof Sprite
|
|
213
|
-
* @function
|
|
212
|
+
* @memberof Sprite
|
|
214
213
|
* @returns {boolean}
|
|
215
214
|
*/
|
|
216
215
|
isFlickering() {
|
|
@@ -220,8 +219,7 @@ class Sprite extends Renderable {
|
|
|
220
219
|
/**
|
|
221
220
|
* make the object flicker
|
|
222
221
|
* @name flicker
|
|
223
|
-
* @memberof Sprite
|
|
224
|
-
* @function
|
|
222
|
+
* @memberof Sprite
|
|
225
223
|
* @param {number} duration expressed in milliseconds
|
|
226
224
|
* @param {Function} callback Function to call when flickering ends
|
|
227
225
|
* @returns {Sprite} Reference to this object for method chaining
|
|
@@ -251,8 +249,7 @@ class Sprite extends Renderable {
|
|
|
251
249
|
* logic as per the following example :<br>
|
|
252
250
|
* <img src="images/spritesheet_grid.png"/>
|
|
253
251
|
* @name addAnimation
|
|
254
|
-
* @memberof Sprite
|
|
255
|
-
* @function
|
|
252
|
+
* @memberof Sprite
|
|
256
253
|
* @param {string} name animation id
|
|
257
254
|
* @param {number[]|string[]|object[]} index list of sprite index or name
|
|
258
255
|
* defining the animation. Can also use objects to specify delay for each frame, see below
|
|
@@ -351,8 +348,7 @@ class Sprite extends Renderable {
|
|
|
351
348
|
* set the current animation
|
|
352
349
|
* this will always change the animation & set the frame to zero
|
|
353
350
|
* @name setCurrentAnimation
|
|
354
|
-
* @memberof Sprite
|
|
355
|
-
* @function
|
|
351
|
+
* @memberof Sprite
|
|
356
352
|
* @param {string} name animation id
|
|
357
353
|
* @param {string|Function} [resetAnim] animation id to switch to when complete, or callback
|
|
358
354
|
* @param {boolean} [preserve_dt=false] if false will reset the elapsed time counter since last frame
|
|
@@ -412,8 +408,7 @@ class Sprite extends Renderable {
|
|
|
412
408
|
/**
|
|
413
409
|
* reverse the given or current animation if none is specified
|
|
414
410
|
* @name reverseAnimation
|
|
415
|
-
* @memberof Sprite
|
|
416
|
-
* @function
|
|
411
|
+
* @memberof Sprite
|
|
417
412
|
* @param {string} [name] animation id
|
|
418
413
|
* @returns {Sprite} Reference to this object for method chaining
|
|
419
414
|
* @see Sprite#animationspeed
|
|
@@ -431,8 +426,7 @@ class Sprite extends Renderable {
|
|
|
431
426
|
/**
|
|
432
427
|
* return true if the specified animation is the current one.
|
|
433
428
|
* @name isCurrentAnimation
|
|
434
|
-
* @memberof Sprite
|
|
435
|
-
* @function
|
|
429
|
+
* @memberof Sprite
|
|
436
430
|
* @param {string} name animation id
|
|
437
431
|
* @returns {boolean}
|
|
438
432
|
* @example
|
|
@@ -448,8 +442,7 @@ class Sprite extends Renderable {
|
|
|
448
442
|
* change the current texture atlas region for this sprite
|
|
449
443
|
* @see Texture.getRegion
|
|
450
444
|
* @name setRegion
|
|
451
|
-
* @memberof Sprite
|
|
452
|
-
* @function
|
|
445
|
+
* @memberof Sprite
|
|
453
446
|
* @param {object} region typically returned through me.Texture.getRegion()
|
|
454
447
|
* @returns {Sprite} Reference to this object for method chaining
|
|
455
448
|
* @example
|
|
@@ -480,8 +473,7 @@ class Sprite extends Renderable {
|
|
|
480
473
|
/**
|
|
481
474
|
* force the current animation frame index.
|
|
482
475
|
* @name setAnimationFrame
|
|
483
|
-
* @memberof Sprite
|
|
484
|
-
* @function
|
|
476
|
+
* @memberof Sprite
|
|
485
477
|
* @param {number} [idx=0] animation frame index
|
|
486
478
|
* @returns {Sprite} Reference to this object for method chaining
|
|
487
479
|
* @example
|
|
@@ -496,8 +488,7 @@ class Sprite extends Renderable {
|
|
|
496
488
|
/**
|
|
497
489
|
* return the current animation frame index.
|
|
498
490
|
* @name getCurrentAnimationFrame
|
|
499
|
-
* @memberof Sprite
|
|
500
|
-
* @function
|
|
491
|
+
* @memberof Sprite
|
|
501
492
|
* @returns {number} current animation frame index
|
|
502
493
|
*/
|
|
503
494
|
getCurrentAnimationFrame() {
|
|
@@ -507,8 +498,7 @@ class Sprite extends Renderable {
|
|
|
507
498
|
/**
|
|
508
499
|
* Returns the frame object by the index.
|
|
509
500
|
* @name getAnimationFrameObjectByIndex
|
|
510
|
-
* @memberof Sprite
|
|
511
|
-
* @function
|
|
501
|
+
* @memberof Sprite
|
|
512
502
|
* @ignore
|
|
513
503
|
* @param {number} id the frame id
|
|
514
504
|
* @returns {number} if using number indices. Returns {object} containing frame data if using texture atlas
|
|
@@ -521,8 +511,7 @@ class Sprite extends Renderable {
|
|
|
521
511
|
* update function. <br>
|
|
522
512
|
* automatically called by the game manager {@link game}
|
|
523
513
|
* @name update
|
|
524
|
-
* @memberof Sprite
|
|
525
|
-
* @function
|
|
514
|
+
* @memberof Sprite
|
|
526
515
|
* @protected
|
|
527
516
|
* @param {number} dt time since the last update in milliseconds.
|
|
528
517
|
* @returns {boolean} true if the Sprite is dirty
|
|
@@ -600,8 +589,7 @@ class Sprite extends Renderable {
|
|
|
600
589
|
* sprite draw. <br>
|
|
601
590
|
* automatically called by the game manager {@link game}
|
|
602
591
|
* @name draw
|
|
603
|
-
* @memberof Sprite
|
|
604
|
-
* @function
|
|
592
|
+
* @memberof Sprite
|
|
605
593
|
* @protected
|
|
606
594
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
607
595
|
*/
|
|
@@ -3,6 +3,7 @@ import collision from "./../physics/collision.js";
|
|
|
3
3
|
import Body from "./../physics/body.js";
|
|
4
4
|
import level from "./../level/level.js";
|
|
5
5
|
import { world, viewport } from "./../game.js";
|
|
6
|
+
import pool from "./../system/pooling.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* @classdesc
|
|
@@ -105,7 +106,6 @@ class Trigger extends Renderable {
|
|
|
105
106
|
* trigger this event
|
|
106
107
|
* @name triggerEvent
|
|
107
108
|
* @memberof Trigger
|
|
108
|
-
* @function
|
|
109
109
|
* @protected
|
|
110
110
|
*/
|
|
111
111
|
triggerEvent() {
|
package/src/state/stage.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { renderer } from "./../video/video.js";
|
|
2
2
|
import * as game from "./../game.js";
|
|
3
3
|
import Camera2d from "./../camera/camera2d.js";
|
|
4
|
+
import Color from "./../math/color.js";
|
|
4
5
|
|
|
5
6
|
// a default camera instance to use across all stages
|
|
6
7
|
var default_camera;
|
|
@@ -37,6 +38,40 @@ class Stage {
|
|
|
37
38
|
*/
|
|
38
39
|
this.cameras = new Map();
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* The list of active lights in this stage.
|
|
43
|
+
* (Note: Canvas Renderering mode will only properly support one light per stage)
|
|
44
|
+
* @public
|
|
45
|
+
* @type {Map<Light2d>}
|
|
46
|
+
* @name lights
|
|
47
|
+
* @memberof Stage
|
|
48
|
+
* @see Light2d
|
|
49
|
+
* @see Stage.ambientLight
|
|
50
|
+
* @example
|
|
51
|
+
* // create a white spot light
|
|
52
|
+
* var whiteLight = new me.Light2d(0, 0, 140, "#fff", 0.7);
|
|
53
|
+
* // and add the light to this current stage
|
|
54
|
+
* this.lights.set("whiteLight", whiteLight);
|
|
55
|
+
* // set a dark ambient light
|
|
56
|
+
* this.ambientLight.parseCSS("#1117");
|
|
57
|
+
* // make the light follow the mouse
|
|
58
|
+
* me.input.registerPointerEvent("pointermove", me.game.viewport, (event) => {
|
|
59
|
+
* whiteLight.centerOn(event.gameX, event.gameY);
|
|
60
|
+
* });
|
|
61
|
+
*/
|
|
62
|
+
this.lights = new Map();
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* an ambient light that will be added to the stage rendering
|
|
66
|
+
* @public
|
|
67
|
+
* @type {Color}
|
|
68
|
+
* @name ambientLight
|
|
69
|
+
* @memberof Stage
|
|
70
|
+
* @default "#000000"
|
|
71
|
+
* @see Light2d
|
|
72
|
+
*/
|
|
73
|
+
this.ambientLight = new Color(0, 0, 0, 0);
|
|
74
|
+
|
|
40
75
|
/**
|
|
41
76
|
* The given constructor options
|
|
42
77
|
* @public
|
|
@@ -81,7 +116,6 @@ class Stage {
|
|
|
81
116
|
* @name update
|
|
82
117
|
* @memberof Stage
|
|
83
118
|
* @ignore
|
|
84
|
-
* @function
|
|
85
119
|
* @param {number} dt time since the last update in milliseconds.
|
|
86
120
|
* @returns {boolean}
|
|
87
121
|
*/
|
|
@@ -92,7 +126,14 @@ class Stage {
|
|
|
92
126
|
// update the camera/viewport
|
|
93
127
|
// iterate through all cameras
|
|
94
128
|
this.cameras.forEach(function(camera) {
|
|
95
|
-
if (camera.update(dt)) {
|
|
129
|
+
if (camera.update(dt) === true) {
|
|
130
|
+
isDirty = true;
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// update all lights
|
|
135
|
+
this.lights.forEach((light) => {
|
|
136
|
+
if (light.update(dt) === true) {
|
|
96
137
|
isDirty = true;
|
|
97
138
|
};
|
|
98
139
|
});
|
|
@@ -105,14 +146,36 @@ class Stage {
|
|
|
105
146
|
* @name draw
|
|
106
147
|
* @memberof Stage
|
|
107
148
|
* @ignore
|
|
108
|
-
* @function
|
|
109
149
|
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
110
150
|
*/
|
|
111
151
|
draw(renderer) {
|
|
112
152
|
// iterate through all cameras
|
|
113
|
-
this.cameras.forEach(
|
|
153
|
+
this.cameras.forEach((camera) => {
|
|
114
154
|
// render the root container
|
|
115
155
|
camera.draw(renderer, game.world);
|
|
156
|
+
|
|
157
|
+
// render the ambient light
|
|
158
|
+
if (this.ambientLight.alpha !== 0) {
|
|
159
|
+
renderer.save();
|
|
160
|
+
// iterate through all lights
|
|
161
|
+
this.lights.forEach((light) => {
|
|
162
|
+
// cut out all lights visible areas
|
|
163
|
+
renderer.setMask(light.getVisibleArea(), true);
|
|
164
|
+
});
|
|
165
|
+
// fill the screen with the ambient color
|
|
166
|
+
renderer.setColor(this.ambientLight);
|
|
167
|
+
renderer.fillRect(0, 0, camera.width, camera.height);
|
|
168
|
+
// clear all masks
|
|
169
|
+
renderer.clearMask();
|
|
170
|
+
renderer.restore();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// render all lights
|
|
174
|
+
this.lights.forEach((light) => {
|
|
175
|
+
light.preDraw(renderer, game.world);
|
|
176
|
+
light.draw(renderer, game.world);
|
|
177
|
+
light.postDraw(renderer, game.world);
|
|
178
|
+
});
|
|
116
179
|
});
|
|
117
180
|
}
|
|
118
181
|
|
|
@@ -123,6 +186,11 @@ class Stage {
|
|
|
123
186
|
destroy() {
|
|
124
187
|
// clear all cameras
|
|
125
188
|
this.cameras.clear();
|
|
189
|
+
// clear all lights
|
|
190
|
+
this.lights.forEach((light) => {
|
|
191
|
+
light.destroy();
|
|
192
|
+
});
|
|
193
|
+
this.lights.clear();
|
|
126
194
|
// notify the object
|
|
127
195
|
this.onDestroyEvent.apply(this, arguments);
|
|
128
196
|
}
|
|
@@ -133,7 +201,6 @@ class Stage {
|
|
|
133
201
|
* this is typically where you will load a level, add renderables, etc...
|
|
134
202
|
* @name onResetEvent
|
|
135
203
|
* @memberof Stage
|
|
136
|
-
* @function
|
|
137
204
|
* @param {object} [...arguments] optional arguments passed when switching state
|
|
138
205
|
* @see state#change
|
|
139
206
|
*/
|
|
@@ -150,7 +217,6 @@ class Stage {
|
|
|
150
217
|
* called by the state manager before switching to another state
|
|
151
218
|
* @name onDestroyEvent
|
|
152
219
|
* @memberof Stage
|
|
153
|
-
* @function
|
|
154
220
|
*/
|
|
155
221
|
onDestroyEvent() {
|
|
156
222
|
// execute onDestroyEvent function if given through the constructor
|
package/src/state/state.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { pauseTrack, resumeTrack } from "./../audio/audio.js";
|
|
2
2
|
import * as fctUtil from "./../utils/function.js";
|
|
3
3
|
import * as event from "./../system/event.js";
|
|
4
|
-
import timer from "./../system/timer.js";
|
|
5
4
|
import * as game from "./../game.js";
|
|
6
5
|
import Stage from "./../state/stage.js";
|
|
7
6
|
import DefaultLoadingScreen from "./../loader/loadingscreen.js";
|
|
@@ -41,9 +40,6 @@ var _pauseTime = 0;
|
|
|
41
40
|
function _startRunLoop() {
|
|
42
41
|
// ensure nothing is running first and in valid state
|
|
43
42
|
if ((_animFrameId === -1) && (_state !== -1)) {
|
|
44
|
-
// reset the timer
|
|
45
|
-
timer.reset();
|
|
46
|
-
|
|
47
43
|
// start the main loop
|
|
48
44
|
_animFrameId = globalThis.requestAnimationFrame(_renderFrame);
|
|
49
45
|
}
|
|
@@ -56,9 +52,6 @@ function _startRunLoop() {
|
|
|
56
52
|
function _resumeRunLoop() {
|
|
57
53
|
// ensure game is actually paused and in valid state
|
|
58
54
|
if (_isPaused && (_state !== -1)) {
|
|
59
|
-
// reset the timer
|
|
60
|
-
timer.reset();
|
|
61
|
-
|
|
62
55
|
_isPaused = false;
|
|
63
56
|
}
|
|
64
57
|
}
|
|
@@ -124,6 +117,9 @@ function _switchState(state) {
|
|
|
124
117
|
// new requested state
|
|
125
118
|
_startRunLoop();
|
|
126
119
|
|
|
120
|
+
// publish the pause event
|
|
121
|
+
event.emit(event.STATE_CHANGE);
|
|
122
|
+
|
|
127
123
|
// execute callback if defined
|
|
128
124
|
if (_onSwitchComplete) {
|
|
129
125
|
_onSwitchComplete();
|
|
@@ -253,7 +249,6 @@ var state = {
|
|
|
253
249
|
* @name stop
|
|
254
250
|
* @memberof state
|
|
255
251
|
* @public
|
|
256
|
-
* @function
|
|
257
252
|
* @param {boolean} [pauseTrack=false] pause current track on screen stop.
|
|
258
253
|
*/
|
|
259
254
|
stop(pauseTrack=false) {
|
|
@@ -280,7 +275,6 @@ var state = {
|
|
|
280
275
|
* @name pause
|
|
281
276
|
* @memberof state
|
|
282
277
|
* @public
|
|
283
|
-
* @function
|
|
284
278
|
* @param {boolean} [music=false] pause current music track on screen pause
|
|
285
279
|
*/
|
|
286
280
|
pause(music=false) {
|
|
@@ -306,7 +300,6 @@ var state = {
|
|
|
306
300
|
* @name restart
|
|
307
301
|
* @memberof state
|
|
308
302
|
* @public
|
|
309
|
-
* @function
|
|
310
303
|
* @param {boolean} [music=false] resume current music track on screen resume
|
|
311
304
|
*/
|
|
312
305
|
restart(music=false) {
|
|
@@ -334,7 +327,6 @@ var state = {
|
|
|
334
327
|
* @name resume
|
|
335
328
|
* @memberof state
|
|
336
329
|
* @public
|
|
337
|
-
* @function
|
|
338
330
|
* @param {boolean} [music=false] resume current music track on screen resume
|
|
339
331
|
*/
|
|
340
332
|
resume(music=false) {
|
|
@@ -359,7 +351,6 @@ var state = {
|
|
|
359
351
|
* @name isRunning
|
|
360
352
|
* @memberof state
|
|
361
353
|
* @public
|
|
362
|
-
* @function
|
|
363
354
|
* @returns {boolean} true if a "process is running"
|
|
364
355
|
*/
|
|
365
356
|
isRunning() {
|
|
@@ -371,7 +362,6 @@ var state = {
|
|
|
371
362
|
* @name isPaused
|
|
372
363
|
* @memberof state
|
|
373
364
|
* @public
|
|
374
|
-
* @function
|
|
375
365
|
* @returns {boolean} true if the game is paused
|
|
376
366
|
*/
|
|
377
367
|
isPaused() {
|
|
@@ -383,7 +373,6 @@ var state = {
|
|
|
383
373
|
* @name set
|
|
384
374
|
* @memberof state
|
|
385
375
|
* @public
|
|
386
|
-
* @function
|
|
387
376
|
* @param {number} state State ID (see constants)
|
|
388
377
|
* @param {Stage} stage Instantiated Stage to associate with state ID
|
|
389
378
|
* @param {boolean} [start = false] if true the state will be changed immediately after adding it.
|
|
@@ -443,7 +432,6 @@ var state = {
|
|
|
443
432
|
* @name current
|
|
444
433
|
* @memberof state
|
|
445
434
|
* @public
|
|
446
|
-
* @function
|
|
447
435
|
* @returns {Stage}
|
|
448
436
|
*/
|
|
449
437
|
current() {
|
|
@@ -457,7 +445,6 @@ var state = {
|
|
|
457
445
|
* @name transition
|
|
458
446
|
* @memberof state
|
|
459
447
|
* @public
|
|
460
|
-
* @function
|
|
461
448
|
* @param {string} effect (only "fade" is supported for now)
|
|
462
449
|
* @param {Color|string} color a CSS color value
|
|
463
450
|
* @param {number} [duration=1000] expressed in milliseconds
|
|
@@ -474,7 +461,6 @@ var state = {
|
|
|
474
461
|
* @name setTransition
|
|
475
462
|
* @memberof state
|
|
476
463
|
* @public
|
|
477
|
-
* @function
|
|
478
464
|
* @param {number} state State ID (see constants)
|
|
479
465
|
* @param {boolean} enable
|
|
480
466
|
*/
|
|
@@ -487,7 +473,6 @@ var state = {
|
|
|
487
473
|
* @name change
|
|
488
474
|
* @memberof state
|
|
489
475
|
* @public
|
|
490
|
-
* @function
|
|
491
476
|
* @param {number} state State ID (see constants)
|
|
492
477
|
* @param {boolean} forceChange if true the state will be changed immediately
|
|
493
478
|
* @param {object} [...arguments] extra arguments to be passed to the reset functions
|
|
@@ -511,7 +496,6 @@ var state = {
|
|
|
511
496
|
}
|
|
512
497
|
// if fading effect
|
|
513
498
|
if (_fade.duration && _stages[state].transition) {
|
|
514
|
-
/** @ignore */
|
|
515
499
|
_onSwitchComplete = () => {
|
|
516
500
|
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
517
501
|
};
|
|
@@ -542,7 +526,6 @@ var state = {
|
|
|
542
526
|
* @name isCurrent
|
|
543
527
|
* @memberof state
|
|
544
528
|
* @public
|
|
545
|
-
* @function
|
|
546
529
|
* @param {number} state State ID (see constants)
|
|
547
530
|
* @returns {boolean} true if the specified state is the current one
|
|
548
531
|
*/
|