littlejsengine 1.16.2 → 1.17.5

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 (57) hide show
  1. package/dist/littlejs.d.ts +291 -246
  2. package/dist/littlejs.esm.js +1520 -1271
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +1178 -920
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +1170 -912
  7. package/examples/box2d/gameObjects.js +4 -4
  8. package/examples/breakout/game.js +5 -6
  9. package/examples/electron/index.html +2 -2
  10. package/examples/electron/tiles.png +0 -0
  11. package/examples/htmlMenu/tiles.png +0 -0
  12. package/examples/index.html +9 -8
  13. package/examples/logo.png +0 -0
  14. package/examples/module/build.bat +7 -0
  15. package/examples/module/build.js +121 -0
  16. package/examples/module/tiles.png +0 -0
  17. package/examples/platformer/game.js +1 -1
  18. package/examples/platformer/gameEffects.js +25 -29
  19. package/examples/platformer/gameLevel.js +27 -28
  20. package/examples/puzzle/game.js +2 -2
  21. package/examples/shorts/base.html +4 -1
  22. package/examples/shorts/box2dPool.js +2 -2
  23. package/examples/shorts/box2dTileLayer.js +48 -0
  24. package/examples/shorts/clock.js +3 -3
  25. package/examples/shorts/fontImage.js +4 -3
  26. package/examples/shorts/music.js +2 -2
  27. package/examples/shorts/musicPlayer.js +2 -2
  28. package/examples/shorts/parallax.js +1 -1
  29. package/examples/shorts/sequencer.js +1 -1
  30. package/examples/shorts/shapes.js +1 -1
  31. package/examples/shorts/texture.js +10 -6
  32. package/examples/shorts/tiles.png +0 -0
  33. package/examples/shorts/tiltedView.js +2 -0
  34. package/examples/starter/index.html +2 -2
  35. package/examples/starter/tiles.png +0 -0
  36. package/examples/typescript/tiles.png +0 -0
  37. package/examples/uiSystem/game.js +1 -1
  38. package/examples/uiSystem/tiles.png +0 -0
  39. package/package.json +5 -5
  40. package/plugins/box2d.js +167 -63
  41. package/plugins/postProcess.js +47 -28
  42. package/plugins/uiSystem.js +18 -18
  43. package/plugins/zzfxm.js +2 -2
  44. package/reference.md +4 -3
  45. package/src/engine.js +182 -181
  46. package/src/engineAudio.js +47 -63
  47. package/src/engineDebug.js +8 -8
  48. package/src/engineDraw.js +184 -124
  49. package/src/engineExport.js +325 -334
  50. package/src/engineFont.png +0 -0
  51. package/src/engineInput.js +18 -24
  52. package/src/engineMath.js +24 -113
  53. package/src/engineObject.js +27 -26
  54. package/src/engineParticles.js +2 -2
  55. package/src/engineTileLayer.js +229 -192
  56. package/src/engineUtilities.js +100 -4
  57. package/src/engineWebGL.js +124 -73
@@ -123,11 +123,11 @@ declare module "littlejsengine" {
123
123
  * @example
124
124
  * // Basic engine startup
125
125
  * engineInit(
126
- * () => { LOG('Game initialized!'); }, // gameInit
127
- * () => { updateGameLogic(); }, // gameUpdate
128
- * () => { updateUI(); }, // gameUpdatePost
129
- * () => { drawBackground(); }, // gameRender
130
- * () => { drawHUD(); }, // gameRenderPost
126
+ * ()=> { LOG('Game initialized!'); }, // gameInit
127
+ * ()=> { updateGameLogic(); }, // gameUpdate
128
+ * ()=> { updateUI(); }, // gameUpdatePost
129
+ * ()=> { drawBackground(); }, // gameRender
130
+ * ()=> { drawHUD(); }, // gameRenderPost
131
131
  * ['tiles.png', 'tilesLevel.png'] // images to load
132
132
  * );
133
133
  * @memberof Engine */
@@ -203,16 +203,16 @@ declare module "littlejsengine" {
203
203
  /** Asserts if the expression is false, does nothing in release builds
204
204
  * Halts execution if the assert fails and throws an error
205
205
  * @param {boolean} assert
206
- * @param {...Object} [output] - error message output
206
+ * @param {...Object} output - error message output
207
207
  * @memberof Debug */
208
- export function ASSERT(assert: boolean, ...output?: any[]): void;
208
+ export function ASSERT(assert: boolean, ...output: any[]): void;
209
209
  /** Log to console if debug is enabled, does nothing in release builds
210
- * @param {...Object} [output] - message output
210
+ * @param {...Object} output - message output
211
211
  * @memberof Debug */
212
- export function LOG(...output?: any[]): void;
212
+ export function LOG(...output: any[]): void;
213
213
  /** Draw a debug rectangle in world space
214
214
  * @param {Vector2} pos
215
- * @param {Vector2} [size=Vector2()]
215
+ * @param {Vector2} [size=vec2(0)]
216
216
  * @param {Color|string} [color]
217
217
  * @param {number} [time]
218
218
  * @param {number} [angle]
@@ -721,12 +721,11 @@ declare module "littlejsengine" {
721
721
  * @memberof Debug */
722
722
  export function setDebugKey(key: string): void;
723
723
  /**
724
- * LittleJS Utility Classes and Functions
724
+ * LittleJS Math Classes and Functions
725
725
  * - General purpose math library
726
- * - Vector2 - fast, simple, easy 2D vector class
727
- * - Color - holds a rgba color with some math functions
728
- * - Timer - tracks time automatically
729
726
  * - RandomGenerator - seeded random number generator
727
+ * - Vector2 - fast, simple, easy 2D vector class
728
+ * - Color - holds a rgba color with math functions
730
729
  * @namespace Math
731
730
  */
732
731
  /** The value of PI
@@ -735,22 +734,22 @@ declare module "littlejsengine" {
735
734
  * @memberof Math */
736
735
  export const PI: number;
737
736
  /** Returns absolute value of value passed in
738
- * @param {number} value
737
+ * @param {number} x
739
738
  * @return {number}
740
739
  * @memberof Math */
741
740
  export const abs: (x: number) => number;
742
741
  /** Returns floored value of value passed in
743
- * @param {number} value
742
+ * @param {number} x
744
743
  * @return {number}
745
744
  * @memberof Math */
746
745
  export const floor: (x: number) => number;
747
746
  /** Returns ceiled value of value passed in
748
- * @param {number} value
747
+ * @param {number} x
749
748
  * @return {number}
750
749
  * @memberof Math */
751
750
  export const ceil: (x: number) => number;
752
751
  /** Returns rounded value passed in
753
- * @param {number} value
752
+ * @param {number} x
754
753
  * @return {number}
755
754
  * @memberof Math */
756
755
  export const round: (x: number) => number;
@@ -765,7 +764,7 @@ declare module "littlejsengine" {
765
764
  * @memberof Math */
766
765
  export const max: (...values: number[]) => number;
767
766
  /** Returns the sign of value passed in
768
- * @param {number} value
767
+ * @param {number} x
769
768
  * @return {number}
770
769
  * @memberof Math */
771
770
  export const sign: (x: number) => number;
@@ -775,22 +774,22 @@ declare module "littlejsengine" {
775
774
  * @memberof Math */
776
775
  export const hypot: (...values: number[]) => number;
777
776
  /** Returns log2 of value passed in
778
- * @param {number} value
777
+ * @param {number} x
779
778
  * @return {number}
780
779
  * @memberof Math */
781
780
  export const log2: (x: number) => number;
782
781
  /** Returns sin of value passed in
783
- * @param {number} value
782
+ * @param {number} x
784
783
  * @return {number}
785
784
  * @memberof Math */
786
785
  export const sin: (x: number) => number;
787
786
  /** Returns cos of value passed in
788
- * @param {number} value
787
+ * @param {number} x
789
788
  * @return {number}
790
789
  * @memberof Math */
791
790
  export const cos: (x: number) => number;
792
791
  /** Returns tan of value passed in
793
- * @param {number} value
792
+ * @param {number} x
794
793
  * @return {number}
795
794
  * @memberof Math */
796
795
  export const tan: (x: number) => number;
@@ -867,11 +866,11 @@ declare module "littlejsengine" {
867
866
  export function nearestPowerOfTwo(value: number): number;
868
867
  /** Returns true if two axis aligned bounding boxes are overlapping
869
868
  * this can be used for simple collision detection between objects
870
- * @param {Vector2} posA - Center of box A
871
- * @param {Vector2} sizeA - Size of box A
872
- * @param {Vector2} posB - Center of box B
873
- * @param {Vector2} [sizeB=(0,0)] - Size of box B, uses a point if undefined
874
- * @return {boolean} - True if overlapping
869
+ * @param {Vector2} posA - Center of box A
870
+ * @param {Vector2} sizeA - Size of box A
871
+ * @param {Vector2} posB - Center of box B
872
+ * @param {Vector2} [sizeB=vec2()] - Size of box B, uses a point if undefined
873
+ * @return {boolean} - True if overlapping
875
874
  * @memberof Math */
876
875
  export function isOverlapping(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB?: Vector2): boolean;
877
876
  /** Returns true if a line segment is intersecting an axis aligned box
@@ -892,11 +891,8 @@ declare module "littlejsengine" {
892
891
  export function wave(frequency?: number, amplitude?: number, t?: number, offset?: number): number;
893
892
  /**
894
893
  * LittleJS Utility Classes and Functions
895
- * - General purpose math library
896
- * - Vector2 - fast, simple, easy 2D vector class
897
- * - Color - holds a rgba color with some math functions
894
+ * - General purpose utilities
898
895
  * - Timer - tracks time automatically
899
- * - RandomGenerator - seeded random number generator
900
896
  * @namespace Utilities
901
897
  */
902
898
  /** Formats seconds to mm:ss style for display purposes
@@ -927,6 +923,12 @@ declare module "littlejsengine" {
927
923
  * @param {number} [revokeTime] - how long before revoking the url
928
924
  * @memberof Utilities */
929
925
  export function saveDataURL(url: string, filename?: string, revokeTime?: number): void;
926
+ /** Share content using the native share dialog if available
927
+ * @param {string} title - title of the share
928
+ * @param {string} url - url to share
929
+ * @param {Function} [callback] - Called when share is complete
930
+ * @memberof Utilities */
931
+ export function shareURL(title: string, url: string, callback?: Function): void;
930
932
  /** Random global functions
931
933
  * @namespace Random */
932
934
  /** Returns a random value between the two values passed in
@@ -963,8 +965,8 @@ declare module "littlejsengine" {
963
965
  * @memberof Random */
964
966
  export function randVec2(length?: number): Vector2;
965
967
  /** Returns a random color between the two passed in colors, combine components if linear
966
- * @param {Color} [colorA=(1,1,1,1)]
967
- * @param {Color} [colorB=(0,0,0,1)]
968
+ * @param {Color} [colorA=WHITE]
969
+ * @param {Color} [colorB=BLACK]
968
970
  * @param {boolean} [linear]
969
971
  * @return {Color}
970
972
  * @memberof Random */
@@ -1017,8 +1019,8 @@ declare module "littlejsengine" {
1017
1019
  * @return {Vector2} */
1018
1020
  vec2(valueA?: number, valueB?: number): Vector2;
1019
1021
  /** Returns a random color between the two passed in colors, combine components if linear
1020
- * @param {Color} [colorA=(1,1,1,1)]
1021
- * @param {Color} [colorB=(0,0,0,1)]
1022
+ * @param {Color} [colorA=WHITE]
1023
+ * @param {Color} [colorB=BLACK]
1022
1024
  * @param {boolean} [linear]
1023
1025
  * @return {Color} */
1024
1026
  randColor(colorA?: Color, colorB?: Color, linear?: boolean): Color;
@@ -1148,9 +1150,6 @@ declare module "littlejsengine" {
1148
1150
  /** Returns the area this vector covers as a rectangle
1149
1151
  * @return {number} */
1150
1152
  area(): number;
1151
- /** Returns true if this vector is (0,0)
1152
- * @return {boolean} */
1153
- isZero(): boolean;
1154
1153
  /** Returns a new vector that is p percent between this and the vector passed in
1155
1154
  * @param {Vector2} v - other vector
1156
1155
  * @param {number} percent
@@ -1436,10 +1435,11 @@ declare module "littlejsengine" {
1436
1435
  * Create a tile info object using a grid based system
1437
1436
  * - This can take vecs or floats for easier use and conversion
1438
1437
  * - If an index is passed in, the tile size and index will determine the position
1439
- * @param {Vector2|number} [pos=0] - Position of the tile in pixels, or tile index
1438
+ * @param {Vector2|number} [index=0] - Index of the tile in 1d or 2d form
1440
1439
  * @param {Vector2|number} [size] - Size of tile in pixels
1441
- * @param {number} [textureIndex] - Texture index to use
1440
+ * @param {TextureInfo|number} [texture] - Texture index or info to use
1442
1441
  * @param {number} [padding] - How many pixels padding around tiles
1442
+ * @param {number} [bleed] - How many pixels smaller to draw tiles
1443
1443
  * @return {TileInfo}
1444
1444
  * @example
1445
1445
  * tile(2) // a tile at index 2 using the default tile size of 16
@@ -1447,26 +1447,24 @@ declare module "littlejsengine" {
1447
1447
  * tile(1, 16, 3) // a tile at index 1 of size 16 on texture 3
1448
1448
  * tile(vec2(4,8), vec2(30,10)) // a tile at index (4,8) with a size of (30,10)
1449
1449
  * @memberof Draw */
1450
- export function tile(pos?: Vector2 | number, size?: Vector2 | number, textureIndex?: number, padding?: number): TileInfo;
1450
+ export function tile(index?: Vector2 | number, size?: Vector2 | number, texture?: TextureInfo | number, padding?: number, bleed?: number): TileInfo;
1451
1451
  /**
1452
1452
  * Tile Info - Stores info about how to draw a tile
1453
1453
  * @memberof Draw
1454
1454
  */
1455
1455
  export class TileInfo {
1456
1456
  /** Create a tile info object
1457
- * @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
1457
+ * @param {Vector2} [pos=vec2()] - Top left corner of tile in pixels
1458
1458
  * @param {Vector2} [size] - Size of tile in pixels
1459
- * @param {number} [textureIndex] - Texture index to use
1460
- * @param {number} [padding] - How many pixels padding around tiles
1461
- * @param {number} [bleed] - How many pixels smaller to draw tiles
1459
+ * @param {TextureInfo} [textureInfo] - Texture info to use
1460
+ * @param {number} [padding] - How many pixels padding around tiles
1461
+ * @param {number} [bleed] - How many pixels smaller to draw tiles
1462
1462
  */
1463
- constructor(pos?: Vector2, size?: Vector2, textureIndex?: number, padding?: number, bleed?: number);
1463
+ constructor(pos?: Vector2, size?: Vector2, textureInfo?: TextureInfo, padding?: number, bleed?: number);
1464
1464
  /** @property {Vector2} - Top left corner of tile in pixels */
1465
1465
  pos: Vector2;
1466
1466
  /** @property {Vector2} - Size of tile in pixels */
1467
1467
  size: Vector2;
1468
- /** @property {number} - Texture index to use */
1469
- textureIndex: number;
1470
1468
  /** @property {number} - How many pixels padding around tiles */
1471
1469
  padding: number;
1472
1470
  /** @property {TextureInfo} - The texture info for this tile */
@@ -1485,10 +1483,16 @@ declare module "littlejsengine" {
1485
1483
  frame(frame: number): TileInfo;
1486
1484
  /**
1487
1485
  * Set this tile to use a full image in a texture info
1488
- * @param {TextureInfo} textureInfo
1486
+ * @param {TextureInfo} [textureInfo]
1487
+ * @return {TileInfo}
1488
+ */
1489
+ setFullImage(textureInfo?: TextureInfo): TileInfo;
1490
+ /**
1491
+ * Returns a tile info for an index using this tile as refrence
1492
+ * @param {Vector2|number} [index=0]
1489
1493
  * @return {TileInfo}
1490
1494
  */
1491
- setFullImage(textureInfo: TextureInfo): TileInfo;
1495
+ tile(index?: Vector2 | number): TileInfo;
1492
1496
  }
1493
1497
  /**
1494
1498
  * Tile Info - Stores info about each texture
@@ -1604,14 +1608,14 @@ declare module "littlejsengine" {
1604
1608
  * @return {[Vector2, Vector2, number]} - [pos, size, angle]
1605
1609
  * @memberof Draw */
1606
1610
  export function screenToWorldTransform(screenPos: Vector2, screenSize: Vector2, screenAngle?: number): [Vector2, Vector2, number];
1607
- /** Draw textured tile centered in world space, with color applied if using WebGL
1608
- * @param {Vector2} pos - Center of the tile in world space
1609
- * @param {Vector2} [size=(1,1)] - Size of the tile in world space
1610
- * @param {TileInfo} [tileInfo] - Tile info to use, untextured if undefined
1611
- * @param {Color} [color=(1,1,1,1)] - Color to modulate with
1612
- * @param {number} [angle] - Angle to rotate by
1613
- * @param {boolean} [mirror] - Is image flipped along the Y axis?
1614
- * @param {Color} [additiveColor] - Additive color to be applied if any
1611
+ /** Draw textured tile centered in world space
1612
+ * @param {Vector2} pos - Center of the tile in world space
1613
+ * @param {Vector2} [size=vec2(1)] - Size of the tile in world space
1614
+ * @param {TileInfo} [tileInfo] - Tile info to use, untextured if undefined
1615
+ * @param {Color} [color=WHITE] - Color to modulate with
1616
+ * @param {number} [angle] - Angle to rotate by
1617
+ * @param {boolean} [mirror] - Is image flipped along the Y axis?
1618
+ * @param {Color} [additiveColor] - Additive color to be applied if any
1615
1619
  * @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering?
1616
1620
  * @param {boolean} [screenSpace=false] - Are the pos and size are in screen space?
1617
1621
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
@@ -1619,8 +1623,8 @@ declare module "littlejsengine" {
1619
1623
  export function drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1620
1624
  /** Draw colored rect centered on pos
1621
1625
  * @param {Vector2} pos
1622
- * @param {Vector2} [size=(1,1)]
1623
- * @param {Color} [color=(1,1,1,1)]
1626
+ * @param {Vector2} [size=vec2(1)]
1627
+ * @param {Color} [color=WHITE]
1624
1628
  * @param {number} [angle]
1625
1629
  * @param {boolean} [useWebGL=glEnable]
1626
1630
  * @param {boolean} [screenSpace]
@@ -1629,9 +1633,9 @@ declare module "littlejsengine" {
1629
1633
  export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1630
1634
  /** Draw a rect centered on pos with a gradient from top to bottom
1631
1635
  * @param {Vector2} pos
1632
- * @param {Vector2} [size=(1,1)]
1633
- * @param {Color} [colorTop=(1,1,1,1)]
1634
- * @param {Color} [colorBottom=(0,0,0,1)]
1636
+ * @param {Vector2} [size=vec2(1)]
1637
+ * @param {Color} [colorTop=WHITE]
1638
+ * @param {Color} [colorBottom=BLACK]
1635
1639
  * @param {number} [angle]
1636
1640
  * @param {boolean} [useWebGL=glEnable]
1637
1641
  * @param {boolean} [screenSpace]
@@ -1641,9 +1645,9 @@ declare module "littlejsengine" {
1641
1645
  /** Draw connected lines between a series of points
1642
1646
  * @param {Array<Vector2>} points
1643
1647
  * @param {number} [width]
1644
- * @param {Color} [color=(1,1,1,1)]
1648
+ * @param {Color} [color=WHITE]
1645
1649
  * @param {boolean} [wrap] - Should the last point connect to the first?
1646
- * @param {Vector2} [pos=(0,0)] - Offset to apply
1650
+ * @param {Vector2} [pos=vec2()] - Offset to apply
1647
1651
  * @param {number} [angle] - Angle to rotate by
1648
1652
  * @param {boolean} [useWebGL=glEnable]
1649
1653
  * @param {boolean} [screenSpace]
@@ -1654,8 +1658,8 @@ declare module "littlejsengine" {
1654
1658
  * @param {Vector2} posA
1655
1659
  * @param {Vector2} posB
1656
1660
  * @param {number} [width]
1657
- * @param {Color} [color=(1,1,1,1)]
1658
- * @param {Vector2} [pos=(0,0)] - Offset to apply
1661
+ * @param {Color} [color=WHITE]
1662
+ * @param {Vector2} [pos=vec2()] - Offset to apply
1659
1663
  * @param {number} [angle] - Angle to rotate by
1660
1664
  * @param {boolean} [useWebGL=glEnable]
1661
1665
  * @param {boolean} [screenSpace]
@@ -1664,10 +1668,10 @@ declare module "littlejsengine" {
1664
1668
  export function drawLine(posA: Vector2, posB: Vector2, width?: number, color?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1665
1669
  /** Draw colored polygon using passed in points
1666
1670
  * @param {Array<Vector2>} points - Array of Vector2 points
1667
- * @param {Color} [color=(1,1,1,1)]
1671
+ * @param {Color} [color=WHITE]
1668
1672
  * @param {number} [lineWidth]
1669
- * @param {Color} [lineColor=(0,0,0,1)]
1670
- * @param {Vector2} [pos=(0,0)] - Offset to apply
1673
+ * @param {Color} [lineColor=BLACK]
1674
+ * @param {Vector2} [pos=vec2()] - Offset to apply
1671
1675
  * @param {number} [angle] - Angle to rotate by
1672
1676
  * @param {boolean} [useWebGL=glEnable]
1673
1677
  * @param {boolean} [screenSpace]
@@ -1676,11 +1680,11 @@ declare module "littlejsengine" {
1676
1680
  export function drawPoly(points: Array<Vector2>, color?: Color, lineWidth?: number, lineColor?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1677
1681
  /** Draw colored ellipse using passed in point
1678
1682
  * @param {Vector2} pos
1679
- * @param {Vector2} [size=(1,1)] - Width and height diameter
1680
- * @param {Color} [color=(1,1,1,1)]
1683
+ * @param {Vector2} [size=vec2(1)] - Width and height diameter
1684
+ * @param {Color} [color=WHITE]
1681
1685
  * @param {number} [angle]
1682
1686
  * @param {number} [lineWidth]
1683
- * @param {Color} [lineColor=(0,0,0,1)]
1687
+ * @param {Color} [lineColor=BLACK]
1684
1688
  * @param {boolean} [useWebGL=glEnable]
1685
1689
  * @param {boolean} [screenSpace]
1686
1690
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
@@ -1689,9 +1693,9 @@ declare module "littlejsengine" {
1689
1693
  /** Draw colored circle using passed in point
1690
1694
  * @param {Vector2} pos
1691
1695
  * @param {number} [size=1] - Diameter
1692
- * @param {Color} [color=(1,1,1,1)]
1696
+ * @param {Color} [color=WHITE]
1693
1697
  * @param {number} [lineWidth=0]
1694
- * @param {Color} [lineColor=(0,0,0,1)]
1698
+ * @param {Color} [lineColor=BLACK]
1695
1699
  * @param {boolean} [useWebGL=glEnable]
1696
1700
  * @param {boolean} [screenSpace]
1697
1701
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
@@ -1717,9 +1721,9 @@ declare module "littlejsengine" {
1717
1721
  * @param {string|number} text
1718
1722
  * @param {Vector2} pos
1719
1723
  * @param {number} [size]
1720
- * @param {Color} [color=(1,1,1,1)]
1724
+ * @param {Color} [color=WHITE]
1721
1725
  * @param {number} [lineWidth]
1722
- * @param {Color} [lineColor=(0,0,0,1)]
1726
+ * @param {Color} [lineColor=BLACK]
1723
1727
  * @param {CanvasTextAlign} [textAlign='center']
1724
1728
  * @param {string} [font=fontDefault]
1725
1729
  * @param {string} [fontStyle]
@@ -1732,10 +1736,10 @@ declare module "littlejsengine" {
1732
1736
  * Automatically splits new lines into rows
1733
1737
  * @param {string|number} text
1734
1738
  * @param {Vector2} pos
1735
- * @param {number} [size]
1736
- * @param {Color} [color=(1,1,1,1)]
1739
+ * @param {number} size
1740
+ * @param {Color} [color=WHITE]
1737
1741
  * @param {number} [lineWidth]
1738
- * @param {Color} [lineColor=(0,0,0,1)]
1742
+ * @param {Color} [lineColor=BLACK]
1739
1743
  * @param {CanvasTextAlign} [textAlign]
1740
1744
  * @param {string} [font=fontDefault]
1741
1745
  * @param {string} [fontStyle]
@@ -1743,7 +1747,7 @@ declare module "littlejsengine" {
1743
1747
  * @param {number} [angle]
1744
1748
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1745
1749
  * @memberof Draw */
1746
- export function drawTextScreen(text: string | number, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1750
+ export function drawTextScreen(text: string | number, pos: Vector2, size: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1747
1751
  /** Enable normal or additive blend mode
1748
1752
  * @param {boolean} [additive]
1749
1753
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
@@ -1753,46 +1757,52 @@ declare module "littlejsengine" {
1753
1757
  * This is necessary for things like screenshots and video
1754
1758
  * @memberof Draw */
1755
1759
  export function combineCanvases(): void;
1756
- export let engineFontImage: any;
1760
+ /** Engine font image, 8x8 font provided by the engine
1761
+ * @type {FontImage}
1762
+ * @memberof Draw */
1763
+ export let engineFontImage: FontImage;
1757
1764
  /**
1758
- * Font Image Object - Draw text on a 2D canvas by using characters in an image
1765
+ * Font Image Object - Draw text by using tiles in an image
1759
1766
  * - 96 characters (from space to tilde) are stored in an image
1760
- * - Uses a default 8x8 font if none is supplied
1761
- * - You can also use fonts from the main tile sheet
1767
+ * - A 8x8 default engine font is supplied for general use
1768
+ * - This system is WebGL enabled for fast text rendering
1769
+ * - Fonts can also be colored and scaled along each axis
1770
+ *
1762
1771
  * @memberof Draw
1763
1772
  * @example
1764
1773
  * // use built in font
1765
- * const font = new FontImage;
1774
+ * const font = engineFontImage;
1766
1775
  *
1767
1776
  * // draw text
1768
1777
  * font.drawTextScreen('LittleJS\nHello World!', vec2(200, 50));
1769
1778
  */
1770
1779
  export class FontImage {
1771
1780
  /** Create an image font
1772
- * @param {HTMLImageElement} [image] - Image for the font, default if undefined
1773
- * @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
1774
- * @param {Vector2} [paddingSize=(0,1)] - How much space between characters
1781
+ * @param {TileInfo} tileInfo - Tile info of first characeter in font
1775
1782
  */
1776
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2);
1777
- image: any;
1778
- tileSize: Vector2;
1779
- paddingSize: Vector2;
1783
+ constructor(tileInfo: TileInfo);
1784
+ /** @property {TileInfo} - Tile info for the font */
1785
+ tileInfo: TileInfo;
1780
1786
  /** Draw text in world space using the image font
1781
- * @param {string|number} text
1787
+ * @param {string|number} text
1782
1788
  * @param {Vector2} pos
1783
- * @param {number} [scale=.25]
1784
- * @param {boolean} [center]
1785
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1789
+ * @param {Vector2|number} [size]
1790
+ * @param {boolean} [center=true]
1791
+ * @param {Color} [color=WHITE]
1792
+ * @param {boolean} [useWebGL=glEnable]
1793
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1786
1794
  */
1787
- drawText(text: string | number, pos: Vector2, scale?: number, center?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1795
+ drawText(text: string | number, pos: Vector2, size?: Vector2 | number, center?: boolean, color?: Color, useWebGL?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1788
1796
  /** Draw text in screen space using the image font
1789
- * @param {string|number} text
1797
+ * @param {string|number} text
1790
1798
  * @param {Vector2} pos
1791
- * @param {number} [scale]
1799
+ * @param {Vector2|number} size
1792
1800
  * @param {boolean} [center]
1793
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1801
+ * @param {Color} [color=WHITE]
1802
+ * @param {boolean} [useWebGL=glEnable]
1803
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1794
1804
  */
1795
- drawTextScreen(text: string | number, pos: Vector2, scale?: number, center?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1805
+ drawTextScreen(text: string | number, pos: Vector2, size: Vector2 | number, center?: boolean, color?: Color, useWebGL?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1796
1806
  }
1797
1807
  /** Returns true if fullscreen mode is active
1798
1808
  * @return {boolean}
@@ -1829,6 +1839,10 @@ declare module "littlejsengine" {
1829
1839
  * @type {WebGL2RenderingContext}
1830
1840
  * @memberof WebGL */
1831
1841
  export let glContext: WebGL2RenderingContext;
1842
+ /** Should WebGL be setup with anti-aliasing? must be set before calling engineInit
1843
+ * @type {boolean}
1844
+ * @memberof WebGL */
1845
+ export let glAntialias: boolean;
1832
1846
  /** Clear the canvas and setup the viewport
1833
1847
  * @memberof WebGL */
1834
1848
  export function glClearCanvas(): void;
@@ -1924,21 +1938,18 @@ declare module "littlejsengine" {
1924
1938
  * @param {Array<number>} pointColors - Array of 32-bit integer colors
1925
1939
  * @memberof WebGL */
1926
1940
  export function glDrawColoredPoints(points: Array<Vector2>, pointColors: Array<number>): void;
1927
- /** Should WebGL be setup with anti-aliasing? must be set before calling engineInit
1928
- * @type {boolean}
1941
+ /** Set the WebGL render target to the given texture or back to the canvas
1942
+ * @param {WebGLTexture} [texture] - a texture or undefined to use normal glCanvas
1943
+ * @param {boolean} [clear] - should the render target be cleared
1929
1944
  * @memberof WebGL */
1930
- export let glAntialias: boolean;
1931
- export let glShader: any;
1932
- export let glPolyShader: any;
1933
- export let glPolyMode: any;
1934
- export let glAdditive: any;
1935
- export let glBatchAdditive: any;
1936
- export let glActiveTexture: any;
1937
- export let glArrayBuffer: any;
1938
- export let glGeometryBuffer: any;
1939
- export let glPositionData: any;
1940
- export let glColorData: any;
1941
- export let glBatchCount: any;
1945
+ export function glSetRenderTarget(texture?: WebGLTexture, clear?: boolean): void;
1946
+ /** Clear out a rectangle area of the WebGL canvas or render target
1947
+ * @param {number} x
1948
+ * @param {number} y
1949
+ * @param {number} width
1950
+ * @param {number} height
1951
+ * @memberof WebGL */
1952
+ export function glClearRect(x: number, y: number, width: number, height: number): void;
1942
1953
  /** Returns true if device key is down
1943
1954
  * @param {string|number} key
1944
1955
  * @param {number} [device]
@@ -2039,6 +2050,9 @@ declare module "littlejsengine" {
2039
2050
  * @type {number}
2040
2051
  * @memberof Input */
2041
2052
  export let gamepadPrimary: number;
2053
+ /** True if a touch device has been detected
2054
+ * @memberof Input */
2055
+ export const isTouchDevice: boolean;
2042
2056
  /** Prevents input continuing to the default browser handling
2043
2057
  * This is useful to disable for html menus so the browser can handle input normally
2044
2058
  * @param {boolean} preventDefault
@@ -2085,9 +2099,6 @@ declare module "littlejsengine" {
2085
2099
  /** Cancel any ongoing vibration
2086
2100
  * @memberof Input */
2087
2101
  export function vibrateStop(): void;
2088
- /** True if a touch device has been detected
2089
- * @memberof Input */
2090
- export const isTouchDevice: boolean;
2091
2102
  /** Request to lock the pointer, does not work on touch devices
2092
2103
  * @memberof Input */
2093
2104
  export function pointerLockRequest(): void;
@@ -2121,24 +2132,38 @@ declare module "littlejsengine" {
2121
2132
  * @memberof Audio */
2122
2133
  export const audioDefaultSampleRate: 44100;
2123
2134
  /**
2124
- * Sound Object - Stores a sound for later use and can be played positionally
2135
+ * Sound Object - Stores a sound for later
2136
+ * - this can be used to load and play wave, mp3, and ogg files
2137
+ * - it can also create sounds using the ZzFX sound generator
2138
+ * - can attenuate and apply stereo panning to sounds
2139
+ * - sound instance control with pause/resume capability
2125
2140
  *
2126
2141
  * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
2127
2142
  * @memberof Audio
2128
2143
  * @example
2129
- * // create a sound
2144
+ * // load an audio asset file
2145
+ * const sound_example = new Sound('sound.mp3');
2146
+ *
2147
+ * // create a zzfx sound
2130
2148
  * const sound_example = new Sound([.5,.5]);
2131
2149
  *
2132
- * // play the sound
2150
+ * // play a sound
2133
2151
  * sound_example.play();
2134
2152
  */
2135
2153
  export class Sound {
2136
- /** Create a sound object and cache the zzfx samples for later use
2137
- * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
2154
+ /**
2155
+ * @callback SoundLoadCallback - Function called when sound is loaded
2156
+ * @param {Sound} sound
2157
+ * @memberof Audio
2158
+ */
2159
+ /** Create a sound object and cache the audio for later use
2160
+ * @param {string|Array} [asset] - Filename of audio file or zzfx array
2161
+ * @param {number} [randomness] - How much to randomize frequency each time sound plays, for zzfx sounds the zzfx default is used if undefined
2138
2162
  * @param {number} [range=soundDefaultRange] - World space max range of sound
2139
2163
  * @param {number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
2164
+ * @param {SoundLoadCallback} [onloadCallback] - callback function to call when sound is loaded
2140
2165
  */
2141
- constructor(zzfxSound: any[], range?: number, taper?: number);
2166
+ constructor(asset?: string | any[], randomness?: number, range?: number, taper?: number, onloadCallback?: (sound: Sound) => Sound);
2142
2167
  /** @property {number} - World space max range of sound */
2143
2168
  range: number;
2144
2169
  /** @property {number} - At what percentage of range should it start tapering */
@@ -2149,6 +2174,8 @@ declare module "littlejsengine" {
2149
2174
  sampleRate: number;
2150
2175
  /** @property {number} - Percentage of this sound currently loaded */
2151
2176
  loadedPercent: number;
2177
+ /** @property {SoundLoadCallback} - function to call when sound is loaded */
2178
+ onloadCallback: (sound: Sound) => Sound;
2152
2179
  sampleChannels: any[][];
2153
2180
  /** Play the sound
2154
2181
  * Sounds may not play until a user interaction occurs
@@ -2165,7 +2192,7 @@ declare module "littlejsengine" {
2165
2192
  * @param {number} [volume] - Volume to play the music at
2166
2193
  * @param {boolean} [loop] - Should the music loop?
2167
2194
  * @param {boolean} [paused] - Should the music start paused
2168
- * @return {SoundInstance} - The audio source node
2195
+ * @return {SoundInstance} - The sound instance
2169
2196
  */
2170
2197
  playMusic(volume?: number, loop?: boolean, paused?: boolean): SoundInstance;
2171
2198
  /** Play the sound as a musical note with a semitone offset
@@ -2173,7 +2200,7 @@ declare module "littlejsengine" {
2173
2200
  * @param {number} [semitoneOffset=0] - How many semitones to offset pitch
2174
2201
  * @param {Vector2} [pos] - World space position to play the sound if any
2175
2202
  * @param {number} [volume=1] - How much to scale volume by
2176
- * @return {SoundInstance} - The audio source node
2203
+ * @return {SoundInstance} - The sound instance
2177
2204
  */
2178
2205
  playNote(semitoneOffset?: number, pos?: Vector2, volume?: number): SoundInstance;
2179
2206
  /** Get how long this sound is in seconds
@@ -2184,36 +2211,7 @@ declare module "littlejsengine" {
2184
2211
  * @return {boolean} - True if sound is loaded and ready to play
2185
2212
  */
2186
2213
  isLoaded(): boolean;
2187
- }
2188
- /**
2189
- * Sound Wave Object - Loads and stores an audio file for later use
2190
- * - this can be used to load and play wave, mp3, and ogg files
2191
- * @extends Sound
2192
- * @memberof Audio
2193
- * @example
2194
- * // load an audio asset file
2195
- * const sound_example = new SoundWave('sound.mp3');
2196
- *
2197
- * // play the sound
2198
- * sound_example.play();
2199
- */
2200
- export class SoundWave extends Sound {
2201
- /**
2202
- * @callback SoundLoadCallback - Function called when sound is loaded
2203
- * @param {SoundWave} sound
2204
- * @memberof Audio
2205
- */
2206
- /** Create a sound object and cache the wave file for later use
2207
- * @param {string} filename - Filename of audio file to load
2208
- * @param {number} [randomness] - How much to randomize frequency each time sound plays
2209
- * @param {number} [range=soundDefaultRange] - World space max range of sound
2210
- * @param {number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
2211
- * @param {SoundLoadCallback} [onloadCallback] - callback function to call when sound is loaded
2212
- */
2213
- constructor(filename: string, randomness?: number, range?: number, taper?: number, onloadCallback?: (sound: SoundWave) => SoundWave);
2214
- /** @property {SoundLoadCallback} - callback function to call when sound is loaded */
2215
- onloadCallback: (sound: SoundWave) => SoundWave;
2216
- /** Loads a sound from a URL and decodes it into sample data. Must be used with await!
2214
+ /** Loads a sound from a URL and decodes it into sample data.
2217
2215
  * @param {string} filename
2218
2216
  * @return {Promise<void>} */
2219
2217
  loadSound(filename: string): Promise<void>;
@@ -2394,10 +2392,10 @@ declare module "littlejsengine" {
2394
2392
  */
2395
2393
  export class EngineObject {
2396
2394
  /** Create an engine object and adds it to the list of objects
2397
- * @param {Vector2} [pos=(0,0)] - World space position of the object
2398
- * @param {Vector2} [size=(1,1)] - World space size of the object
2399
- * @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
2400
- * @param {number} [angle] - Angle the object is rotated by
2395
+ * @param {Vector2} [pos=vec2()] - World space position of the object
2396
+ * @param {Vector2} [size=vec2(1)] - World space size of the object
2397
+ * @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
2398
+ * @param {number} [angle] - Angle the object is rotated by
2401
2399
  * @param {Color} [color=WHITE] - Color to apply to tile when rendered
2402
2400
  * @param {number} [renderOrder] - Objects sorted by renderOrder before being rendered
2403
2401
  */
@@ -2481,14 +2479,14 @@ declare module "littlejsengine" {
2481
2479
  /** Convert from world space to local space for a vector (rotation only)
2482
2480
  * @param {Vector2} vec - world space vector */
2483
2481
  worldToLocalVector(vec: Vector2): Vector2;
2484
- /** Called to check if a tile collision should be resolved
2482
+ /** Called to check if a tile collision should be resolved. Return true for physics to resolve the collision or false to ignore and resolve it manually.
2485
2483
  * @param {number} tileData - the value of the tile at the position
2486
- * @param {Vector2} pos - tile where the collision occurred
2487
- * @return {boolean} - true if the collision should be resolved */
2484
+ * @param {Vector2} pos - tile where the collision occurred
2485
+ * @return {boolean} - true if the collision should be resolved by modifying it's position and velocity */
2488
2486
  collideWithTile(tileData: number, pos: Vector2): boolean;
2489
- /** Called to check if a object collision should be resolved
2487
+ /** Called by the engine to check if an object collision should be resolved. Return true for physics to resolve the collision or false to ignore and resolve it manually.
2490
2488
  * @param {EngineObject} object - the object to test against
2491
- * @return {boolean} - true if the collision should be resolved
2489
+ * @return {boolean} - true if the collision should be resolved by modifying it's position and velocity
2492
2490
  */
2493
2491
  collideWithObject(object: EngineObject): boolean;
2494
2492
  /** Get this object's up vector
@@ -2519,7 +2517,7 @@ declare module "littlejsengine" {
2519
2517
  getMirrorSign(): number;
2520
2518
  /** Attaches a child to this with a local transform, returns child for chaining
2521
2519
  * @param {EngineObject} child
2522
- * @param {Vector2} [localPos=(0,0)]
2520
+ * @param {Vector2} [localPos=vec2()]
2523
2521
  * @param {number} [localAngle]
2524
2522
  * @return {EngineObject} The child object added */
2525
2523
  addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): EngineObject;
@@ -2533,7 +2531,7 @@ declare module "littlejsengine" {
2533
2531
  isOverlappingObject(object: EngineObject): boolean;
2534
2532
  /** Check if overlapping a point or aligned bounding box
2535
2533
  * @param {Vector2} pos - Center of box
2536
- * @param {Vector2} [size=(0,0)] - Size of box, uses a point if undefined
2534
+ * @param {Vector2} [size=vec2()] - Size of box, uses a point if undefined
2537
2535
  * @return {boolean} */
2538
2536
  isOverlapping(pos: Vector2, size?: Vector2): boolean;
2539
2537
  /** Set how this object collides
@@ -2567,7 +2565,7 @@ declare module "littlejsengine" {
2567
2565
  export function tileCollisionGetData(pos: Vector2): number;
2568
2566
  /** Check if a tile layer collides with another object
2569
2567
  * @param {Vector2} pos
2570
- * @param {Vector2} [size=(0,0)]
2568
+ * @param {Vector2} [size=vec2()]
2571
2569
  * @param {EngineObject} [object] - An object or undefined for generic test
2572
2570
  * @param {boolean} [solidOnly] - Only check solid layers if true
2573
2571
  * @return {TileCollisionLayer}
@@ -2606,18 +2604,18 @@ declare module "littlejsengine" {
2606
2604
  */
2607
2605
  export class TileLayerData {
2608
2606
  /** Create a tile layer data object, one for each tile in a TileLayer
2609
- * @param {number} [tile] - The tile to use, untextured if undefined
2607
+ * @param {number} [tile] - The tile to use, untextured if undefined
2610
2608
  * @param {number} [direction] - Integer direction of tile, in 90 degree increments
2611
- * @param {boolean} [mirror] - If the tile should be mirrored along the x axis
2612
- * @param {Color} [color] - Color of the tile */
2609
+ * @param {boolean} [mirror] - If the tile should be mirrored along the x axis
2610
+ * @param {Color} [color] - Color of the tile */
2613
2611
  constructor(tile?: number, direction?: number, mirror?: boolean, color?: Color);
2614
- /** @property {number} - The tile to use, untextured if undefined */
2612
+ /** @property {number} - The tile to use, untextured if undefined */
2615
2613
  tile: number;
2616
- /** @property {number} - Integer direction of tile, in 90 degree increments */
2614
+ /** @property {number} - Integer direction of tile, in 90 degree increments */
2617
2615
  direction: number;
2618
2616
  /** @property {boolean} - If the tile should be mirrored along the x axis */
2619
2617
  mirror: boolean;
2620
- /** @property {Color} - Color of the tile */
2618
+ /** @property {Color} - Color of the tile */
2621
2619
  color: Color;
2622
2620
  /** Set this tile to clear, it will not be rendered */
2623
2621
  clear(): void;
@@ -2625,7 +2623,7 @@ declare module "littlejsengine" {
2625
2623
  /**
2626
2624
  * Canvas Layer - cached off screen rendering system
2627
2625
  * - Contains an offscreen canvas that can be rendered to
2628
- * - WebGL rendering is optional, call useWebGL to enable
2626
+ * - WebGL rendering is optional, call updateWebGL to enable/update
2629
2627
  * @extends EngineObject
2630
2628
  * @memberof TileLayers
2631
2629
  * @example
@@ -2633,20 +2631,20 @@ declare module "littlejsengine" {
2633
2631
  */
2634
2632
  export class CanvasLayer extends EngineObject {
2635
2633
  /** Create a canvas layer object
2636
- * @param {Vector2} [position] - World space position of the layer
2634
+ * @param {Vector2} [pos] - World space position of the layer
2637
2635
  * @param {Vector2} [size] - World space size of the layer
2638
2636
  * @param {number} [angle] - Angle the layer is rotated by
2639
2637
  * @param {number} [renderOrder] - Objects sorted by renderOrder
2640
2638
  * @param {Vector2} [canvasSize] - Default size of canvas, can be changed later
2639
+ * @param {boolean} [useWebGL] - Should this layer use WebGL for rendering
2641
2640
  */
2642
- constructor(position?: Vector2, size?: Vector2, angle?: number, renderOrder?: number, canvasSize?: Vector2);
2641
+ constructor(pos?: Vector2, size?: Vector2, angle?: number, renderOrder?: number, canvasSize?: Vector2, useWebGL?: boolean);
2643
2642
  /** @property {HTMLCanvasElement} - The canvas used by this layer */
2644
2643
  canvas: OffscreenCanvas;
2645
2644
  /** @property {OffscreenCanvasRenderingContext2D} - The 2D canvas context used by this layer */
2646
2645
  context: OffscreenCanvasRenderingContext2D;
2646
+ /** @property {TextureInfo} - Texture info to use for this object rendering */
2647
2647
  textureInfo: TextureInfo;
2648
- /** @property {boolean} - True if WebGL texture needs to be refreshed */
2649
- refreshWebGL: boolean;
2650
2648
  /** Draw this canvas layer centered in world space, with color applied if using WebGL
2651
2649
  * @param {Vector2} pos - Center in world space
2652
2650
  * @param {Vector2} [size] - Size in world space
@@ -2657,38 +2655,26 @@ declare module "littlejsengine" {
2657
2655
  * @param {boolean} [screenSpace] - If true the pos and size are in screen space
2658
2656
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
2659
2657
  * @memberof Draw */
2660
- draw(pos: Vector2, size?: Vector2, angle?: number, color?: Color, mirror?: boolean, additiveColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2661
- /**
2662
- * @callback Canvas2DDrawCallback - Function that draws to a canvas 2D context
2663
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
2664
- * @memberof TileLayers
2665
- */
2666
- /** Draw onto the layer canvas in world space (bypass WebGL)
2667
- * @param {Vector2} pos
2668
- * @param {Vector2} size
2669
- * @param {number} angle
2670
- * @param {boolean} mirror
2671
- * @param {Canvas2DDrawCallback} drawFunction */
2672
- drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: (context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D) => any): void;
2658
+ draw(pos: Vector2, size?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2673
2659
  /** Draw a tile onto the layer canvas in world space
2674
2660
  * @param {Vector2} pos
2675
- * @param {Vector2} [size=(1,1)]
2661
+ * @param {Vector2} [size=vec2(1)]
2676
2662
  * @param {TileInfo} [tileInfo]
2677
- * @param {Color} [color=(1,1,1,1)]
2678
- * @param {number} [angle=0]
2679
- * @param {boolean} [mirror=false] */
2663
+ * @param {Color} [color=WHITE]
2664
+ * @param {number} [angle]
2665
+ * @param {boolean} [mirror] */
2680
2666
  drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
2681
2667
  /** Draw a rectangle onto the layer canvas in world space
2682
2668
  * @param {Vector2} pos
2683
- * @param {Vector2} [size=(1,1)]
2684
- * @param {Color} [color=(1,1,1,1)]
2685
- * @param {number} [angle=0] */
2669
+ * @param {Vector2} [size=vec2(1)]
2670
+ * @param {Color} [color=WHITE]
2671
+ * @param {number} [angle] */
2686
2672
  drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2687
- /** Create or update the WebGL texture for this layer
2688
- * @param {boolean} [enable] - enable WebGL rendering and update the texture
2689
- * @param {boolean} [immediate] - shoulkd the texture be updated immediately
2690
- */
2691
- useWebGL(enable?: boolean, immediate?: boolean): void;
2673
+ /** Create WebGL texture if necessary and copy layer canvas to it */
2674
+ updateWebGL(): void;
2675
+ /** Check if this layer is using WebGL
2676
+ * @return {boolean} */
2677
+ hasWebGL(): boolean;
2692
2678
  }
2693
2679
  /**
2694
2680
  * Tile Layer - cached rendering system for tile layers
@@ -2704,38 +2690,76 @@ declare module "littlejsengine" {
2704
2690
  */
2705
2691
  export class TileLayer extends CanvasLayer {
2706
2692
  /** Create a tile layer object
2707
- * @param {Vector2} position - World space position
2708
- * @param {Vector2} size - World space size
2709
- * @param {TileInfo} [tileInfo] - Default tile info for layer (used for size and texture)
2693
+ * @param {Vector2} pos - World space position
2694
+ * @param {Vector2} size - World space size
2695
+ * @param {TileInfo} [tileInfo] - Default tile info for layer (used for size and texture)
2710
2696
  * @param {number} [renderOrder] - Objects are sorted by renderOrder
2697
+ * @param {boolean} [useWebGL] - Should this layer use WebGL for rendering
2711
2698
  */
2712
- constructor(position: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number);
2699
+ constructor(pos: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number, useWebGL?: boolean);
2700
+ /** @property {Array<TileLayerData>} - Default tile info for layer */
2713
2701
  data: TileLayerData[];
2702
+ /** @property {boolean} - Is this layer using a webgl texture? */
2703
+ isUsingWebGL: boolean;
2714
2704
  /** Draw all the tile data to an offscreen canvas
2715
- * - This may be slow in some browsers but only needs to be done once */
2705
+ * - This may be slow if not using webgl but only needs to be done once */
2716
2706
  redraw(): void;
2717
2707
  /** Call to start the redraw process
2718
- * - This can be used to manually update small parts of the level
2708
+ * - This can be used to manually update parts of the level
2719
2709
  * @param {boolean} [clear] - Should it clear the canvas before drawing */
2720
2710
  redrawStart(clear?: boolean): void;
2721
2711
  /** Call to end the redraw process */
2722
2712
  redrawEnd(): void;
2723
- /** Draw the tile at a given position in the tile grid
2713
+ /** Draw the tile at a given position in the tile layer
2724
2714
  * This can be used to clear out tiles when they are destroyed
2725
2715
  * Tiles can also be redrawn if inside a redrawStart/End block
2726
2716
  * @param {Vector2} layerPos
2727
2717
  * @param {boolean} [clear] - should the old tile be cleared out
2728
2718
  */
2729
2719
  drawTileData(layerPos: Vector2, clear?: boolean): void;
2720
+ /** Draw the tile at a given position in the tile layer
2721
+ * This can be used to clear tiles when they are destroyed
2722
+ * For better performance use drawTileData inside a redrawStart/End block
2723
+ * @param {Vector2} layerPos
2724
+ * @param {boolean} [clear] - should the old tile be cleared
2725
+ */
2726
+ redrawTileData(layerPos: Vector2, clear?: boolean): void;
2727
+ /** Draw textured tile in layer space
2728
+ * @param {Vector2} pos - Position in pixel coordinates
2729
+ * @param {Vector2} [size=vec2(1)] - Size of the tile
2730
+ * @param {TileInfo} [tileInfo] - Tile info to use, untextured if undefined
2731
+ * @param {Color} [color=WHITE] - Color to modulate with
2732
+ * @param {number} [angle] - Angle to rotate by
2733
+ * @param {boolean} [mirror] - Is image flipped along the Y axis?
2734
+ * @param {Color} [additiveColor] - Additive color to be applied if any */
2735
+ drawLayerTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color): void;
2736
+ /** Clear a rectangle in layer space
2737
+ * @param {Vector2} pos
2738
+ * @param {Vector2} size
2739
+ * @param {Color} [color=WHITE] - Color to modulate with
2740
+ * @param {number} [angle] - Angle to rotate by
2741
+ */
2742
+ drawLayerRect(pos: Vector2, size: Vector2, color?: Color, angle?: number): void;
2743
+ /** Clear a rectangle in layer space
2744
+ * @param {Vector2} pos - position in pixel coordinates
2745
+ * @param {Vector2} size
2746
+ */
2747
+ clearLayerRect(pos: Vector2, size: Vector2): void;
2730
2748
  /** Set data at a given position in the array
2731
2749
  * @param {Vector2} layerPos - Local position in array
2732
- * @param {TileLayerData} data - Data to set
2750
+ * @param {TileLayerData} data - Data to set
2733
2751
  * @param {boolean} [redraw] - Force the tile to redraw if true */
2734
2752
  setData(layerPos: Vector2, data: TileLayerData, redraw?: boolean): void;
2753
+ /** Clear data at a given position in the array
2754
+ * @param {Vector2} layerPos - Local position in array
2755
+ * @param {boolean} [redraw] - Force the tile to redraw if true */
2756
+ clearData(layerPos: Vector2, redraw?: boolean): void;
2735
2757
  /** Get data at a given position in the array
2736
2758
  * @param {Vector2} layerPos - Local position in array
2737
2759
  * @return {TileLayerData} */
2738
2760
  getData(layerPos: Vector2): TileLayerData;
2761
+ /** Called after this layer is redrawn, does nothing by default */
2762
+ onRedraw(): void;
2739
2763
  /** @type {[CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D, Vector2, Vector2, number, Color]} */
2740
2764
  savedRenderSettings: [CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, Vector2, Vector2, number, Color];
2741
2765
  }
@@ -2743,7 +2767,6 @@ declare module "littlejsengine" {
2743
2767
  * Tile Collision Layer - a tile layer with collision
2744
2768
  * - adds collision data and functions to TileLayer
2745
2769
  * - there can be multiple tile collision layers
2746
- * - tile collision layers should not overlap each other
2747
2770
  * @extends TileLayer
2748
2771
  * @memberof TileLayers
2749
2772
  */
@@ -2753,17 +2776,20 @@ declare module "littlejsengine" {
2753
2776
  /** Clear and initialize tile collision to new size
2754
2777
  * @param {Vector2} size - width and height of tile collision 2d grid */
2755
2778
  initCollision(size: Vector2): void;
2756
- /** Set tile collision data for a given cell in the grid
2757
- * @param {Vector2} gridPos
2779
+ /** Set tile collision data for a given cell in the layer
2780
+ * @param {Vector2} layerPos
2758
2781
  * @param {number} [data] */
2759
- setCollisionData(gridPos: Vector2, data?: number): void;
2760
- /** Get tile collision data for a given cell in the grid
2761
- * @param {Vector2} gridPos
2782
+ setCollisionData(layerPos: Vector2, data?: number): void;
2783
+ /** Clear tile collision data for a given cell in the layer
2784
+ * @param {Vector2} layerPos */
2785
+ clearCollisionData(layerPos: Vector2): void;
2786
+ /** Get tile collision data for a given cell in the layer
2787
+ * @param {Vector2} layerPos
2762
2788
  * @return {number} */
2763
- getCollisionData(gridPos: Vector2): number;
2789
+ getCollisionData(layerPos: Vector2): number;
2764
2790
  /** Check if collision with another object should occur
2765
2791
  * @param {Vector2} pos
2766
- * @param {Vector2} [size=(0,0)]
2792
+ * @param {Vector2} [size=vec2()]
2767
2793
  * @param {EngineObject} [object]
2768
2794
  * @return {boolean} */
2769
2795
  collisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
@@ -3086,16 +3112,19 @@ declare module "littlejsengine" {
3086
3112
  export class PostProcessPlugin {
3087
3113
  /** Create global post processing shader
3088
3114
  * @param {string} shaderCode
3089
- * @param {boolean} [includeMainCanvas]
3090
- * @example
3091
- * // create the post process plugin object
3092
- * new PostProcessPlugin(shaderCode);
3093
- */
3094
- constructor(shaderCode: string, includeMainCanvas?: boolean);
3115
+ * @param {boolean} [includeMainCanvas] - combine mainCanvs onto glCanvas
3116
+ * @param {boolean} [feedbackTexture] - use glCanvas from previous frame as the texture
3117
+ * @example
3118
+ * // create the post process plugin object
3119
+ * new PostProcessPlugin(shaderCode);
3120
+ */
3121
+ constructor(shaderCode: string, includeMainCanvas?: boolean, feedbackTexture?: boolean);
3095
3122
  /** @property {WebGLProgram} - Shader for post processing */
3096
3123
  shader: any;
3097
3124
  /** @property {WebGLTexture} - Texture for post processing */
3098
3125
  texture: any;
3126
+ /** @property {WebGLVertexArrayObject} - Vertex array object */
3127
+ vao: any;
3099
3128
  }
3100
3129
  /**
3101
3130
  * LittleJS ZzFXM Plugin
@@ -3142,9 +3171,9 @@ declare module "littlejsengine" {
3142
3171
  /** Play the music that loops by default
3143
3172
  * @param {number} [volume] - Volume to play the music at
3144
3173
  * @param {boolean} [loop] - Should the music loop?
3145
- * @return {AudioBufferSourceNode} - The audio source node
3174
+ * @return {SoundInstance} - The sound instance
3146
3175
  */
3147
- playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
3176
+ playMusic(volume?: number, loop?: boolean): SoundInstance;
3148
3177
  }
3149
3178
  /**
3150
3179
  * LittleJS User Interface Plugin
@@ -3171,9 +3200,9 @@ declare module "littlejsengine" {
3171
3200
  export let uiDebug: number;
3172
3201
  /** Enable UI system debug drawing
3173
3202
  * 0=off, 1=normal, 2=show invisible
3174
- * @param {number|boolean} enable
3203
+ * @param {number|boolean} debugMode
3175
3204
  * @memberof UISystem */
3176
- export function uiSetDebug(debugMode: any): void;
3205
+ export function uiSetDebug(debugMode: number | boolean): void;
3177
3206
  /**
3178
3207
  * UI System Global Object
3179
3208
  * @memberof UISystem
@@ -3338,8 +3367,8 @@ declare module "littlejsengine" {
3338
3367
  * @memberof UISystem */
3339
3368
  export class UIObject {
3340
3369
  /** Create a UIObject
3341
- * @param {Vector2} [pos=(0,0)]
3342
- * @param {Vector2} [size=(1,1)]
3370
+ * @param {Vector2} [pos=vec2()]
3371
+ * @param {Vector2} [size=vec2(1)]
3343
3372
  */
3344
3373
  constructor(pos?: Vector2, size?: Vector2);
3345
3374
  /** @property {Vector2} - Local position of the object */
@@ -3350,7 +3379,7 @@ declare module "littlejsengine" {
3350
3379
  size: Vector2;
3351
3380
  /** @property {Color} - Color of the object */
3352
3381
  color: Color;
3353
- /** @property {Color} - Color of the object when active, uses color if undefined */
3382
+ /** @property {Color} - Color of the object when active, uses hoverColor if undefined */
3354
3383
  activeColor: any;
3355
3384
  /** @property {string} - Text for this ui object */
3356
3385
  text: any;
@@ -3575,14 +3604,14 @@ declare module "littlejsengine" {
3575
3604
  */
3576
3605
  export class UIVideo extends UIObject {
3577
3606
  /** Create a video player UI object
3578
- * @param {Vector2} [pos]
3579
- * @param {Vector2} [size]
3607
+ * @param {Vector2} pos
3608
+ * @param {Vector2} size
3580
3609
  * @param {string} src - Video file path or URL
3581
3610
  * @param {boolean} [autoplay=false] - Start playing immediately?
3582
3611
  * @param {boolean} [loop=false] - Loop the video?
3583
3612
  * @param {number} [volume=1] - Volume percent scaled by global volume (0-1)
3584
3613
  */
3585
- constructor(pos?: Vector2, size?: Vector2, src: string, autoplay?: boolean, loop?: boolean, volume?: number);
3614
+ constructor(pos: Vector2, size: Vector2, src: string, autoplay?: boolean, loop?: boolean, volume?: number);
3586
3615
  /** @property {number} - The video volume */
3587
3616
  volume: number;
3588
3617
  /** @property {HTMLVideoElement} - The video player */
@@ -3636,6 +3665,7 @@ declare module "littlejsengine" {
3636
3665
  * - Contact begin and end callbacks
3637
3666
  * - Wraps b2Vec2 type to/from Vector2
3638
3667
  * - Raycasting and querying
3668
+ * - Box2dTileLayer for grid based collision
3639
3669
  * - Every type of joint
3640
3670
  * - Debug physics drawing
3641
3671
  * @namespace Box2D
@@ -3668,8 +3698,11 @@ declare module "littlejsengine" {
3668
3698
  /** Create the global UI system object
3669
3699
  * @param {Object} instance */
3670
3700
  constructor(instance: any);
3701
+ /** @property {Object} - The Box2d instance */
3671
3702
  instance: any;
3703
+ /** @property {Object} - The Box2d world */
3672
3704
  world: any;
3705
+ /** @property {Array<Box2dObject>} - List of all Box2d objects */
3673
3706
  objects: any[];
3674
3707
  /** @property {number} - Velocity iterations per update*/
3675
3708
  velocityIterations: number;
@@ -3719,13 +3752,14 @@ declare module "littlejsengine" {
3719
3752
  * @param {Color} [color]
3720
3753
  * @param {Color} [lineColor]
3721
3754
  * @param {number} [lineWidth]
3755
+ * @param {boolean} [useWebGL=glEnable]
3722
3756
  * @param {CanvasRenderingContext2D} [context] */
3723
- drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3757
+ drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number, useWebgl: any, context?: CanvasRenderingContext2D): void;
3724
3758
  /** converts a box2d vec2 to a Vector2
3725
3759
  * @param {Object} v */
3726
3760
  vec2From(v: any): Vector2;
3727
3761
  /** converts a box2d vec2 pointer to a Vector2
3728
- * @param {Object} v */
3762
+ * @param {Object} vp */
3729
3763
  vec2FromPointer(vp: any): Vector2;
3730
3764
  /** converts a Vector2 to a box2 vec2
3731
3765
  * @param {Vector2} v */
@@ -3755,16 +3789,21 @@ declare module "littlejsengine" {
3755
3789
  * @param {number} [bodyType]
3756
3790
  * @param {number} [renderOrder] */
3757
3791
  constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, bodyType?: number, renderOrder?: number);
3792
+ /** @property {Object} - The Box2d body */
3758
3793
  body: any;
3794
+ /** @property {Color} - Line color used for default box2d drawing */
3759
3795
  lineColor: Color;
3796
+ /** @property {Array<Object>} - List of all edges for default box2d drawing */
3760
3797
  edgeLists: any[];
3798
+ /** @property {Array<Object>} - List of all edge loops for default box2d drawing */
3761
3799
  edgeLoops: any[];
3762
3800
  /** Draws all this object's fixtures
3763
- * @param {Color} [color]
3764
- * @param {Color} [lineColor]
3765
- * @param {number} [lineWidth]
3801
+ * @param {Color} [color]
3802
+ * @param {Color} [lineColor]
3803
+ * @param {number} [lineWidth]
3804
+ * @param {boolean} [useWebGL=glEnable]
3766
3805
  * @param {CanvasRenderingContext2D} [context] */
3767
- drawFixtures(color?: Color, lineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3806
+ drawFixtures(color?: Color, lineColor?: Color, lineWidth?: number, useWebGL?: boolean, context?: CanvasRenderingContext2D): void;
3768
3807
  /** Called when a contact begins
3769
3808
  * @param {Box2dObject} otherObject */
3770
3809
  beginContact(otherObject: Box2dObject): void;
@@ -3839,6 +3878,11 @@ declare module "littlejsengine" {
3839
3878
  * @param {number} [restitution]
3840
3879
  * @param {boolean} [isSensor] */
3841
3880
  addEdgeLoop(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
3881
+ /** Destroy a fixture from the body
3882
+ * @param {Object} [fixture] */
3883
+ destroyFixture(fixture?: any): void;
3884
+ /** Destroy all fixture from the body */
3885
+ destroyAllFixtures(): void;
3842
3886
  /** Gets the center of mass
3843
3887
  * @return {Vector2} */
3844
3888
  getCenterOfMass(): Vector2;
@@ -4011,6 +4055,7 @@ declare module "littlejsengine" {
4011
4055
  /** Create a box2d joint, the base class is not intended to be used directly
4012
4056
  * @param {Object} jointDef */
4013
4057
  constructor(jointDef: any);
4058
+ /** @property {Object} - The Box2d joint */
4014
4059
  box2dJoint: any;
4015
4060
  /** Destroy this joint */
4016
4061
  destroy(): void;
@@ -4241,8 +4286,8 @@ declare module "littlejsengine" {
4241
4286
  * @param {Box2dObject} objectB
4242
4287
  * @param {Box2dJoint} joint1
4243
4288
  * @param {Box2dJoint} joint2
4244
- * @param {ratio} [ratio] */
4245
- constructor(objectA: Box2dObject, objectB: Box2dObject, joint1: Box2dJoint, joint2: Box2dJoint, ratio?: ratio);
4289
+ * @param {number} [ratio] */
4290
+ constructor(objectA: Box2dObject, objectB: Box2dObject, joint1: Box2dJoint, joint2: Box2dJoint, ratio?: number);
4246
4291
  joint1: Box2dJoint;
4247
4292
  joint2: Box2dJoint;
4248
4293
  /** Get the first joint