littlejsengine 1.5.0 → 1.5.2
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/build.bat +4 -3
- package/engine/engine.all.js +193 -105
- package/engine/engine.all.min.js +1 -1
- package/engine/engine.all.module.js +388 -181
- package/engine/engine.all.module.min.js +1 -1
- package/engine/engine.all.release.js +186 -103
- package/engine/engine.js +57 -22
- package/engine/engineAudio.js +1 -1
- package/engine/engineDebug.js +7 -2
- package/engine/engineDraw.js +24 -26
- package/engine/engineExport.js +195 -76
- package/engine/engineInput.js +6 -1
- package/engine/engineMedals.js +1 -0
- package/engine/engineObject.js +6 -6
- package/engine/engineParticles.js +5 -5
- package/engine/engineSettings.js +46 -20
- package/engine/engineTileLayer.js +13 -12
- package/engine/engineUtilities.js +14 -8
- package/engine/engineWebGL.js +13 -2
- package/engine/index.d.ts +1796 -1615
- package/examples/breakout/game.js +3 -1
- package/examples/breakout/index.html +3 -3
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +1 -1
- package/examples/platformer/game.js +2 -0
- package/examples/platformer/gameObjects.js +3 -3
- package/examples/platformer/index.html +6 -6
- package/examples/puzzle/index.html +2 -2
- package/examples/stress/index.html +4 -4
- package/examples/typescript/game.js +89 -89
- package/examples/typescript/index.html +1 -1
- package/index.html +13 -13
- package/package.json +7 -7
- package/buildSetup.bat +0 -10
|
@@ -43,7 +43,8 @@ const debugSaveCanvas = ()=> {}
|
|
|
43
43
|
'use strict';
|
|
44
44
|
|
|
45
45
|
/** A shortcut to get Math.PI
|
|
46
|
-
* @
|
|
46
|
+
* @type {Number}
|
|
47
|
+
* @default Math.PI
|
|
47
48
|
* @memberof Utilities */
|
|
48
49
|
const PI = Math.PI;
|
|
49
50
|
|
|
@@ -123,7 +124,7 @@ const nearestPowerOfTwo = (v)=> 2**Math.ceil(Math.log2(v));
|
|
|
123
124
|
* @param {Vector2} [sizeB] - Size of box B
|
|
124
125
|
* @return {Boolean} - True if overlapping
|
|
125
126
|
* @memberof Utilities */
|
|
126
|
-
const isOverlapping = (pA, sA, pB, sB)=> abs(pA.x - pB.x)*2 < sA.x + sB.x
|
|
127
|
+
const isOverlapping = (pA, sA, pB, sB)=> abs(pA.x - pB.x)*2 < sA.x + sB.x && abs(pA.y - pB.y)*2 < sA.y + sB.y;
|
|
127
128
|
|
|
128
129
|
/** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
|
|
129
130
|
* @param {Number} [frequency=1] - Frequency of the wave in Hz
|
|
@@ -177,8 +178,8 @@ const randInCircle = (radius=1, minRadius=0)=> radius > 0 ? randVector(radius *
|
|
|
177
178
|
const randVector = (length=1)=> new Vector2().setAngle(rand(2*PI), length);
|
|
178
179
|
|
|
179
180
|
/** Returns a random color between the two passed in colors, combine components if linear
|
|
180
|
-
* @param {Color} [colorA=
|
|
181
|
-
* @param {Color} [colorB=
|
|
181
|
+
* @param {Color} [colorA=Color()]
|
|
182
|
+
* @param {Color} [colorB=Color(0,0,0,1)]
|
|
182
183
|
* @param {Boolean} [linear]
|
|
183
184
|
* @return {Color}
|
|
184
185
|
* @memberof Random */
|
|
@@ -186,6 +187,8 @@ const randColor = (cA = new Color, cB = new Color(0,0,0,1), linear)=>
|
|
|
186
187
|
linear ? cA.lerp(cB, rand()) : new Color(rand(cA.r,cB.r),rand(cA.g,cB.g),rand(cA.b,cB.b),rand(cA.a,cB.a));
|
|
187
188
|
|
|
188
189
|
/** Seed used by the randSeeded function
|
|
190
|
+
* @type {Number}
|
|
191
|
+
* @default
|
|
189
192
|
* @memberof Random */
|
|
190
193
|
let randSeed = 1;
|
|
191
194
|
|
|
@@ -324,7 +327,8 @@ class Vector2
|
|
|
324
327
|
|
|
325
328
|
/** Sets this vector with angle and length passed in
|
|
326
329
|
* @param {Number} [angle=0]
|
|
327
|
-
* @param {Number} [length=1]
|
|
330
|
+
* @param {Number} [length=1]
|
|
331
|
+
* @return {Vector2} */
|
|
328
332
|
setAngle(a=0, length=1) { this.x = length*Math.sin(a); this.y = length*Math.cos(a); return this; }
|
|
329
333
|
|
|
330
334
|
/** Returns copy of this vector rotated by the angle passed in
|
|
@@ -393,9 +397,11 @@ const colorHSLA = (h, s, l, a)=> new Color().setHSLA(h, s, l, a);
|
|
|
393
397
|
/**
|
|
394
398
|
* Color object (red, green, blue, alpha) with some helpful functions
|
|
395
399
|
* @example
|
|
396
|
-
* let a = new Color;
|
|
397
|
-
* let b = new Color(1, 0, 0);
|
|
398
|
-
* let c = new Color(0, 0, 0, 0);
|
|
400
|
+
* let a = new Color; // white
|
|
401
|
+
* let b = new Color(1, 0, 0); // red
|
|
402
|
+
* let c = new Color(0, 0, 0, 0); // transparent black
|
|
403
|
+
* let d = colorRGBA(0, 0, 1); // blue using rgb color
|
|
404
|
+
* let e = colorHSLA(.3, 1, .5); // green using hsl color
|
|
399
405
|
*/
|
|
400
406
|
class Color
|
|
401
407
|
{
|
|
@@ -619,11 +625,12 @@ class Timer
|
|
|
619
625
|
|
|
620
626
|
/** Position of camera in world space
|
|
621
627
|
* @type {Vector2}
|
|
622
|
-
* @default
|
|
628
|
+
* @default Vector2()
|
|
623
629
|
* @memberof Settings */
|
|
624
630
|
let cameraPos = vec2();
|
|
625
631
|
|
|
626
632
|
/** Scale of camera in world space
|
|
633
|
+
* @type {Number}
|
|
627
634
|
* @default
|
|
628
635
|
* @memberof Settings */
|
|
629
636
|
let cameraScale = 32;
|
|
@@ -632,24 +639,26 @@ let cameraScale = 32;
|
|
|
632
639
|
// Display settings
|
|
633
640
|
|
|
634
641
|
/** The max size of the canvas, centered if window is larger
|
|
635
|
-
* @type {Vector2}
|
|
636
|
-
* @default
|
|
642
|
+
* @type {Vector2}
|
|
643
|
+
* @default Vector2(1920,1200)
|
|
637
644
|
* @memberof Settings */
|
|
638
645
|
let canvasMaxSize = vec2(1920, 1200);
|
|
639
646
|
|
|
640
647
|
/** Fixed size of the canvas, if enabled canvas size never changes
|
|
641
648
|
* - you may also need to set mainCanvasSize if using screen space coords in startup
|
|
642
|
-
* @type {Vector2}
|
|
643
|
-
* @default
|
|
649
|
+
* @type {Vector2}
|
|
650
|
+
* @default Vector2()
|
|
644
651
|
* @memberof Settings */
|
|
645
652
|
let canvasFixedSize = vec2();
|
|
646
653
|
|
|
647
654
|
/** Disables anti aliasing for pixel art if true
|
|
655
|
+
* @type {Boolean}
|
|
648
656
|
* @default
|
|
649
657
|
* @memberof Settings */
|
|
650
658
|
let cavasPixelated = 1;
|
|
651
659
|
|
|
652
660
|
/** Default font used for text rendering
|
|
661
|
+
* @type {String}
|
|
653
662
|
* @default
|
|
654
663
|
* @memberof Settings */
|
|
655
664
|
let fontDefault = 'arial';
|
|
@@ -658,11 +667,13 @@ let fontDefault = 'arial';
|
|
|
658
667
|
// WebGL settings
|
|
659
668
|
|
|
660
669
|
/** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
|
|
670
|
+
* @type {Boolean}
|
|
661
671
|
* @default
|
|
662
672
|
* @memberof Settings */
|
|
663
673
|
let glEnable = 1;
|
|
664
674
|
|
|
665
675
|
/** Fixes slow rendering in some browsers by not compositing the WebGL canvas
|
|
676
|
+
* @type {Boolean}
|
|
666
677
|
* @default
|
|
667
678
|
* @memberof Settings */
|
|
668
679
|
let glOverlay = 1;
|
|
@@ -671,12 +682,13 @@ let glOverlay = 1;
|
|
|
671
682
|
// Tile sheet settings
|
|
672
683
|
|
|
673
684
|
/** Default size of tiles in pixels
|
|
674
|
-
* @type {Vector2}
|
|
675
|
-
* @default
|
|
685
|
+
* @type {Vector2}
|
|
686
|
+
* @default Vector2(16,16)
|
|
676
687
|
* @memberof Settings */
|
|
677
688
|
let tileSizeDefault = vec2(16);
|
|
678
689
|
|
|
679
690
|
/** Prevent tile bleeding from neighbors in pixels
|
|
691
|
+
* @type {Number}
|
|
680
692
|
* @default
|
|
681
693
|
* @memberof Settings */
|
|
682
694
|
let tileFixBleedScale = .3;
|
|
@@ -684,53 +696,56 @@ let tileFixBleedScale = .3;
|
|
|
684
696
|
///////////////////////////////////////////////////////////////////////////////
|
|
685
697
|
// Object settings
|
|
686
698
|
|
|
687
|
-
/** Default size of objects
|
|
688
|
-
* @type {Vector2}
|
|
689
|
-
* @default
|
|
690
|
-
* @memberof Settings */
|
|
691
|
-
let objectDefaultSize = vec2(1);
|
|
692
|
-
|
|
693
699
|
/** Enable physics solver for collisions between objects
|
|
700
|
+
* @type {Boolean}
|
|
694
701
|
* @default
|
|
695
702
|
* @memberof Settings */
|
|
696
703
|
let enablePhysicsSolver = 1;
|
|
697
704
|
|
|
698
705
|
/** Default object mass for collison calcuations (how heavy objects are)
|
|
706
|
+
* @type {Number}
|
|
699
707
|
* @default
|
|
700
708
|
* @memberof Settings */
|
|
701
709
|
let objectDefaultMass = 1;
|
|
702
710
|
|
|
703
711
|
/** How much to slow velocity by each frame (0-1)
|
|
712
|
+
* @type {Number}
|
|
704
713
|
* @default
|
|
705
714
|
* @memberof Settings */
|
|
706
|
-
let objectDefaultDamping =
|
|
715
|
+
let objectDefaultDamping = 1;
|
|
707
716
|
|
|
708
717
|
/** How much to slow angular velocity each frame (0-1)
|
|
718
|
+
* @type {Number}
|
|
709
719
|
* @default
|
|
710
720
|
* @memberof Settings */
|
|
711
|
-
let objectDefaultAngleDamping =
|
|
721
|
+
let objectDefaultAngleDamping = 1;
|
|
712
722
|
|
|
713
723
|
/** How much to bounce when a collision occurs (0-1)
|
|
714
|
-
* @
|
|
724
|
+
* @type {Number}
|
|
725
|
+
* @default 0
|
|
715
726
|
* @memberof Settings */
|
|
716
727
|
let objectDefaultElasticity = 0;
|
|
717
728
|
|
|
718
729
|
/** How much to slow when touching (0-1)
|
|
730
|
+
* @type {Number}
|
|
719
731
|
* @default
|
|
720
732
|
* @memberof Settings */
|
|
721
733
|
let objectDefaultFriction = .8;
|
|
722
734
|
|
|
723
735
|
/** Clamp max speed to avoid fast objects missing collisions
|
|
736
|
+
* @type {Number}
|
|
724
737
|
* @default
|
|
725
738
|
* @memberof Settings */
|
|
726
739
|
let objectMaxSpeed = 1;
|
|
727
740
|
|
|
728
741
|
/** How much gravity to apply to objects along the Y axis, negative is down
|
|
729
|
-
* @
|
|
742
|
+
* @type {Number}
|
|
743
|
+
* @default 0
|
|
730
744
|
* @memberof Settings */
|
|
731
745
|
let gravity = 0;
|
|
732
746
|
|
|
733
747
|
/** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
|
|
748
|
+
* @type {Number}
|
|
734
749
|
* @default
|
|
735
750
|
* @memberof Settings */
|
|
736
751
|
let particleEmitRateScale = 1;
|
|
@@ -739,16 +754,19 @@ let particleEmitRateScale = 1;
|
|
|
739
754
|
// Input settings
|
|
740
755
|
|
|
741
756
|
/** Should gamepads be allowed
|
|
757
|
+
* @type {Boolean}
|
|
742
758
|
* @default
|
|
743
759
|
* @memberof Settings */
|
|
744
760
|
let gamepadsEnable = 1;
|
|
745
761
|
|
|
746
762
|
/** If true, the dpad input is also routed to the left analog stick (for better accessability)
|
|
763
|
+
* @type {Boolean}
|
|
747
764
|
* @default
|
|
748
765
|
* @memberof Settings */
|
|
749
766
|
let gamepadDirectionEmulateStick = 1;
|
|
750
767
|
|
|
751
768
|
/** If true the WASD keys are also routed to the direction keys (for better accessability)
|
|
769
|
+
* @type {Boolean}
|
|
752
770
|
* @default
|
|
753
771
|
* @memberof Settings */
|
|
754
772
|
let inputWASDEmulateDirection = 1;
|
|
@@ -756,26 +774,31 @@ let inputWASDEmulateDirection = 1;
|
|
|
756
774
|
/** True if touch gamepad should appear on mobile devices
|
|
757
775
|
* <br> - Supports left analog stick, 4 face buttons and start button (button 9)
|
|
758
776
|
* <br> - Must be set by end of gameInit to be activated
|
|
759
|
-
* @
|
|
777
|
+
* @type {Boolean}
|
|
778
|
+
* @default 0
|
|
760
779
|
* @memberof Settings */
|
|
761
780
|
let touchGamepadEnable = 0;
|
|
762
781
|
|
|
763
782
|
/** True if touch gamepad should be analog stick or false to use if 8 way dpad
|
|
783
|
+
* @type {Boolean}
|
|
764
784
|
* @default
|
|
765
785
|
* @memberof Settings */
|
|
766
786
|
let touchGamepadAnalog = 1;
|
|
767
787
|
|
|
768
788
|
/** Size of virutal gamepad for touch devices in pixels
|
|
789
|
+
* @type {Number}
|
|
769
790
|
* @default
|
|
770
791
|
* @memberof Settings */
|
|
771
792
|
let touchGamepadSize = 99;
|
|
772
793
|
|
|
773
794
|
/** Transparency of touch gamepad overlay
|
|
795
|
+
* @type {Number}
|
|
774
796
|
* @default
|
|
775
797
|
* @memberof Settings */
|
|
776
798
|
let touchGamepadAlpha = .3;
|
|
777
799
|
|
|
778
800
|
/** Allow vibration hardware if it exists
|
|
801
|
+
* @type {Boolean}
|
|
779
802
|
* @default
|
|
780
803
|
* @memberof Settings */
|
|
781
804
|
let vibrateEnable = 1;
|
|
@@ -784,21 +807,25 @@ let vibrateEnable = 1;
|
|
|
784
807
|
// Audio settings
|
|
785
808
|
|
|
786
809
|
/** All audio code can be disabled and removed from build
|
|
810
|
+
* @type {Boolean}
|
|
787
811
|
* @default
|
|
788
812
|
* @memberof Settings */
|
|
789
813
|
let soundEnable = 1;
|
|
790
814
|
|
|
791
815
|
/** Volume scale to apply to all sound, music and speech
|
|
816
|
+
* @type {Number}
|
|
792
817
|
* @default
|
|
793
818
|
* @memberof Settings */
|
|
794
819
|
let soundVolume = .5;
|
|
795
820
|
|
|
796
821
|
/** Default range where sound no longer plays
|
|
822
|
+
* @type {Number}
|
|
797
823
|
* @default
|
|
798
824
|
* @memberof Settings */
|
|
799
825
|
let soundDefaultRange = 40;
|
|
800
826
|
|
|
801
827
|
/** Default range percent to start tapering off sound (0-1)
|
|
828
|
+
* @type {Number}
|
|
802
829
|
* @default
|
|
803
830
|
* @memberof Settings */
|
|
804
831
|
let soundDefaultTaper = .7;
|
|
@@ -807,27 +834,32 @@ let soundDefaultTaper = .7;
|
|
|
807
834
|
// Medals settings
|
|
808
835
|
|
|
809
836
|
/** How long to show medals for in seconds
|
|
837
|
+
* @type {Number}
|
|
810
838
|
* @default
|
|
811
839
|
* @memberof Settings */
|
|
812
840
|
let medalDisplayTime = 5;
|
|
813
841
|
|
|
814
842
|
/** How quickly to slide on/off medals in seconds
|
|
843
|
+
* @type {Number}
|
|
815
844
|
* @default
|
|
816
845
|
* @memberof Settings */
|
|
817
846
|
let medalDisplaySlideTime = .5;
|
|
818
847
|
|
|
819
848
|
/** Size of medal display
|
|
820
|
-
* @
|
|
849
|
+
* @type {Vector2}
|
|
850
|
+
* @default Vector2(640,80)
|
|
821
851
|
* @memberof Settings */
|
|
822
852
|
let medalDisplaySize = vec2(640, 80);
|
|
823
853
|
|
|
824
854
|
/** Size of icon in medal display
|
|
855
|
+
* @type {Number}
|
|
825
856
|
* @default
|
|
826
857
|
* @memberof Settings */
|
|
827
858
|
let medalDisplayIconSize = 50;
|
|
828
859
|
|
|
829
860
|
/** Set to stop medals from being unlockable (like if cheats are enabled)
|
|
830
|
-
* @
|
|
861
|
+
* @type {Boolean}
|
|
862
|
+
* @default 0
|
|
831
863
|
* @memberof Settings */
|
|
832
864
|
let medalsPreventUnlock;
|
|
833
865
|
/*
|
|
@@ -849,43 +881,71 @@ let medalsPreventUnlock;
|
|
|
849
881
|
- Call engineInit() to start it up!
|
|
850
882
|
*/
|
|
851
883
|
|
|
884
|
+
/**
|
|
885
|
+
* LittleJS Engine Globals
|
|
886
|
+
* @namespace Engine
|
|
887
|
+
*/
|
|
888
|
+
|
|
852
889
|
'use strict';
|
|
853
890
|
|
|
854
|
-
/** Name of engine
|
|
891
|
+
/** Name of engine
|
|
892
|
+
* @type {String}
|
|
893
|
+
* @default
|
|
894
|
+
* @memberof Engine */
|
|
855
895
|
const engineName = 'LittleJS';
|
|
856
896
|
|
|
857
|
-
/** Version of engine
|
|
858
|
-
|
|
897
|
+
/** Version of engine
|
|
898
|
+
* @type {String}
|
|
899
|
+
* @default
|
|
900
|
+
* @memberof Engine */
|
|
901
|
+
const engineVersion = '1.5.2';
|
|
859
902
|
|
|
860
903
|
/** Frames per second to update objects
|
|
861
|
-
* @
|
|
904
|
+
* @type {Number}
|
|
905
|
+
* @default
|
|
906
|
+
* @memberof Engine */
|
|
862
907
|
const frameRate = 60;
|
|
863
908
|
|
|
864
909
|
/** How many seconds each frame lasts, engine uses a fixed time step
|
|
865
|
-
* @
|
|
910
|
+
* @type {Number}
|
|
911
|
+
* @default 1/60
|
|
912
|
+
* @memberof Engine */
|
|
866
913
|
const timeDelta = 1/frameRate;
|
|
867
914
|
|
|
868
|
-
/** Array containing all engine objects
|
|
915
|
+
/** Array containing all engine objects
|
|
916
|
+
* @type {Array}
|
|
917
|
+
* @memberof Engine */
|
|
869
918
|
let engineObjects = [];
|
|
870
919
|
|
|
871
|
-
/** Array containing only objects that are set to collide with other objects this frame (for optimization)
|
|
920
|
+
/** Array containing only objects that are set to collide with other objects this frame (for optimization)
|
|
921
|
+
* @type {Array}
|
|
922
|
+
* @memberof Engine */
|
|
872
923
|
let engineObjectsCollide = [];
|
|
873
924
|
|
|
874
|
-
/** Current update frame, used to calculate time
|
|
925
|
+
/** Current update frame, used to calculate time
|
|
926
|
+
* @type {Number}
|
|
927
|
+
* @memberof Engine */
|
|
875
928
|
let frame = 0;
|
|
876
929
|
|
|
877
|
-
/** Current engine time since start in seconds, derived from frame
|
|
930
|
+
/** Current engine time since start in seconds, derived from frame
|
|
931
|
+
* @type {Number}
|
|
932
|
+
* @memberof Engine */
|
|
878
933
|
let time = 0;
|
|
879
934
|
|
|
880
|
-
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
|
|
935
|
+
/** Actual clock time since start in seconds (not affected by pause or frame rate clamping)
|
|
936
|
+
* @type {Number}
|
|
937
|
+
* @memberof Engine */
|
|
881
938
|
let timeReal = 0;
|
|
882
939
|
|
|
883
|
-
/** Is the game paused? Causes time and objects to not be updated
|
|
940
|
+
/** Is the game paused? Causes time and objects to not be updated
|
|
941
|
+
* @type {Boolean}
|
|
942
|
+
* @default 0
|
|
943
|
+
* @memberof Engine */
|
|
884
944
|
let paused = 0;
|
|
885
945
|
|
|
886
946
|
/** Set if game is paused
|
|
887
947
|
* @param {Boolean} paused
|
|
888
|
-
*/
|
|
948
|
+
* @memberof Engine */
|
|
889
949
|
function setPaused(_paused) { paused = _paused; }
|
|
890
950
|
|
|
891
951
|
///////////////////////////////////////////////////////////////////////////////
|
|
@@ -897,7 +957,7 @@ function setPaused(_paused) { paused = _paused; }
|
|
|
897
957
|
* @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
|
|
898
958
|
* @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
|
|
899
959
|
* @param {String} [tileImageSource] - Tile image to use, everything starts when the image is finished loading
|
|
900
|
-
*/
|
|
960
|
+
* @memberof Engine */
|
|
901
961
|
function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, tileImageSource)
|
|
902
962
|
{
|
|
903
963
|
// init engine when tiles load or fail to load
|
|
@@ -946,8 +1006,8 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
946
1006
|
averageFPS = lerp(.05, averageFPS, 1e3/(frameTimeDeltaMS||1));
|
|
947
1007
|
const debugSpeedUp = debug && keyIsDown(107); // +
|
|
948
1008
|
const debugSpeedDown = debug && keyIsDown(109); // -
|
|
949
|
-
if (debug)
|
|
950
|
-
frameTimeDeltaMS *= debugSpeedUp ? 5 : debugSpeedDown ? .2 : 1;
|
|
1009
|
+
if (debug) // +/- to speed/slow time
|
|
1010
|
+
frameTimeDeltaMS *= debugSpeedUp ? 5 : debugSpeedDown ? .2 : 1;
|
|
951
1011
|
timeReal += frameTimeDeltaMS / 1e3;
|
|
952
1012
|
frameTimeBufferMS += !paused * frameTimeDeltaMS;
|
|
953
1013
|
if (!debugSpeedUp)
|
|
@@ -956,8 +1016,8 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
956
1016
|
if (canvasFixedSize.x)
|
|
957
1017
|
{
|
|
958
1018
|
// clear canvas and set fixed size
|
|
959
|
-
|
|
960
|
-
|
|
1019
|
+
mainCanvas.width = canvasFixedSize.x;
|
|
1020
|
+
mainCanvas.height = canvasFixedSize.y;
|
|
961
1021
|
|
|
962
1022
|
// fit to window by adding space on top or bottom if necessary
|
|
963
1023
|
const aspect = innerWidth / innerHeight;
|
|
@@ -968,10 +1028,14 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
|
|
|
968
1028
|
else
|
|
969
1029
|
{
|
|
970
1030
|
// clear canvas and set size to same as window
|
|
971
|
-
|
|
972
|
-
|
|
1031
|
+
mainCanvas.width = min(innerWidth, canvasMaxSize.x);
|
|
1032
|
+
mainCanvas.height = min(innerHeight, canvasMaxSize.y);
|
|
973
1033
|
}
|
|
974
1034
|
|
|
1035
|
+
// clear overlay canvas and set size
|
|
1036
|
+
overlayCanvas.width = mainCanvas.width;
|
|
1037
|
+
overlayCanvas.height = mainCanvas.height;
|
|
1038
|
+
|
|
975
1039
|
// save canvas size
|
|
976
1040
|
mainCanvasSize = vec2(mainCanvas.width, mainCanvas.height);
|
|
977
1041
|
|
|
@@ -1061,7 +1125,8 @@ function enginePreRender()
|
|
|
1061
1125
|
glEnable && glPreRender();
|
|
1062
1126
|
}
|
|
1063
1127
|
|
|
1064
|
-
/** Update each engine object, remove destroyed objects, and update time
|
|
1128
|
+
/** Update each engine object, remove destroyed objects, and update time
|
|
1129
|
+
* @memberof Engine */
|
|
1065
1130
|
function engineObjectsUpdate()
|
|
1066
1131
|
{
|
|
1067
1132
|
// get list of solid objects for physics optimzation
|
|
@@ -1087,7 +1152,8 @@ function engineObjectsUpdate()
|
|
|
1087
1152
|
time = ++frame / frameRate;
|
|
1088
1153
|
}
|
|
1089
1154
|
|
|
1090
|
-
/** Destroy and remove all objects
|
|
1155
|
+
/** Destroy and remove all objects
|
|
1156
|
+
* @memberof Engine */
|
|
1091
1157
|
function engineObjectsDestroy()
|
|
1092
1158
|
{
|
|
1093
1159
|
for (const o of engineObjects)
|
|
@@ -1099,7 +1165,8 @@ function engineObjectsDestroy()
|
|
|
1099
1165
|
* @param {Vector2} [pos] - Center of test area
|
|
1100
1166
|
* @param {Number} [size] - Radius of circle if float, rectangle size if Vector2
|
|
1101
1167
|
* @param {Function} [callbackFunction] - Calls this function on every object that passes the test
|
|
1102
|
-
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
1168
|
+
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
1169
|
+
* @memberof Engine */
|
|
1103
1170
|
function engineObjectsCallback(pos, size, callbackFunction, objects=engineObjects)
|
|
1104
1171
|
{
|
|
1105
1172
|
if (!pos) // all objects
|
|
@@ -1153,15 +1220,15 @@ function engineObjectsCallback(pos, size, callbackFunction, objects=engineObject
|
|
|
1153
1220
|
class EngineObject
|
|
1154
1221
|
{
|
|
1155
1222
|
/** Create an engine object and adds it to the list of objects
|
|
1156
|
-
* @param {Vector2} [position=
|
|
1157
|
-
* @param {Vector2} [size=
|
|
1223
|
+
* @param {Vector2} [position=Vector2()] - World space position of the object
|
|
1224
|
+
* @param {Vector2} [size=Vector2(1,1)] - World space size of the object
|
|
1158
1225
|
* @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
|
|
1159
1226
|
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
1160
1227
|
* @param {Number} [angle=0] - Angle the object is rotated by
|
|
1161
|
-
* @param {Color} [color]
|
|
1228
|
+
* @param {Color} [color=Color()] - Color to apply to tile when rendered
|
|
1162
1229
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
1163
1230
|
*/
|
|
1164
|
-
constructor(pos=vec2(), size=
|
|
1231
|
+
constructor(pos=vec2(), size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
|
|
1165
1232
|
{
|
|
1166
1233
|
// set passed in params
|
|
1167
1234
|
ASSERT(isVector2(pos) && isVector2(size)); // ensure pos and size are vec2s
|
|
@@ -1198,7 +1265,7 @@ class EngineObject
|
|
|
1198
1265
|
this.gravityScale = 1;
|
|
1199
1266
|
/** @property {Number} [renderOrder=0] - Objects are sorted by render order */
|
|
1200
1267
|
this.renderOrder = renderOrder;
|
|
1201
|
-
/** @property {Vector2} [velocity=
|
|
1268
|
+
/** @property {Vector2} [velocity=Vector2()] - Velocity of the object */
|
|
1202
1269
|
this.velocity = new Vector2();
|
|
1203
1270
|
/** @property {Number} [angleVelocity=0] - Angular velocity of the object */
|
|
1204
1271
|
this.angleVelocity = 0;
|
|
@@ -1441,7 +1508,7 @@ class EngineObject
|
|
|
1441
1508
|
|
|
1442
1509
|
/** Attaches a child to this with a given local transform
|
|
1443
1510
|
* @param {EngineObject} child
|
|
1444
|
-
* @param {Vector2} [localPos=
|
|
1511
|
+
* @param {Vector2} [localPos=Vector2()]
|
|
1445
1512
|
* @param {Number} [localAngle=0] */
|
|
1446
1513
|
addChild(child, localPos=vec2(), localAngle=0)
|
|
1447
1514
|
{
|
|
@@ -1575,15 +1642,15 @@ const worldToScreen = (worldPos)=>
|
|
|
1575
1642
|
}
|
|
1576
1643
|
|
|
1577
1644
|
/** Draw textured tile centered in world space, with color applied if using WebGL
|
|
1578
|
-
* @param {Vector2} pos
|
|
1579
|
-
* @param {Vector2} [size=
|
|
1580
|
-
* @param {Number} [tileIndex=-1]
|
|
1581
|
-
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
1582
|
-
* @param {Color} [color=
|
|
1583
|
-
* @param {Number} [angle=0]
|
|
1584
|
-
* @param {Boolean} [mirror=0]
|
|
1585
|
-
* @param {Color} [additiveColor=
|
|
1586
|
-
* @param {Boolean} [useWebGL=glEnable]
|
|
1645
|
+
* @param {Vector2} pos - Center of the tile in world space
|
|
1646
|
+
* @param {Vector2} [size=Vector2(1,1)] - Size of the tile in world space
|
|
1647
|
+
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
1648
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1649
|
+
* @param {Color} [color=Color()] - Color to modulate with
|
|
1650
|
+
* @param {Number} [angle=0] - Angle to rotate by
|
|
1651
|
+
* @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
|
|
1652
|
+
* @param {Color} [additiveColor=Color(0,0,0,0)] - Additive color to be applied
|
|
1653
|
+
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
1587
1654
|
* @memberof Draw */
|
|
1588
1655
|
function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
|
|
1589
1656
|
additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
|
|
@@ -1638,8 +1705,8 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, col
|
|
|
1638
1705
|
|
|
1639
1706
|
/** Draw colored rect centered on pos
|
|
1640
1707
|
* @param {Vector2} pos
|
|
1641
|
-
* @param {Vector2} [size=
|
|
1642
|
-
* @param {Color} [color=
|
|
1708
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
1709
|
+
* @param {Color} [color=Color()]
|
|
1643
1710
|
* @param {Number} [angle=0]
|
|
1644
1711
|
* @param {Boolean} [useWebGL=glEnable]
|
|
1645
1712
|
* @memberof Draw */
|
|
@@ -1650,13 +1717,13 @@ function drawRect(pos, size, color, angle, useWebGL)
|
|
|
1650
1717
|
|
|
1651
1718
|
/** Draw textured tile centered on pos in screen space
|
|
1652
1719
|
* @param {Vector2} pos - Center of the tile
|
|
1653
|
-
* @param {Vector2} [size=
|
|
1720
|
+
* @param {Vector2} [size=Vector2(1,1)] - Size of the tile
|
|
1654
1721
|
* @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
|
|
1655
1722
|
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1656
|
-
* @param {Color} [color=
|
|
1723
|
+
* @param {Color} [color=Color()]
|
|
1657
1724
|
* @param {Number} [angle=0]
|
|
1658
1725
|
* @param {Boolean} [mirror=0]
|
|
1659
|
-
* @param {Color} [additiveColor=
|
|
1726
|
+
* @param {Color} [additiveColor=Color(0,0,0,0)]
|
|
1660
1727
|
* @param {Boolean} [useWebGL=glEnable]
|
|
1661
1728
|
* @memberof Draw */
|
|
1662
1729
|
function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angle, mirror, additiveColor, useWebGL)
|
|
@@ -1666,8 +1733,8 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
|
|
|
1666
1733
|
|
|
1667
1734
|
/** Draw colored rectangle in screen space
|
|
1668
1735
|
* @param {Vector2} pos
|
|
1669
|
-
* @param {Vector2} [size=
|
|
1670
|
-
* @param {Color} [color=
|
|
1736
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
1737
|
+
* @param {Color} [color=Color()]
|
|
1671
1738
|
* @param {Number} [angle=0]
|
|
1672
1739
|
* @param {Boolean} [useWebGL=glEnable]
|
|
1673
1740
|
* @memberof Draw */
|
|
@@ -1680,7 +1747,7 @@ function drawRectScreenSpace(pos, size, color, angle, useWebGL)
|
|
|
1680
1747
|
* @param {Vector2} posA
|
|
1681
1748
|
* @param {Vector2} posB
|
|
1682
1749
|
* @param {Number} [thickness=.1]
|
|
1683
|
-
* @param {Color} [color=
|
|
1750
|
+
* @param {Color} [color=Color()]
|
|
1684
1751
|
* @param {Boolean} [useWebGL=glEnable]
|
|
1685
1752
|
* @memberof Draw */
|
|
1686
1753
|
function drawLine(posA, posB, thickness=.1, color, useWebGL)
|
|
@@ -1728,9 +1795,9 @@ function setBlendMode(additive, useWebGL=glEnable)
|
|
|
1728
1795
|
* @param {String} text
|
|
1729
1796
|
* @param {Vector2} pos
|
|
1730
1797
|
* @param {Number} [size=1]
|
|
1731
|
-
* @param {Color} [color=
|
|
1798
|
+
* @param {Color} [color=Color()]
|
|
1732
1799
|
* @param {Number} [lineWidth=0]
|
|
1733
|
-
* @param {Color} [lineColor=
|
|
1800
|
+
* @param {Color} [lineColor=Color(0,0,0)]
|
|
1734
1801
|
* @param {String} [textAlign='center']
|
|
1735
1802
|
* @memberof Draw */
|
|
1736
1803
|
function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault, context=overlayContext)
|
|
@@ -1757,18 +1824,20 @@ function drawTextScreen(text, pos, size=1, color=new Color, lineWidth=0, lineCol
|
|
|
1757
1824
|
* @param {String} text
|
|
1758
1825
|
* @param {Vector2} pos
|
|
1759
1826
|
* @param {Number} [size=1]
|
|
1760
|
-
* @param {Color} [color=
|
|
1827
|
+
* @param {Color} [color=Color()]
|
|
1761
1828
|
* @param {Number} [lineWidth=0]
|
|
1762
|
-
* @param {Color} [lineColor=
|
|
1829
|
+
* @param {Color} [lineColor=Color(0,0,0)]
|
|
1763
1830
|
* @param {String} [textAlign='center']
|
|
1764
1831
|
* @memberof Draw */
|
|
1765
|
-
function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, font)
|
|
1832
|
+
function drawText(text, pos, size=1, color, lineWidth=0, lineColor, textAlign, font)
|
|
1766
1833
|
{
|
|
1767
1834
|
drawTextScreen(text, worldToScreen(pos), size*cameraScale, color, lineWidth*cameraScale, lineColor, textAlign, font, mainContext);
|
|
1768
1835
|
}
|
|
1769
1836
|
|
|
1770
1837
|
///////////////////////////////////////////////////////////////////////////////
|
|
1771
1838
|
|
|
1839
|
+
let engineFontImage;
|
|
1840
|
+
|
|
1772
1841
|
/**
|
|
1773
1842
|
* Font Image Object - Draw text on a 2D canvas by using characters in an image
|
|
1774
1843
|
* <br> - 96 characters (from space to tilde) are stored in an image
|
|
@@ -1781,10 +1850,6 @@ function drawText(text, pos, size=1, color, lineWidth, lineColor, textAlign, fon
|
|
|
1781
1850
|
* // draw text
|
|
1782
1851
|
* font.drawTextScreen("LittleJS\nHello World!", vec2(200, 50));
|
|
1783
1852
|
*/
|
|
1784
|
-
|
|
1785
|
-
// default font image created by engine
|
|
1786
|
-
let engineFontImage;
|
|
1787
|
-
|
|
1788
1853
|
class FontImage
|
|
1789
1854
|
{
|
|
1790
1855
|
/** Create an image font
|
|
@@ -1915,18 +1980,21 @@ const keyWasReleased = (key, device=0)=> inputData[device] && inputData[device][
|
|
|
1915
1980
|
const clearInput = ()=> inputData = [[]];
|
|
1916
1981
|
|
|
1917
1982
|
/** Returns true if mouse button is down
|
|
1983
|
+
* @function
|
|
1918
1984
|
* @param {Number} button
|
|
1919
1985
|
* @return {Boolean}
|
|
1920
1986
|
* @memberof Input */
|
|
1921
1987
|
const mouseIsDown = keyIsDown;
|
|
1922
1988
|
|
|
1923
1989
|
/** Returns true if mouse button was pressed
|
|
1990
|
+
* @function
|
|
1924
1991
|
* @param {Number} button
|
|
1925
1992
|
* @return {Boolean}
|
|
1926
1993
|
* @memberof Input */
|
|
1927
1994
|
const mouseWasPressed = keyWasPressed;
|
|
1928
1995
|
|
|
1929
1996
|
/** Returns true if mouse button was released
|
|
1997
|
+
* @function
|
|
1930
1998
|
* @param {Number} button
|
|
1931
1999
|
* @return {Boolean}
|
|
1932
2000
|
* @memberof Input */
|
|
@@ -1943,14 +2011,17 @@ let mousePos = vec2();
|
|
|
1943
2011
|
let mousePosScreen = vec2();
|
|
1944
2012
|
|
|
1945
2013
|
/** Mouse wheel delta this frame
|
|
2014
|
+
* @type {Number}
|
|
1946
2015
|
* @memberof Input */
|
|
1947
2016
|
let mouseWheel = 0;
|
|
1948
2017
|
|
|
1949
2018
|
/** Returns true if user is using gamepad (has more recently pressed a gamepad button)
|
|
2019
|
+
* @type {Boolean}
|
|
1950
2020
|
* @memberof Input */
|
|
1951
2021
|
let isUsingGamepad = 0;
|
|
1952
2022
|
|
|
1953
2023
|
/** Prevents input continuing to the default browser handling (false by default)
|
|
2024
|
+
* @type {Boolean}
|
|
1954
2025
|
* @memberof Input */
|
|
1955
2026
|
let preventDefaultInput = 0;
|
|
1956
2027
|
|
|
@@ -2126,7 +2197,6 @@ const vibrateStop = ()=> vibrate(0);
|
|
|
2126
2197
|
// Touch input
|
|
2127
2198
|
|
|
2128
2199
|
/** True if a touch device has been detected
|
|
2129
|
-
* @const {Boolean}
|
|
2130
2200
|
* @memberof Input */
|
|
2131
2201
|
const isTouchDevice = window.ontouchstart !== undefined;
|
|
2132
2202
|
|
|
@@ -2456,7 +2526,7 @@ class Music
|
|
|
2456
2526
|
{
|
|
2457
2527
|
if (!soundEnable) return;
|
|
2458
2528
|
|
|
2459
|
-
this.source = playSamples(this.cachedSamples, volume, 1, 0, loop);
|
|
2529
|
+
return this.source = playSamples(this.cachedSamples, volume, 1, 0, loop);
|
|
2460
2530
|
}
|
|
2461
2531
|
|
|
2462
2532
|
/** Stop the music */
|
|
@@ -2797,6 +2867,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
2797
2867
|
'use strict';
|
|
2798
2868
|
|
|
2799
2869
|
/** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
|
|
2870
|
+
* @type {Array}
|
|
2800
2871
|
* @memberof TileCollision */
|
|
2801
2872
|
let tileCollision = [];
|
|
2802
2873
|
|
|
@@ -2832,7 +2903,7 @@ const getTileCollisionData = (pos)=>
|
|
|
2832
2903
|
|
|
2833
2904
|
/** Check if collision with another object should occur
|
|
2834
2905
|
* @param {Vector2} pos
|
|
2835
|
-
* @param {Vector2} [size=
|
|
2906
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
2836
2907
|
* @param {EngineObject} [object]
|
|
2837
2908
|
* @return {Boolean}
|
|
2838
2909
|
* @memberof TileCollision */
|
|
@@ -2900,11 +2971,11 @@ function tileCollisionRaycast(posStart, posEnd, object)
|
|
|
2900
2971
|
class TileLayerData
|
|
2901
2972
|
{
|
|
2902
2973
|
/** Create a tile layer data object, one for each tile in a TileLayer
|
|
2903
|
-
* @param {Number} [tile]
|
|
2904
|
-
* @param {Number} [direction=0]
|
|
2905
|
-
* @param {Boolean} [mirror=0]
|
|
2906
|
-
* @param {Color} [color=
|
|
2907
|
-
constructor(tile, direction=0, mirror=0, color=new Color)
|
|
2974
|
+
* @param {Number} [tile] - The tile to use, untextured if undefined
|
|
2975
|
+
* @param {Number} [direction=0] - Integer direction of tile, in 90 degree increments
|
|
2976
|
+
* @param {Boolean} [mirror=0] - If the tile should be mirrored along the x axis
|
|
2977
|
+
* @param {Color} [color=Color()] - Color of the tile */
|
|
2978
|
+
constructor(tile, direction=0, mirror=0, color=new Color())
|
|
2908
2979
|
{
|
|
2909
2980
|
/** @property {Number} - The tile to use, untextured if undefined */
|
|
2910
2981
|
this.tile = tile;
|
|
@@ -2935,10 +3006,10 @@ class TileLayerData
|
|
|
2935
3006
|
class TileLayer extends EngineObject
|
|
2936
3007
|
{
|
|
2937
3008
|
/** Create a tile layer object
|
|
2938
|
-
* @param {Vector2} [position=
|
|
3009
|
+
* @param {Vector2} [position=Vector2()] - World space position
|
|
2939
3010
|
* @param {Vector2} [size=tileCollisionSize] - World space size
|
|
2940
3011
|
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
|
|
2941
|
-
* @param {Vector2} [scale=
|
|
3012
|
+
* @param {Vector2} [scale=Vector2(1,1)] - How much to scale this layer when rendered
|
|
2942
3013
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
2943
3014
|
*/
|
|
2944
3015
|
constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
|
|
@@ -3090,10 +3161,10 @@ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1)
|
|
|
3090
3161
|
|
|
3091
3162
|
/** Draw a tile directly onto the layer canvas
|
|
3092
3163
|
* @param {Vector2} pos
|
|
3093
|
-
* @param {Vector2} [size=
|
|
3164
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
3094
3165
|
* @param {Number} [tileIndex=-1]
|
|
3095
3166
|
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
3096
|
-
* @param {Color} [color=
|
|
3167
|
+
* @param {Color} [color=Color()]
|
|
3097
3168
|
* @param {Number} [angle=0]
|
|
3098
3169
|
* @param {Boolean} [mirror=0] */
|
|
3099
3170
|
drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle, mirror)
|
|
@@ -3119,8 +3190,8 @@ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1)
|
|
|
3119
3190
|
|
|
3120
3191
|
/** Draw a rectangle directly onto the layer canvas
|
|
3121
3192
|
* @param {Vector2} pos
|
|
3122
|
-
* @param {Vector2} [size=
|
|
3123
|
-
* @param {Color} [color=
|
|
3193
|
+
* @param {Vector2} [size=Vector2(1,1)]
|
|
3194
|
+
* @param {Color} [color=Color()]
|
|
3124
3195
|
* @param {Number} [angle=0] */
|
|
3125
3196
|
drawRect(pos, size, color, angle)
|
|
3126
3197
|
{ this.drawTile(pos, size, -1, 0, color, angle); }
|
|
@@ -3161,11 +3232,11 @@ class ParticleEmitter extends EngineObject
|
|
|
3161
3232
|
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
|
|
3162
3233
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
3163
3234
|
* @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
|
|
3164
|
-
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
3165
|
-
* @param {Color} [colorStartA=
|
|
3166
|
-
* @param {Color} [colorStartB=
|
|
3167
|
-
* @param {Color} [colorEndA=
|
|
3168
|
-
* @param {Color} [colorEndB=
|
|
3235
|
+
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size for particles
|
|
3236
|
+
* @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
|
|
3237
|
+
* @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
|
|
3238
|
+
* @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
3239
|
+
* @param {Color} [colorEndB=Color(1,1,1,0)] - Color at end of life 2, randomized between end colors
|
|
3169
3240
|
* @param {Number} [particleTime=.5] - How long particles live
|
|
3170
3241
|
* @param {Number} [sizeStart=.1] - How big are particles at start
|
|
3171
3242
|
* @param {Number} [sizeEnd=1] - How big are particles at end
|
|
@@ -3445,6 +3516,7 @@ class Particle extends EngineObject
|
|
|
3445
3516
|
'use strict';
|
|
3446
3517
|
|
|
3447
3518
|
/** List of all medals
|
|
3519
|
+
* @type {Array}
|
|
3448
3520
|
* @memberof Medals */
|
|
3449
3521
|
const medals = [];
|
|
3450
3522
|
|
|
@@ -3996,12 +4068,13 @@ function glDraw(x, y, sizeX, sizeY, angle, uv0X, uv0Y, uv1X, uv1Y, rgba, rgbaAdd
|
|
|
3996
4068
|
///////////////////////////////////////////////////////////////////////////////
|
|
3997
4069
|
// post processing - can be enabled to pass other canvases through a final shader
|
|
3998
4070
|
|
|
3999
|
-
let glPostShader, glPostArrayBuffer, glPostTexture;
|
|
4071
|
+
let glPostShader, glPostArrayBuffer, glPostTexture, glPostIncludeOverlay;
|
|
4000
4072
|
|
|
4001
4073
|
/** Set up a post processing shader
|
|
4002
4074
|
* @param {String} shaderCode
|
|
4075
|
+
* @param {Boolean} includeOverlay
|
|
4003
4076
|
* @memberof WebGL */
|
|
4004
|
-
function glInitPostProcess(shaderCode)
|
|
4077
|
+
function glInitPostProcess(shaderCode, includeOverlay)
|
|
4005
4078
|
{
|
|
4006
4079
|
ASSERT(!glPostShader); // can only have 1 post effects shader
|
|
4007
4080
|
|
|
@@ -4030,6 +4103,7 @@ function glInitPostProcess(shaderCode)
|
|
|
4030
4103
|
// create buffer and texture
|
|
4031
4104
|
glPostArrayBuffer = glContext.createBuffer();
|
|
4032
4105
|
glPostTexture = glCreateTexture();
|
|
4106
|
+
glPostIncludeOverlay = includeOverlay;
|
|
4033
4107
|
|
|
4034
4108
|
// hide the original 2d canvas
|
|
4035
4109
|
mainCanvas.style.visibility = 'hidden';
|
|
@@ -4050,6 +4124,15 @@ function glRenderPostProcess()
|
|
|
4050
4124
|
else // set viewport
|
|
4051
4125
|
glContext.viewport(0, 0, glCanvas.width = mainCanvas.width, glCanvas.height = mainCanvas.height);
|
|
4052
4126
|
|
|
4127
|
+
if (glPostIncludeOverlay)
|
|
4128
|
+
{
|
|
4129
|
+
// copy overlay canvas so it will be included in post processing
|
|
4130
|
+
mainContext.drawImage(overlayCanvas, 0, 0);
|
|
4131
|
+
|
|
4132
|
+
// clear overlay canvas
|
|
4133
|
+
overlayCanvas.width = mainCanvas.width;
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4053
4136
|
// setup shader program to draw one triangle
|
|
4054
4137
|
glContext.useProgram(glPostShader);
|
|
4055
4138
|
glContext.disable(gl_BLEND);
|