littlejsengine 1.1.6 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/docs/Audio.html +2268 -0
  2. package/docs/Color.html +2989 -0
  3. package/docs/Debug.html +2933 -0
  4. package/docs/Draw.html +4092 -0
  5. package/docs/EngineObject.html +4458 -0
  6. package/docs/Input.html +2482 -0
  7. package/docs/Medal.html +1007 -0
  8. package/docs/Medals.html +628 -0
  9. package/docs/Music.html +584 -0
  10. package/docs/Newgrounds.html +1399 -0
  11. package/docs/Particle.html +4535 -0
  12. package/docs/ParticleEmitter.html +7770 -0
  13. package/docs/Random.html +1774 -0
  14. package/docs/Settings.html +2679 -0
  15. package/docs/Sound.html +1249 -0
  16. package/docs/TileCollision.html +1409 -0
  17. package/docs/TileLayer.html +6948 -0
  18. package/docs/TileLayerData.html +1052 -0
  19. package/docs/Timer.html +1183 -0
  20. package/docs/Utilities.html +3281 -0
  21. package/docs/Vector2.html +4207 -0
  22. package/docs/WebGL.html +2327 -0
  23. package/docs/engine.js.html +429 -0
  24. package/docs/engineAudio.js.html +609 -0
  25. package/docs/engineDebug.js.html +725 -0
  26. package/docs/engineDraw.js.html +419 -0
  27. package/docs/engineInput.js.html +401 -0
  28. package/docs/engineMedals.js.html +461 -0
  29. package/docs/engineObject.js.html +518 -0
  30. package/docs/engineParticles.js.html +441 -0
  31. package/docs/engineSettings.js.html +349 -0
  32. package/docs/engineTileLayer.js.html +513 -0
  33. package/docs/engineUtilities.js.html +647 -0
  34. package/docs/engineWebGL.js.html +522 -0
  35. package/docs/fonts/MavenPro-Regular.ttf +0 -0
  36. package/docs/fonts/Montserrat-Regular.ttf +0 -0
  37. package/docs/fonts/Muli-Black.ttf +0 -0
  38. package/docs/fonts/OFL-hind.txt +93 -0
  39. package/docs/fonts/OFL-montserrat.txt +93 -0
  40. package/docs/global.html +1691 -0
  41. package/docs/index.css +6 -0
  42. package/docs/index.html +247 -0
  43. package/docs/scripts/fix-code-block.js +53 -0
  44. package/docs/scripts/fix-navbar.js +25 -0
  45. package/docs/scripts/linenumber.js +25 -0
  46. package/docs/scripts/misc.js +217 -0
  47. package/docs/scripts/resize.js +85 -0
  48. package/docs/scripts/search.js +83 -0
  49. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  50. package/docs/scripts/third-party/fuse.js +9 -0
  51. package/docs/scripts/third-party/lang-css.js +2 -0
  52. package/docs/scripts/third-party/prettify.js +28 -0
  53. package/docs/static/favicon.png +0 -0
  54. package/docs/static/index.css +4 -0
  55. package/docs/styles/clean-jsdoc-theme-base.css +393 -0
  56. package/docs/styles/clean-jsdoc-theme-dark.css +324 -0
  57. package/docs/styles/clean-jsdoc-theme-light.css +319 -0
  58. package/docs/styles/reset.css +346 -0
  59. package/docs/styles/third-party/ionicons.min.css +11 -0
  60. package/docs/styles/third-party/prettify-jsdoc.css +111 -0
  61. package/docs/styles/third-party/prettify-tomorrow.css +5 -0
  62. package/engine/engine.all.js +94 -110
  63. package/engine/engine.all.min.js +1 -1
  64. package/engine/engine.all.release.js +94 -110
  65. package/engine/engine.js +14 -17
  66. package/engine/engineAudio.js +7 -7
  67. package/engine/engineDraw.js +6 -6
  68. package/engine/engineInput.js +7 -7
  69. package/engine/engineMedals.js +3 -3
  70. package/engine/engineObject.js +15 -15
  71. package/engine/engineParticles.js +3 -3
  72. package/engine/engineSettings.js +30 -43
  73. package/engine/engineTileLayer.js +5 -5
  74. package/engine/engineUtilities.js +4 -4
  75. package/examples/breakout/game.js +1 -1
  76. package/examples/breakout/gameObjects.js +1 -1
  77. package/examples/breakout/index.html +3 -3
  78. package/examples/platformer/gameObjects.js +1 -1
  79. package/examples/platformer/gamePlayer.js +1 -1
  80. package/examples/platformer/index.html +6 -6
  81. package/examples/puzzle/game.js +1 -1
  82. package/examples/puzzle/index.html +2 -2
  83. package/examples/stress/index.html +1 -1
  84. package/index.html +13 -13
  85. package/package.json +1 -1
@@ -363,10 +363,10 @@ class Vector2
363
363
  class Color
364
364
  {
365
365
  /** Create a color with the components passed in, white by default
366
- * @param {Number} [r=1] - Red
367
- * @param {Number} [g=1] - Green
368
- * @param {Number} [b=1] - Blue
369
- * @param {Number} [a=1] - Alpha */
366
+ * @param {Number} [red=1]
367
+ * @param {Number} [green=1]
368
+ * @param {Number} [blue=1]
369
+ * @param {Number} [alpha=1] */
370
370
  constructor(r=1, g=1, b=1, a=1)
371
371
  {
372
372
  /** @property {Number} - Red */
@@ -526,35 +526,27 @@ class Timer
526
526
  ///////////////////////////////////////////////////////////////////////////////
527
527
  // Display settings
528
528
 
529
- /** The max width of the canvas, centered if window is larger
530
- * @default
531
- * @memberof Settings */
532
- const maxWidth = 1920;
533
-
534
- /** The max height of the canvas, centered if window is larger
535
- * @default
536
- * @memberof Settings */
537
- const maxHeight = 1200; // up to 1080p and 16:10
538
-
539
- /** Fixed witdh, if enabled cavnvas size never changes
529
+ /** The max size of the canvas, centered if window is larger
530
+ * @type {Vector2}
540
531
  * @default
541
532
  * @memberof Settings */
542
- let fixedWidth = 0;
533
+ const maxSize = vec2(1920, 1200);
543
534
 
544
- /** Fixed height, if enabled cavnvas size never changes
535
+ /** Fixed size of the canvas, if enabled cavnvas size never changes
536
+ * @type {Vector2}
545
537
  * @default
546
538
  * @memberof Settings */
547
- let fixedHeight = 0;
539
+ let fixedSize = vec2();
548
540
 
549
- /** Fit to canvas to window by adding space on top or bottom if necessary
541
+ /** Default font used for text rendering
550
542
  * @default
551
543
  * @memberof Settings */
552
- let fixedFitToWindow = 1;
544
+ let fontDefault = 'arial';
553
545
 
554
- /** Default font used for text rendering
546
+ /** Use crisp pixels for pixel art if true
555
547
  * @default
556
548
  * @memberof Settings */
557
- let defaultFont = 'arial';
549
+ let pixelated = 1;
558
550
 
559
551
  ///////////////////////////////////////////////////////////////////////////////
560
552
  // Tile sheet settings
@@ -563,18 +555,13 @@ let defaultFont = 'arial';
563
555
  * @type {Vector2}
564
556
  * @default
565
557
  * @memberof Settings */
566
- const defaultTileSize = vec2(16);
558
+ const tileSizeDefault = vec2(16);
567
559
 
568
560
  /** Prevent tile bleeding from neighbors in pixels
569
561
  * @default
570
562
  * @memberof Settings */
571
563
  const tileBleedShrinkFix = .3;
572
564
 
573
- /** Use crisp pixels for pixel art if true
574
- * @default
575
- * @memberof Settings */
576
- let pixelated = 1;
577
-
578
565
  ///////////////////////////////////////////////////////////////////////////////
579
566
  // Object settings
580
567
 
@@ -582,37 +569,37 @@ let pixelated = 1;
582
569
  * @type {Vector2}
583
570
  * @default
584
571
  * @memberof Settings */
585
- const defaultObjectSize = vec2(1);
572
+ const objectDefaultSize = vec2(1);
586
573
 
587
574
  /** Default object mass for collison calcuations (how heavy objects are)
588
575
  * @default
589
576
  * @memberof Settings */
590
- const defaultObjectMass = 1;
577
+ const objectDefaultMass = 1;
591
578
 
592
579
  /** How much to slow velocity by each frame (0-1)
593
580
  * @default
594
581
  * @memberof Settings */
595
- const defaultObjectDamping = .99;
582
+ const objectDefaultDamping = .99;
596
583
 
597
584
  /** How much to slow angular velocity each frame (0-1)
598
585
  * @default
599
586
  * @memberof Settings */
600
- const defaultObjectAngleDamping = .99;
587
+ const objectDefaultAngleDamping = .99;
601
588
 
602
589
  /** How much to bounce when a collision occurs (0-1)
603
590
  * @default
604
591
  * @memberof Settings */
605
- const defaultObjectElasticity = 0;
592
+ const objectDefaultElasticity = 0;
606
593
 
607
594
  /** How much to slow when touching (0-1)
608
595
  * @default
609
596
  * @memberof Settings */
610
- const defaultObjectFriction = .8;
597
+ const objectDefaultFriction = .8;
611
598
 
612
599
  /** Clamp max speed to avoid fast objects missing collisions
613
600
  * @default
614
601
  * @memberof Settings */
615
- const maxObjectSpeed = 1;
602
+ const objectMaxSpeed = 1;
616
603
 
617
604
  /** How much gravity to apply to objects along the Y axis, negative is down
618
605
  * @default
@@ -631,7 +618,7 @@ let cameraPos = vec2();
631
618
  /** Scale of camera in world space
632
619
  * @default
633
620
  * @memberof Settings */
634
- let cameraScale = max(defaultTileSize.x, defaultTileSize.y);
621
+ let cameraScale = max(tileSizeDefault.x, tileSizeDefault.y);
635
622
 
636
623
  ///////////////////////////////////////////////////////////////////////////////
637
624
  // WebGL settings
@@ -654,43 +641,43 @@ let glOverlay = 1;
654
641
  * @memberof Settings */
655
642
  const gamepadsEnable = 1;
656
643
 
657
- /** If true touch input is routed to mouse functions
644
+ /** If true, the dpad input is also routed to the left analog stick (for better accessability)
658
645
  * @default
659
646
  * @memberof Settings */
660
- const touchInputEnable = 1;
647
+ const gamepadDirectionEmulateStick = 1;
661
648
 
662
- /** If true, the dpad also routes input to the analog stick (for better accessability)
649
+ /** If true touch input is routed to mouse functions
663
650
  * @default
664
651
  * @memberof Settings */
665
- const copyGamepadDirectionToStick = 1;
652
+ const inputTouchEnable = 1;
666
653
 
667
654
  /** If true the WASD keys are also routed to the direction keys (for better accessability)
668
655
  * @default
669
656
  * @memberof Settings */
670
- const copyWASDToDpad = 1;
657
+ const inputWASDEmulateDirection = 1;
671
658
 
672
659
  ///////////////////////////////////////////////////////////////////////////////
673
660
  // Audio settings
674
661
 
675
- /** All audio code can be disabled and removed from build
662
+ /** Volume scale to apply to all sound, music and speech
676
663
  * @default
677
664
  * @memberof Settings */
678
- const soundEnable = 1;
665
+ let soundVolume = .5;
679
666
 
680
- /** Volume scale to apply to all sound, music and speech
667
+ /** All audio code can be disabled and removed from build
681
668
  * @default
682
669
  * @memberof Settings */
683
- let audioVolume = .5;
670
+ const soundEnable = 1;
684
671
 
685
672
  /** Default range where sound no longer plays
686
673
  * @default
687
674
  * @memberof Settings */
688
- const defaultSoundRange = 30;
675
+ const soundDefaultRange = 30;
689
676
 
690
677
  /** Default range percent to start tapering off sound (0-1)
691
678
  * @default
692
679
  * @memberof Settings */
693
- const defaultSoundTaper = .7;
680
+ const soundDefaultTaper = .7;
694
681
 
695
682
  ///////////////////////////////////////////////////////////////////////////////
696
683
  // Medals settings
@@ -743,7 +730,7 @@ const medalDisplayIconSize = 80;
743
730
  const engineName = 'LittleJS';
744
731
 
745
732
  /** Version of engine */
746
- const engineVersion = '1.1.6';
733
+ const engineVersion = '1.1.8';
747
734
 
748
735
  /** Frames per second to update objects
749
736
  * @default */
@@ -868,31 +855,28 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
868
855
  frameTimeBufferMS += deltaSmooth;
869
856
  }
870
857
 
871
- if (fixedWidth)
858
+ if (fixedSize.x)
872
859
  {
873
860
  // clear set fixed size
874
- mainCanvas.width = fixedWidth;
875
- mainCanvas.height = fixedHeight;
861
+ mainCanvas.width = fixedSize.x;
862
+ mainCanvas.height = fixedSize.y;
876
863
 
877
- if (fixedFitToWindow)
864
+ // fit to window by adding space on top or bottom if necessary
865
+ const aspect = innerWidth / innerHeight;
866
+ const fixedAspect = mainCanvas.width / mainCanvas.height;
867
+ mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
868
+ mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
869
+ if (glCanvas)
878
870
  {
879
- // fit to window by adding space on top or bottom if necessary
880
- const aspect = innerWidth / innerHeight;
881
- const fixedAspect = fixedWidth / fixedHeight;
882
- mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
883
- mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
884
- if (glCanvas)
885
- {
886
- glCanvas.style.width = mainCanvas.style.width;
887
- glCanvas.style.height = mainCanvas.style.height;
888
- }
871
+ glCanvas.style.width = mainCanvas.style.width;
872
+ glCanvas.style.height = mainCanvas.style.height;
889
873
  }
890
874
  }
891
875
  else
892
876
  {
893
877
  // clear and set size to same as window
894
- mainCanvas.width = min(innerWidth, maxWidth);
895
- mainCanvas.height = min(innerHeight, maxHeight);
878
+ mainCanvas.width = min(innerWidth, maxSize.x);
879
+ mainCanvas.height = min(innerHeight, maxSize.y);
896
880
  }
897
881
 
898
882
  // save canvas size and clear overlay canvas
@@ -1019,14 +1003,14 @@ class EngineObject
1019
1003
  {
1020
1004
  /** Create an engine object and adds it to the list of objects
1021
1005
  * @param {Vector2} [position=new Vector2(0,0)] - World space position of the object
1022
- * @param {Vector2} [size=defaultObjectSize] - World space size of the object
1006
+ * @param {Vector2} [size=objectDefaultSize] - World space size of the object
1023
1007
  * @param {Number} [tileIndex=-1] - Tile to use to render object, untextured if -1
1024
- * @param {Vector2} [tileSize=defaultTileSize] - Size of tile in source pixels
1008
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
1025
1009
  * @param {Number} [angle=0] - Angle to rotate the object
1026
1010
  * @param {Color} [color] - Color to apply to tile when rendered
1027
1011
  * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1028
1012
  */
1029
- constructor(pos=vec2(), size=defaultObjectSize, tileIndex=-1, tileSize=defaultTileSize, angle=0, color, renderOrder=0)
1013
+ constructor(pos=vec2(), size=objectDefaultSize, tileIndex=-1, tileSize=tileSizeDefault, angle=0, color, renderOrder=0)
1030
1014
  {
1031
1015
  // set passed in params
1032
1016
  ASSERT(pos && pos.x != undefined && size.x != undefined); // ensure pos and size are vec2s
@@ -1049,16 +1033,16 @@ class EngineObject
1049
1033
  this.additiveColor;
1050
1034
 
1051
1035
  // set object defaults
1052
- /** @property {Number} [mass=defaultObjectMass] - How heavy the object is */
1053
- this.mass = defaultObjectMass;
1054
- /** @property {Number} [damping=defaultObjectDamping] - How much to slow down velocity each frame (0-1) */
1055
- this.damping = defaultObjectDamping;
1056
- /** @property {Number} [angleDamping=defaultObjectAngleDamping] - How much to slow down rotation each frame (0-1) */
1057
- this.angleDamping = defaultObjectAngleDamping;
1058
- /** @property {Number} [elasticity=defaultObjectElasticity] - How bouncy the object is when colliding (0-1) */
1059
- this.elasticity = defaultObjectElasticity;
1060
- /** @property {Number} [friction=defaultObjectFriction] - How much friction to apply when sliding (0-1) */
1061
- this.friction = defaultObjectFriction;
1036
+ /** @property {Number} [mass=objectDefaultMass] - How heavy the object is */
1037
+ this.mass = objectDefaultMass;
1038
+ /** @property {Number} [damping=objectDefaultDamping] - How much to slow down velocity each frame (0-1) */
1039
+ this.damping = objectDefaultDamping;
1040
+ /** @property {Number} [angleDamping=objectDefaultAngleDamping] - How much to slow down rotation each frame (0-1) */
1041
+ this.angleDamping = objectDefaultAngleDamping;
1042
+ /** @property {Number} [elasticity=objectDefaultElasticity] - How bouncy the object is when colliding (0-1) */
1043
+ this.elasticity = objectDefaultElasticity;
1044
+ /** @property {Number} [friction=objectDefaultFriction] - How much friction to apply when sliding (0-1) */
1045
+ this.friction = objectDefaultFriction;
1062
1046
  /** @property {Number} [gravityScale=1] - How much to scale gravity by for this object */
1063
1047
  this.gravityScale = 1;
1064
1048
  /** @property {Number} [renderOrder=0] - Objects are sorted by render order */
@@ -1087,8 +1071,8 @@ class EngineObject
1087
1071
  }
1088
1072
 
1089
1073
  // limit max speed to prevent missing collisions
1090
- this.velocity.x = clamp(this.velocity.x, maxObjectSpeed, -maxObjectSpeed);
1091
- this.velocity.y = clamp(this.velocity.y, maxObjectSpeed, -maxObjectSpeed);
1074
+ this.velocity.x = clamp(this.velocity.x, objectMaxSpeed, -objectMaxSpeed);
1075
+ this.velocity.y = clamp(this.velocity.y, objectMaxSpeed, -objectMaxSpeed);
1092
1076
 
1093
1077
  // apply physics
1094
1078
  const oldPos = this.pos.copy();
@@ -1410,14 +1394,14 @@ const worldToScreen = (worldPos)=>
1410
1394
  * @param {Vector2} pos - Center of the tile in world space
1411
1395
  * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile in world space, width and height
1412
1396
  * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
1413
- * @param {Vector2} [tileSize=defaultTileSize] - Tile size in source pixels
1397
+ * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
1414
1398
  * @param {Color} [color=new Color(1,1,1)] - Color to modulate with
1415
1399
  * @param {Number} [angle=0] - Angle to rotate by
1416
1400
  * @param {Boolean} [mirror=0] - If true image is flipped along the Y axis
1417
1401
  * @param {Color} [additiveColor=new Color(0,0,0,0)] - Additive color to be applied
1418
1402
  * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1419
1403
  * @memberof Draw */
1420
- function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, color=new Color, angle=0, mirror,
1404
+ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror,
1421
1405
  additiveColor=new Color(0,0,0,0), useWebGL=glEnable)
1422
1406
  {
1423
1407
  showWatermark && ++drawCount;
@@ -1481,14 +1465,14 @@ function drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, col
1481
1465
  * @memberof Draw */
1482
1466
  function drawRect(pos, size, color, angle, useWebGL)
1483
1467
  {
1484
- drawTile(pos, size, -1, defaultTileSize, color, angle, 0, 0, useWebGL);
1468
+ drawTile(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
1485
1469
  }
1486
1470
 
1487
1471
  /** Draw textured tile centered on pos in screen space
1488
1472
  * @param {Vector2} pos - Center of the tile
1489
1473
  * @param {Vector2} [size=new Vector2(1,1)] - Size of the tile
1490
1474
  * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
1491
- * @param {Vector2} [tileSize=defaultTileSize] - Tile size in source pixels
1475
+ * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
1492
1476
  * @param {Color} [color=new Color]
1493
1477
  * @param {Number} [angle=0]
1494
1478
  * @param {Boolean} [mirror=0]
@@ -1509,7 +1493,7 @@ function drawTileScreenSpace(pos, size=vec2(1), tileIndex, tileSize, color, angl
1509
1493
  * @memberof Draw */
1510
1494
  function drawRectScreenSpace(pos, size, color, angle, useWebGL)
1511
1495
  {
1512
- drawTileSrceenSpace(pos, size, -1, defaultTileSize, color, angle, 0, 0, useWebGL);
1496
+ drawTileSrceenSpace(pos, size, -1, tileSizeDefault, color, angle, 0, 0, useWebGL);
1513
1497
  }
1514
1498
 
1515
1499
  /** Draw colored line between two points
@@ -1556,7 +1540,7 @@ function drawCanvas2D(pos, size, angle, mirror, drawFunction, context = mainCont
1556
1540
  * @param {Color} [lineColor=new Color(0,0,0)]
1557
1541
  * @param {String} [textAlign='center']
1558
1542
  * @memberof Draw */
1559
- function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=defaultFont)
1543
+ function drawText(text, pos, size=1, color=new Color, lineWidth=0, lineColor=new Color(0,0,0), textAlign='center', font=fontDefault)
1560
1544
  {
1561
1545
  pos = worldToScreen(pos);
1562
1546
  overlayContext.font = size*cameraScale + 'px '+ font;
@@ -1680,7 +1664,7 @@ let mouseWheel = 0;
1680
1664
 
1681
1665
  /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
1682
1666
  * @memberof Input */
1683
- let usingGamepad = 0;
1667
+ let isUsingGamepad = 0;
1684
1668
 
1685
1669
  /** Returns true if gamepad button is down
1686
1670
  * @param {Number} button
@@ -1742,7 +1726,7 @@ function inputUpdatePost()
1742
1726
  onkeydown = e=>
1743
1727
  {
1744
1728
  if (debug && e.target != document.body) return;
1745
- e.repeat || (inputData[usingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
1729
+ e.repeat || (inputData[isUsingGamepad = 0][remapKeyCode(e.keyCode)] = 3);
1746
1730
  debug || e.preventDefault();
1747
1731
  }
1748
1732
  onkeyup = e=>
@@ -1750,12 +1734,12 @@ onkeyup = e=>
1750
1734
  if (debug && e.target != document.body) return;
1751
1735
  inputData[0][remapKeyCode(e.keyCode)] = 4;
1752
1736
  }
1753
- const remapKeyCode = c=> copyWASDToDpad ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;
1737
+ const remapKeyCode = c=> inputWASDEmulateDirection ? c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c;
1754
1738
 
1755
1739
  ///////////////////////////////////////////////////////////////////////////////
1756
1740
  // Mouse event handlers
1757
1741
 
1758
- onmousedown = e=> {inputData[usingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
1742
+ onmousedown = e=> {inputData[isUsingGamepad = 0][e.button] = 3; onmousemove(e); e.button && e.preventDefault();}
1759
1743
  onmouseup = e=> inputData[0][e.button] = inputData[0][e.button] & 2 | 4;
1760
1744
  onmousemove = e=>
1761
1745
  {
@@ -1803,10 +1787,10 @@ function gamepadsUpdate()
1803
1787
  {
1804
1788
  const button = gamepad.buttons[j];
1805
1789
  data[j] = button.pressed ? 1 + 2*!gamepadIsDown(j,i) : 4*gamepadIsDown(j,i);
1806
- usingGamepad |= !i && button.pressed;
1790
+ isUsingGamepad |= !i && button.pressed;
1807
1791
  }
1808
1792
 
1809
- if (copyGamepadDirectionToStick)
1793
+ if (gamepadDirectionEmulateStick)
1810
1794
  {
1811
1795
  // copy dpad to left analog stick when pressed
1812
1796
  const dpad = vec2(gamepadIsDown(15,i) - gamepadIsDown(14,i), gamepadIsDown(12,i) - gamepadIsDown(13,i));
@@ -1823,7 +1807,7 @@ function gamepadsUpdate()
1823
1807
  /** True if a touch device has been detected
1824
1808
  * @const {boolean}
1825
1809
  * @memberof Input */
1826
- const isTouchDevice = touchInputEnable && window.ontouchstart !== undefined;
1810
+ const isTouchDevice = inputTouchEnable && window.ontouchstart !== undefined;
1827
1811
  if (isTouchDevice)
1828
1812
  {
1829
1813
  // handle all touch events the same way
@@ -1878,10 +1862,10 @@ class Sound
1878
1862
  {
1879
1863
  /** Create a sound object and cache the zzfx samples for later use
1880
1864
  * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
1881
- * @param {Number} [range=defaultSoundRange] - World space max range of sound, will not play if camera is farther away
1882
- * @param {Number} [taper=defaultSoundTaper] - At what percentage of range should it start tapering off
1865
+ * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1866
+ * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1883
1867
  */
1884
- constructor(zzfxSound, range=defaultSoundRange, taper=defaultSoundTaper)
1868
+ constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
1885
1869
  {
1886
1870
  if (!soundEnable) return;
1887
1871
 
@@ -2012,7 +1996,7 @@ function playAudioFile(url, volume=1, loop=1)
2012
1996
  if (!soundEnable) return;
2013
1997
 
2014
1998
  const audio = new Audio(url);
2015
- audio.volume = audioVolume * volume;
1999
+ audio.volume = soundVolume * volume;
2016
2000
  audio.loop = loop;
2017
2001
  audio.play();
2018
2002
  return audio;
@@ -2037,7 +2021,7 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
2037
2021
  // build utterance and speak
2038
2022
  const utterance = new SpeechSynthesisUtterance(text);
2039
2023
  utterance.lang = language;
2040
- utterance.volume = 2*volume*audioVolume;
2024
+ utterance.volume = 2*volume*soundVolume;
2041
2025
  utterance.rate = rate;
2042
2026
  utterance.pitch = pitch;
2043
2027
  speechSynthesis.speak(utterance);
@@ -2090,7 +2074,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
2090
2074
  // create pan and gain nodes
2091
2075
  source
2092
2076
  .connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, 1, -1)}))
2093
- .connect(new GainNode(audioContext, {'gain':audioVolume*volume}))
2077
+ .connect(new GainNode(audioContext, {'gain':soundVolume*volume}))
2094
2078
  .connect(audioContext.destination);
2095
2079
 
2096
2080
  // play and return sound
@@ -2158,7 +2142,7 @@ function zzfxG
2158
2142
  1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
2159
2143
  : 1) *
2160
2144
  sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
2161
- volume * audioVolume * ( // envelope
2145
+ volume * soundVolume * ( // envelope
2162
2146
  i < attack ? i/attack : // attack
2163
2147
  i < attack + decay ? // decay
2164
2148
  1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff
@@ -2461,12 +2445,12 @@ class TileLayer extends EngineObject
2461
2445
  {
2462
2446
  /** Create a tile layer object
2463
2447
  * @param {Vector2} [position=new Vector2(0,0)] - World space position
2464
- * @param {Vector2} [size=defaultObjectSize] - World space size
2465
- * @param {Vector2} [tileSize=defaultTileSize] - Size of tiles in source pixels
2448
+ * @param {Vector2} [size=objectDefaultSize] - World space size
2449
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
2466
2450
  * @param {Vector2} [scale=new Vector2(1,1)] - How much to scale this layer when rendered
2467
2451
  * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
2468
2452
  */
2469
- constructor(pos, size=tileCollisionSize, tileSize=defaultTileSize, scale=vec2(1), renderOrder=0)
2453
+ constructor(pos, size=tileCollisionSize, tileSize=tileSizeDefault, scale=vec2(1), renderOrder=0)
2470
2454
  {
2471
2455
  super(pos, size, -1, tileSize, 0, undefined, renderOrder);
2472
2456
 
@@ -2625,11 +2609,11 @@ class TileLayer extends EngineObject
2625
2609
  * @param {Vector2} pos
2626
2610
  * @param {Vector2} [size=new Vector2(1,1)]
2627
2611
  * @param {Number} [tileIndex=-1]
2628
- * @param {Vector2} [tileSize=defaultTileSize]
2612
+ * @param {Vector2} [tileSize=tileSizeDefault]
2629
2613
  * @param {Color} [color=new Color(1,1,1)]
2630
2614
  * @param {Number} [angle=0]
2631
2615
  * @param {Boolean} [mirror=0] */
2632
- drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=defaultTileSize, color=new Color, angle=0, mirror)
2616
+ drawTile(pos, size=vec2(1), tileIndex=-1, tileSize=tileSizeDefault, color=new Color, angle=0, mirror)
2633
2617
  {
2634
2618
  this.drawCanvas2D(pos, size, angle, mirror, (context)=>
2635
2619
  {
@@ -2692,7 +2676,7 @@ class ParticleEmitter extends EngineObject
2692
2676
  * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
2693
2677
  * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
2694
2678
  * @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
2695
- * @param {Number} [tileSize=defaultTileSize] - Tile size for particles
2679
+ * @param {Number} [tileSize=tileSizeDefault] - Tile size for particles
2696
2680
  * @param {Color} [colorStartA=new Color(1,1,1)] - Color at start of life 1, randomized between start colors
2697
2681
  * @param {Color} [colorStartB=new Color(1,1,1)] - Color at start of life 2, randomized between start colors
2698
2682
  * @param {Color} [colorEndA=new Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
@@ -2721,7 +2705,7 @@ class ParticleEmitter extends EngineObject
2721
2705
  emitRate = 100,
2722
2706
  emitConeAngle = PI,
2723
2707
  tileIndex = -1,
2724
- tileSize = defaultTileSize,
2708
+ tileSize = tileSizeDefault,
2725
2709
  colorStartA = new Color,
2726
2710
  colorStartB = new Color,
2727
2711
  colorEndA = new Color(1,1,1,0),
@@ -2892,7 +2876,7 @@ class Particle extends EngineObject
2892
2876
  * Create a particle with the given settings
2893
2877
  * @param {Vector2} position - World space position of the particle
2894
2878
  * @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
2895
- * @param {Vector2} [tileSize=defaultTileSize] - Size of tile in source pixels
2879
+ * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
2896
2880
  * @param {Number} [angle=0] - Angle to rotate the particle
2897
2881
  */
2898
2882
  constructor(pos, tileIndex, tileSize, angle) { super(pos, new Vector2, tileIndex, tileSize, angle); }
@@ -3054,9 +3038,9 @@ class Medal
3054
3038
 
3055
3039
  // draw the text
3056
3040
  context.textAlign = 'left';
3057
- context.font = '3em '+ defaultFont;
3041
+ context.font = '3em '+ fontDefault;
3058
3042
  context.fillText(this.name, x+medalDisplayIconSize+25, y+35);
3059
- context.font = '1.5em '+ defaultFont;
3043
+ context.font = '1.5em '+ fontDefault;
3060
3044
  context.restore(context.fillText(this.description, x+medalDisplayIconSize+25, y+70));
3061
3045
  }
3062
3046
 
@@ -3071,7 +3055,7 @@ class Medal
3071
3055
  const context = overlayContext;
3072
3056
  context.textAlign = 'center';
3073
3057
  context.textBaseline = 'middle';
3074
- context.font = size*.6 + 'px '+ defaultFont;
3058
+ context.font = size*.6 + 'px '+ fontDefault;
3075
3059
  context.fillStyle = '#000';
3076
3060
  if (this.image)
3077
3061
  context.drawImage(this.image, x-size/2, y-size/2, size, size);
package/engine/engine.js CHANGED
@@ -22,7 +22,7 @@
22
22
  const engineName = 'LittleJS';
23
23
 
24
24
  /** Version of engine */
25
- const engineVersion = '1.1.6';
25
+ const engineVersion = '1.1.8';
26
26
 
27
27
  /** Frames per second to update objects
28
28
  * @default */
@@ -147,31 +147,28 @@ function engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRender
147
147
  frameTimeBufferMS += deltaSmooth;
148
148
  }
149
149
 
150
- if (fixedWidth)
150
+ if (fixedSize.x)
151
151
  {
152
152
  // clear set fixed size
153
- mainCanvas.width = fixedWidth;
154
- mainCanvas.height = fixedHeight;
153
+ mainCanvas.width = fixedSize.x;
154
+ mainCanvas.height = fixedSize.y;
155
155
 
156
- if (fixedFitToWindow)
156
+ // fit to window by adding space on top or bottom if necessary
157
+ const aspect = innerWidth / innerHeight;
158
+ const fixedAspect = mainCanvas.width / mainCanvas.height;
159
+ mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
160
+ mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
161
+ if (glCanvas)
157
162
  {
158
- // fit to window by adding space on top or bottom if necessary
159
- const aspect = innerWidth / innerHeight;
160
- const fixedAspect = fixedWidth / fixedHeight;
161
- mainCanvas.style.width = overlayCanvas.style.width = aspect < fixedAspect ? '100%' : '';
162
- mainCanvas.style.height = overlayCanvas.style.height = aspect < fixedAspect ? '' : '100%';
163
- if (glCanvas)
164
- {
165
- glCanvas.style.width = mainCanvas.style.width;
166
- glCanvas.style.height = mainCanvas.style.height;
167
- }
163
+ glCanvas.style.width = mainCanvas.style.width;
164
+ glCanvas.style.height = mainCanvas.style.height;
168
165
  }
169
166
  }
170
167
  else
171
168
  {
172
169
  // clear and set size to same as window
173
- mainCanvas.width = min(innerWidth, maxWidth);
174
- mainCanvas.height = min(innerHeight, maxHeight);
170
+ mainCanvas.width = min(innerWidth, maxSize.x);
171
+ mainCanvas.height = min(innerHeight, maxSize.y);
175
172
  }
176
173
 
177
174
  // save canvas size and clear overlay canvas
@@ -23,10 +23,10 @@ class Sound
23
23
  {
24
24
  /** Create a sound object and cache the zzfx samples for later use
25
25
  * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
26
- * @param {Number} [range=defaultSoundRange] - World space max range of sound, will not play if camera is farther away
27
- * @param {Number} [taper=defaultSoundTaper] - At what percentage of range should it start tapering off
26
+ * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
27
+ * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
28
28
  */
29
- constructor(zzfxSound, range=defaultSoundRange, taper=defaultSoundTaper)
29
+ constructor(zzfxSound, range=soundDefaultRange, taper=soundDefaultTaper)
30
30
  {
31
31
  if (!soundEnable) return;
32
32
 
@@ -157,7 +157,7 @@ function playAudioFile(url, volume=1, loop=1)
157
157
  if (!soundEnable) return;
158
158
 
159
159
  const audio = new Audio(url);
160
- audio.volume = audioVolume * volume;
160
+ audio.volume = soundVolume * volume;
161
161
  audio.loop = loop;
162
162
  audio.play();
163
163
  return audio;
@@ -182,7 +182,7 @@ function speak(text, language='', volume=1, rate=1, pitch=1)
182
182
  // build utterance and speak
183
183
  const utterance = new SpeechSynthesisUtterance(text);
184
184
  utterance.lang = language;
185
- utterance.volume = 2*volume*audioVolume;
185
+ utterance.volume = 2*volume*soundVolume;
186
186
  utterance.rate = rate;
187
187
  utterance.pitch = pitch;
188
188
  speechSynthesis.speak(utterance);
@@ -235,7 +235,7 @@ function playSamples(sampleChannels, volume=1, rate=1, pan=0, loop=0)
235
235
  // create pan and gain nodes
236
236
  source
237
237
  .connect(new StereoPannerNode(audioContext, {'pan':clamp(pan, 1, -1)}))
238
- .connect(new GainNode(audioContext, {'gain':audioVolume*volume}))
238
+ .connect(new GainNode(audioContext, {'gain':soundVolume*volume}))
239
239
  .connect(audioContext.destination);
240
240
 
241
241
  // play and return sound
@@ -303,7 +303,7 @@ function zzfxG
303
303
  1 - tremolo + tremolo*Math.sin(PI2*i/repeatTime) // tremolo
304
304
  : 1) *
305
305
  sign(s)*(abs(s)**shapeCurve) * // curve 0=square, 2=pointy
306
- volume * audioVolume * ( // envelope
306
+ volume * soundVolume * ( // envelope
307
307
  i < attack ? i/attack : // attack
308
308
  i < attack + decay ? // decay
309
309
  1-((i-attack)/decay)*(1-sustainVolume) : // decay falloff