littlejsengine 1.15.9 → 1.16.1

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 (48) hide show
  1. package/dist/littlejs.d.ts +66 -83
  2. package/dist/littlejs.esm.js +318 -330
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +306 -319
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +229 -242
  7. package/examples/box2d/game.js +1 -1
  8. package/examples/breakout/game.js +3 -3
  9. package/examples/electron/game.js +1 -2
  10. package/examples/electron/index.html +2 -2
  11. package/examples/htmlMenu/game.js +0 -1
  12. package/examples/index.html +1 -1
  13. package/examples/module/game.js +1 -2
  14. package/examples/particles/index.html +1 -1
  15. package/examples/platformer/game.js +4 -4
  16. package/examples/puzzle/game.js +2 -2
  17. package/examples/shorts/base.html +3 -3
  18. package/examples/shorts/box2dPool.js +2 -2
  19. package/examples/shorts/empty.js +1 -1
  20. package/examples/shorts/{systemFont.js → fontImage.js} +3 -3
  21. package/examples/shorts/fps.js +1 -1
  22. package/examples/shorts/helloWorld.js +2 -2
  23. package/examples/shorts/nineSlice.js +2 -2
  24. package/examples/shorts/slidingPuzzle.js +1 -1
  25. package/examples/starter/game.js +1 -2
  26. package/examples/starter/index.html +2 -2
  27. package/examples/stress/index.html +1 -1
  28. package/examples/typescript/game.js +1 -2
  29. package/examples/typescript/game.ts +1 -2
  30. package/package.json +1 -1
  31. package/plugins/box2d.js +8 -8
  32. package/plugins/drawUtilities.js +6 -6
  33. package/plugins/postProcess.js +13 -20
  34. package/plugins/uiSystem.js +15 -3
  35. package/reference.md +4 -6
  36. package/src/engine.js +35 -37
  37. package/src/engineAudio.js +3 -3
  38. package/src/engineDebug.js +78 -78
  39. package/src/engineDraw.js +107 -109
  40. package/src/engineExport.js +12 -11
  41. package/src/engineInput.js +1 -1
  42. package/src/engineMedals.js +3 -3
  43. package/src/engineObject.js +4 -2
  44. package/src/engineRelease.js +1 -1
  45. package/src/engineSettings.js +20 -30
  46. package/src/engineTileLayer.js +5 -4
  47. package/src/engineUtilities.js +2 -10
  48. package/src/engineWebGL.js +6 -5
@@ -199,7 +199,7 @@ declare module "littlejsengine" {
199
199
  * @type {boolean}
200
200
  * @default
201
201
  * @memberof Debug */
202
- export let showWatermark: boolean;
202
+ export let debugWatermark: boolean;
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
@@ -373,13 +373,6 @@ declare module "littlejsengine" {
373
373
  * @default
374
374
  * @memberof Settings */
375
375
  export let canvasPixelated: boolean;
376
- /** Use nearest canvas scaling for more pixelated look
377
- * - If enabled sets css image-rendering:pixelated
378
- * - This defaults to false because text looks better with smoothing
379
- * @type {boolean}
380
- * @default
381
- * @memberof Settings */
382
- export let overlayCanvasPixelated: boolean;
383
376
  /** Disables texture filtering for crisper pixel art
384
377
  * @type {boolean}
385
378
  * @default
@@ -404,12 +397,17 @@ declare module "littlejsengine" {
404
397
  * @type {Vector2}
405
398
  * @default Vector2(16,16)
406
399
  * @memberof Settings */
407
- export let tileSizeDefault: Vector2;
408
- /** How many pixels smaller to draw tiles to prevent bleeding from neighbors
400
+ export let tileDefaultSize: Vector2;
401
+ /** Default padding pixels around tiles
409
402
  * @type {number}
410
403
  * @default
411
404
  * @memberof Settings */
412
- export let tileFixBleedScale: number;
405
+ export let tileDefaultPadding: number;
406
+ /** Default amount of pixels smaller to draw tiles to prevent neighbor bleeding
407
+ * @type {number}
408
+ * @default
409
+ * @memberof Settings */
410
+ export let tileDefaultBleed: number;
413
411
  /** Enable physics solver for collisions between objects
414
412
  * @type {boolean}
415
413
  * @default
@@ -583,16 +581,9 @@ declare module "littlejsengine" {
583
581
  * @memberof Settings */
584
582
  export function setCanvasFixedSize(size: Vector2): void;
585
583
  /** Use nearest scaling algorithm for canvas for more pixelated look
586
- * - If enabled sets css image-rendering:pixelated
587
584
  * @param {boolean} pixelated
588
585
  * @memberof Settings */
589
586
  export function setCanvasPixelated(pixelated: boolean): void;
590
- /** Use nearest scaling algorithm for canvas for more pixelated look
591
- * - If enabled sets css image-rendering:pixelated
592
- * - This defaults to false because text looks better with smoothing
593
- * @param {boolean} pixelated
594
- * @memberof Settings */
595
- export function setOverlayCanvasPixelated(pixelated: boolean): void;
596
587
  /** Disables texture filtering for crisper pixel art
597
588
  * @param {boolean} pixelated
598
589
  * @memberof Settings */
@@ -616,11 +607,15 @@ declare module "littlejsengine" {
616
607
  /** Set default size of tiles in pixels
617
608
  * @param {Vector2} size
618
609
  * @memberof Settings */
619
- export function setTileSizeDefault(size: Vector2): void;
620
- /** Set to prevent tile bleeding from neighbors in pixels
621
- * @param {number} scale
610
+ export function setTileDefaultSize(size: Vector2): void;
611
+ /** Default padding pixels around tiles
612
+ * @param {number} padding
613
+ * @memberof Settings */
614
+ export function setTileDefaultPadding(padding: number): void;
615
+ /** Default amount of pixels smaller to draw tiles to prevent neighbor bleeding
616
+ * @param {number} bleed
622
617
  * @memberof Settings */
623
- export function setTileFixBleedScale(scale: number): void;
618
+ export function setTileDefaultBleed(bleed: number): void;
624
619
  /** Set if collisions between objects are enabled
625
620
  * @param {boolean} enable
626
621
  * @memberof Settings */
@@ -737,7 +732,7 @@ declare module "littlejsengine" {
737
732
  /** Set if watermark with FPS should be shown
738
733
  * @param {boolean} show
739
734
  * @memberof Debug */
740
- export function setShowWatermark(show: boolean): void;
735
+ export function setDebugWatermark(show: boolean): void;
741
736
  /** Set key code used to toggle debug mode, Esc by default
742
737
  * @param {string} key
743
738
  * @memberof Debug */
@@ -1432,7 +1427,7 @@ declare module "littlejsengine" {
1432
1427
  * - This can take vecs or floats for easier use and conversion
1433
1428
  * - If an index is passed in, the tile size and index will determine the position
1434
1429
  * @param {Vector2|number} [pos=0] - Position of the tile in pixels, or tile index
1435
- * @param {Vector2|number} [size=tileSizeDefault] - Size of tile in pixels
1430
+ * @param {Vector2|number} [size] - Size of tile in pixels
1436
1431
  * @param {number} [textureIndex] - Texture index to use
1437
1432
  * @param {number} [padding] - How many pixels padding around tiles
1438
1433
  * @return {TileInfo}
@@ -1449,13 +1444,13 @@ declare module "littlejsengine" {
1449
1444
  */
1450
1445
  export class TileInfo {
1451
1446
  /** Create a tile info object
1452
- * @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
1453
- * @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
1454
- * @param {number} [textureIndex] - Texture index to use
1455
- * @param {number} [padding] - How many pixels padding around tiles
1456
- * @param {number} [bleedScale] - How many pixels smaller to draw tiles
1447
+ * @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
1448
+ * @param {Vector2} [size] - Size of tile in pixels
1449
+ * @param {number} [textureIndex] - Texture index to use
1450
+ * @param {number} [padding] - How many pixels padding around tiles
1451
+ * @param {number} [bleed] - How many pixels smaller to draw tiles
1457
1452
  */
1458
- constructor(pos?: Vector2, size?: Vector2, textureIndex?: number, padding?: number, bleedScale?: number);
1453
+ constructor(pos?: Vector2, size?: Vector2, textureIndex?: number, padding?: number, bleed?: number);
1459
1454
  /** @property {Vector2} - Top left corner of tile in pixels */
1460
1455
  pos: Vector2;
1461
1456
  /** @property {Vector2} - Size of tile in pixels */
@@ -1467,7 +1462,7 @@ declare module "littlejsengine" {
1467
1462
  /** @property {TextureInfo} - The texture info for this tile */
1468
1463
  textureInfo: TextureInfo;
1469
1464
  /** @property {number} - Shrinks tile by this many pixels to prevent neighbors bleeding */
1470
- bleedScale: number;
1465
+ bleed: number;
1471
1466
  /** Returns a copy of this tile offset by a vector
1472
1467
  * @param {Vector2} offset - Offset to apply in pixels
1473
1468
  * @return {TileInfo}
@@ -1524,7 +1519,6 @@ declare module "littlejsengine" {
1524
1519
  * There are 3 canvas/contexts available to draw to...
1525
1520
  * mainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.
1526
1521
  * glCanvas - Used by the accelerated WebGL batch rendering system.
1527
- * overlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.
1528
1522
  *
1529
1523
  * The WebGL rendering system is very fast with some caveats...
1530
1524
  * - Switching blend modes (additive) or textures causes another draw call which is expensive in excess
@@ -1549,14 +1543,22 @@ declare module "littlejsengine" {
1549
1543
  * @type {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D}
1550
1544
  * @memberof Draw */
1551
1545
  export let drawContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
1552
- /** A canvas that appears on top of everything the same size as mainCanvas
1553
- * @type {HTMLCanvasElement}
1546
+ /** Offscreen canvas that can be used for image processing
1547
+ * @type {OffscreenCanvas}
1554
1548
  * @memberof Draw */
1555
- export let overlayCanvas: HTMLCanvasElement;
1556
- /** 2d context for overlayCanvas
1557
- * @type {CanvasRenderingContext2D}
1549
+ export let workCanvas: OffscreenCanvas;
1550
+ /** Offscreen canvas that can be used for image processing
1551
+ * @type {OffscreenCanvasRenderingContext2D}
1552
+ * @memberof Draw */
1553
+ export let workContext: OffscreenCanvasRenderingContext2D;
1554
+ /** Offscreen canvas with willReadFrequently that can be used for image processing
1555
+ * @type {OffscreenCanvas}
1558
1556
  * @memberof Draw */
1559
- export let overlayContext: CanvasRenderingContext2D;
1557
+ export let workReadCanvas: OffscreenCanvas;
1558
+ /** Offscreen canvas with willReadFrequently that can be used for image processing
1559
+ * @type {OffscreenCanvasRenderingContext2D}
1560
+ * @memberof Draw */
1561
+ export let workReadContext: OffscreenCanvasRenderingContext2D;
1560
1562
  /** The size of the main canvas (and other secondary canvases)
1561
1563
  * @type {Vector2}
1562
1564
  * @memberof Draw */
@@ -1713,22 +1715,7 @@ declare module "littlejsengine" {
1713
1715
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1714
1716
  * @memberof Draw */
1715
1717
  export function drawText(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;
1716
- /** Draw text on overlay canvas in world space
1717
- * Automatically splits new lines into rows
1718
- * @param {string|number} text
1719
- * @param {Vector2} pos
1720
- * @param {number} [size]
1721
- * @param {Color} [color=(1,1,1,1)]
1722
- * @param {number} [lineWidth]
1723
- * @param {Color} [lineColor=(0,0,0,1)]
1724
- * @param {CanvasTextAlign} [textAlign='center']
1725
- * @param {string} [font=fontDefault]
1726
- * @param {string} [fontStyle]
1727
- * @param {number} [maxWidth]
1728
- * @param {number} [angle]
1729
- * @memberof Draw */
1730
- export function drawTextOverlay(text: string | number, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number): void;
1731
- /** Draw text on overlay canvas in screen space
1718
+ /** Draw text in screen space
1732
1719
  * Automatically splits new lines into rows
1733
1720
  * @param {string|number} text
1734
1721
  * @param {Vector2} pos
@@ -1741,7 +1728,7 @@ declare module "littlejsengine" {
1741
1728
  * @param {string} [fontStyle]
1742
1729
  * @param {number} [maxWidth]
1743
1730
  * @param {number} [angle]
1744
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
1731
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
1745
1732
  * @memberof Draw */
1746
1733
  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
1734
  /** Enable normal or additive blend mode
@@ -1749,8 +1736,8 @@ declare module "littlejsengine" {
1749
1736
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1750
1737
  * @memberof Draw */
1751
1738
  export function setBlendMode(additive?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1752
- /** Combines all LittleJS canvases onto the main canvas and clears them
1753
- * This is necessary for things like saving a screenshot
1739
+ /** Combines LittleJS canvases onto the main canvas
1740
+ * This is necessary for things like screenshots and video
1754
1741
  * @memberof Draw */
1755
1742
  export function combineCanvases(): void;
1756
1743
  export let engineFontImage: any;
@@ -1785,14 +1772,7 @@ declare module "littlejsengine" {
1785
1772
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1786
1773
  */
1787
1774
  drawText(text: string | number, pos: Vector2, scale?: number, center?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1788
- /** Draw text on overlay canvas in world space using the image font
1789
- * @param {string|number} text
1790
- * @param {Vector2} pos
1791
- * @param {number} [scale]
1792
- * @param {boolean} [center]
1793
- */
1794
- drawTextOverlay(text: string | number, pos: Vector2, scale?: number, center?: boolean): void;
1795
- /** Draw text on overlay canvas in screen space using the image font
1775
+ /** Draw text in screen space using the image font
1796
1776
  * @param {string|number} text
1797
1777
  * @param {Vector2} pos
1798
1778
  * @param {number} [scale]
@@ -1828,7 +1808,7 @@ declare module "littlejsengine" {
1828
1808
  * - Supports shadertoy style post processing shaders via plugin
1829
1809
  * @namespace WebGL
1830
1810
  */
1831
- /** The WebGL canvas which appears above the main canvas and below the overlay canvas
1811
+ /** The WebGL canvas which appears below the main canvas
1832
1812
  * @type {HTMLCanvasElement}
1833
1813
  * @memberof WebGL */
1834
1814
  export let glCanvas: HTMLCanvasElement;
@@ -2193,12 +2173,12 @@ declare module "littlejsengine" {
2193
2173
  isLoaded(): boolean;
2194
2174
  }
2195
2175
  /**
2196
- * Sound Wave Object - Stores a wave sound for later use and can be played positionally
2197
- * - this can be used to play wave, mp3, and ogg files
2176
+ * Sound Wave Object - Loads and stores an audio file for later use
2177
+ * - this can be used to load and play wave, mp3, and ogg files
2198
2178
  * @extends Sound
2199
2179
  * @memberof Audio
2200
2180
  * @example
2201
- * // create a sound
2181
+ * // load an audio asset file
2202
2182
  * const sound_example = new SoundWave('sound.mp3');
2203
2183
  *
2204
2184
  * // play the sound
@@ -2524,11 +2504,12 @@ declare module "littlejsengine" {
2524
2504
  /** Get the direction of the mirror
2525
2505
  * @return {number} -1 if this.mirror is true, or 1 if not mirrored */
2526
2506
  getMirrorSign(): number;
2527
- /** Attaches a child to this with a given local transform
2507
+ /** Attaches a child to this with a local transform, returns child for chaining
2528
2508
  * @param {EngineObject} child
2529
2509
  * @param {Vector2} [localPos=(0,0)]
2530
- * @param {number} [localAngle] */
2531
- addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): void;
2510
+ * @param {number} [localAngle]
2511
+ * @return {EngineObject} The child object added */
2512
+ addChild(child: EngineObject, localPos?: Vector2, localAngle?: number): EngineObject;
2532
2513
  /** Removes a child from this one
2533
2514
  * @param {EngineObject} child */
2534
2515
  removeChild(child: EngineObject): void;
@@ -2742,8 +2723,8 @@ declare module "littlejsengine" {
2742
2723
  * @param {Vector2} layerPos - Local position in array
2743
2724
  * @return {TileLayerData} */
2744
2725
  getData(layerPos: Vector2): TileLayerData;
2745
- /** @type {[HTMLCanvasElement|OffscreenCanvas, CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D, Vector2, Vector2, number]} */
2746
- savedRenderSettings: [HTMLCanvasElement | OffscreenCanvas, CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, Vector2, Vector2, number];
2726
+ /** @type {[HTMLCanvasElement|OffscreenCanvas, CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D, Vector2, Vector2, number, Color]} */
2727
+ savedRenderSettings: [HTMLCanvasElement | OffscreenCanvas, CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, Vector2, Vector2, number, Color];
2747
2728
  }
2748
2729
  /**
2749
2730
  * Tile Collision Layer - a tile layer with collision
@@ -3092,13 +3073,12 @@ declare module "littlejsengine" {
3092
3073
  export class PostProcessPlugin {
3093
3074
  /** Create global post processing shader
3094
3075
  * @param {string} shaderCode
3095
- * @param {boolean} [includeOverlay]
3096
3076
  * @param {boolean} [includeMainCanvas]
3097
3077
  * @example
3098
3078
  * // create the post process plugin object
3099
3079
  * new PostProcessPlugin(shaderCode);
3100
3080
  */
3101
- constructor(shaderCode: string, includeOverlay?: boolean, includeMainCanvas?: boolean);
3081
+ constructor(shaderCode: string, includeMainCanvas?: boolean);
3102
3082
  /** @property {WebGLProgram} - Shader for post processing */
3103
3083
  shader: any;
3104
3084
  /** @property {WebGLTexture} - Texture for post processing */
@@ -3193,6 +3173,8 @@ declare module "littlejsengine" {
3193
3173
  * new UISystemPlugin;
3194
3174
  */
3195
3175
  constructor(context?: CanvasRenderingContext2D);
3176
+ /** @property {boolean} - Activate when mouse is pressed down instead of clicked */
3177
+ activateOnPress: boolean;
3196
3178
  /** @property {Color} - Default fill color for UI elements */
3197
3179
  defaultColor: Color;
3198
3180
  /** @property {Color} - Default outline color for UI elements */
@@ -3421,9 +3403,10 @@ declare module "littlejsengine" {
3421
3403
  navigationIndex: any;
3422
3404
  /** @property {boolean} - Should this be auto selected by navigation? Must also have valid navigation index. */
3423
3405
  navigationAutoSelect: boolean;
3424
- /** Add a child UIObject to this object
3425
- * @param {UIObject} child */
3426
- addChild(child: UIObject): void;
3406
+ /** Add a child UIObject to this object, returns child for chaining
3407
+ * @param {UIObject} child
3408
+ * @return {UIObject} The child object added */
3409
+ addChild(child: UIObject): UIObject;
3427
3410
  /** Remove a child UIObject from this object
3428
3411
  * @param {UIObject} child */
3429
3412
  removeChild(child: UIObject): void;
@@ -4575,8 +4558,8 @@ declare module "littlejsengine" {
4575
4558
  * - Nine slice and three slice drawing
4576
4559
  * @namespace DrawUtilities
4577
4560
  */
4578
- /** Draw a scalable nine-slice UI element to the overlay canvas in screen space
4579
- * This function can not apply color because it draws using the overlay 2d context
4561
+ /** Draw a scalable nine-slice UI element to the main canvas in screen space
4562
+ * This function can not apply color because it draws using the 2d context
4580
4563
  * @param {Vector2} pos - Screen space position
4581
4564
  * @param {Vector2} size - Screen space size
4582
4565
  * @param {TileInfo} startTile - Starting tile for the nine-slice pattern
@@ -4600,8 +4583,8 @@ declare module "littlejsengine" {
4600
4583
  * @param {CanvasRenderingContext2D} [context] - Canvas context to use
4601
4584
  * @memberof DrawUtilities */
4602
4585
  export function drawThreeSlice(pos: Vector2, size: Vector2, startTile: TileInfo, color?: Color, borderSize?: number, additiveColor?: Color, extraSpace?: number, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
4603
- /** Draw a scalable three-slice UI element to the overlay canvas in screen space
4604
- * This function can not apply color because it draws using the overlay 2d context
4586
+ /** Draw a scalable three-slice UI element to the main canvas in screen space
4587
+ * This function can not apply color because it draws using the 2d context
4605
4588
  * @param {Vector2} pos - Screen space position
4606
4589
  * @param {Vector2} size - Screen space size
4607
4590
  * @param {TileInfo} startTile - Starting tile for the three-slice pattern