littlejsengine 1.13.4 → 1.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +2 -1
  2. package/copyToGithub.bat +28 -0
  3. package/dist/littlejs.d.ts +346 -240
  4. package/dist/littlejs.esm.js +1370 -723
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +1350 -709
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +1333 -692
  9. package/examples/box2d/game.js +1 -1
  10. package/examples/box2d/gameObjects.js +1 -1
  11. package/examples/breakout/game.js +30 -25
  12. package/examples/electron/index.html +2 -2
  13. package/examples/index.html +207 -96
  14. package/examples/platformer/gameEffects.js +19 -18
  15. package/examples/platformer/gameLevel.js +6 -1
  16. package/examples/shorts/base.html +1 -1
  17. package/examples/shorts/flappyGame.js +2 -1
  18. package/examples/shorts/helloWorld.js +1 -1
  19. package/examples/shorts/music.js +106 -0
  20. package/examples/shorts/parallax.js +71 -0
  21. package/examples/shorts/piano.js +7 -8
  22. package/examples/shorts/postProcess.js +25 -8
  23. package/examples/shorts/shapes.js +1 -9
  24. package/examples/shorts/song.mp3 +0 -0
  25. package/examples/shorts/uiSystem.js +15 -8
  26. package/examples/starter/index.html +2 -2
  27. package/examples/stress/index.html +8 -3
  28. package/examples/style.css +14 -4
  29. package/examples/uiSystem/game.js +11 -11
  30. package/package.json +1 -1
  31. package/plugins/box2d.js +10 -8
  32. package/plugins/drawUtilities.js +5 -5
  33. package/plugins/newgrounds.js +6 -6
  34. package/plugins/pluginExport.js +1 -1
  35. package/plugins/uiSystem.js +103 -79
  36. package/plugins/zzfxm.js +10 -10
  37. package/reference.md +90 -54
  38. package/src/engine.js +22 -22
  39. package/src/engineAudio.js +284 -109
  40. package/src/engineBuild.js +9 -9
  41. package/src/engineDebug.js +26 -26
  42. package/src/engineDraw.js +148 -97
  43. package/src/engineExport.js +22 -16
  44. package/src/engineInput.js +57 -67
  45. package/src/engineMedals.js +25 -25
  46. package/src/engineObject.js +25 -22
  47. package/src/engineParticles.js +59 -59
  48. package/src/engineRelease.js +1 -1
  49. package/src/engineSettings.js +20 -13
  50. package/src/engineTileLayer.js +34 -34
  51. package/src/engineUtilities.js +62 -55
  52. package/src/engineWebGL.js +447 -65
  53. /package/examples/shorts/{playSound.js → sound.js} +0 -0
@@ -79,7 +79,7 @@ declare module "littlejsengine" {
79
79
  * // Basic engine startup
80
80
  * engineInit(
81
81
  * () => { console.log('Game initialized!'); }, // gameInit
82
- * () => { updatePlayer(); }, // gameUpdate
82
+ * () => { updateGameLogic(); }, // gameUpdate
83
83
  * () => { updateUI(); }, // gameUpdatePost
84
84
  * () => { drawBackground(); }, // gameRender
85
85
  * () => { drawHUD(); }, // gameRenderPost
@@ -263,7 +263,7 @@ declare module "littlejsengine" {
263
263
  * @memberof Settings */
264
264
  export let cameraScale: number;
265
265
  /** Enable applying color to tiles when using canvas2d
266
- * - This is slower but should be the same as webgl rendering
266
+ * - This is slower but should be the same as WebGL rendering
267
267
  * @type {boolean}
268
268
  * @default
269
269
  * @memberof Settings */
@@ -302,13 +302,12 @@ declare module "littlejsengine" {
302
302
  * @default
303
303
  * @memberof Settings */
304
304
  export let fontDefault: string;
305
- /** Enable to show the LittleJS splash screen be shown on startup
305
+ /** Enable to show the LittleJS splash screen on startup
306
306
  * @type {boolean}
307
307
  * @default
308
308
  * @memberof Settings */
309
309
  export let showSplashScreen: boolean;
310
310
  /** Disables all rendering, audio, and input for servers
311
- * - Must be set before startup to take effect
312
311
  * @type {boolean}
313
312
  * @default
314
313
  * @memberof Settings */
@@ -368,8 +367,7 @@ declare module "littlejsengine" {
368
367
  * @default
369
368
  * @memberof Settings */
370
369
  export let particleEmitRateScale: number;
371
- /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
372
- * - Must be set before startup to take effect
370
+ /** Enable WebGL accelerated rendering
373
371
  * @type {boolean}
374
372
  * @default
375
373
  * @memberof Settings */
@@ -379,19 +377,18 @@ declare module "littlejsengine" {
379
377
  * @default
380
378
  * @memberof Settings */
381
379
  export let gamepadsEnable: boolean;
382
- /** If true, the dpad input is also routed to the left analog stick (for better accessability)
380
+ /** If true, the dpad input is also routed to the left analog stick (for better accessibility)
383
381
  * @type {boolean}
384
382
  * @default
385
383
  * @memberof Settings */
386
384
  export let gamepadDirectionEmulateStick: boolean;
387
- /** If true the WASD keys are also routed to the direction keys (for better accessability)
385
+ /** If true the WASD keys are also routed to the direction keys (for better accessibility)
388
386
  * @type {boolean}
389
387
  * @default
390
388
  * @memberof Settings */
391
389
  export let inputWASDEmulateDirection: boolean;
392
390
  /** True if touch gamepad should appear on mobile devices
393
391
  * - Supports left analog stick, 4 face buttons and start button (button 9)
394
- * - Must be set before startup to take effect
395
392
  * @type {boolean}
396
393
  * @default
397
394
  * @memberof Settings */
@@ -464,7 +461,7 @@ declare module "littlejsengine" {
464
461
  * @memberof Settings */
465
462
  export function setCameraScale(scale: number): void;
466
463
  /** Set if tiles should be colorized when using canvas2d
467
- * This can be slower but results should look nearly identical to webgl rendering
464
+ * This can be slower but results should look nearly identical to WebGL rendering
468
465
  * It can be enabled/disabled at any time
469
466
  * Optimized for performance, and will use faster method if color is white or untextured
470
467
  * @param {boolean} colorTiles
@@ -497,7 +494,7 @@ declare module "littlejsengine" {
497
494
  * @param {string} font
498
495
  * @memberof Settings */
499
496
  export function setFontDefault(font: string): void;
500
- /** Set if the LittleJS splash screen be shown on startup
497
+ /** Set if the LittleJS splash screen should be shown on startup
501
498
  * @param {boolean} show
502
499
  * @memberof Settings */
503
500
  export function setShowSplashScreen(show: boolean): void;
@@ -505,7 +502,7 @@ declare module "littlejsengine" {
505
502
  * @param {boolean} headless
506
503
  * @memberof Settings */
507
504
  export function setHeadlessMode(headless: boolean): void;
508
- /** Set if webgl rendering is enabled
505
+ /** Set if WebGL rendering is enabled
509
506
  * @param {boolean} enable
510
507
  * @memberof Settings */
511
508
  export function setGLEnable(enable: boolean): void;
@@ -533,7 +530,7 @@ declare module "littlejsengine" {
533
530
  * @param {number} damp
534
531
  * @memberof Settings */
535
532
  export function setObjectDefaultAngleDamping(damp: number): void;
536
- /** Set how much to bounce when a collision occur
533
+ /** Set how much to bounce when a collision occurs
537
534
  * @param {number} restitution
538
535
  * @memberof Settings */
539
536
  export function setObjectDefaultRestitution(restitution: number): void;
@@ -723,7 +720,7 @@ declare module "littlejsengine" {
723
720
  * @return {number}
724
721
  * @memberof Utilities */
725
722
  export function smoothStep(percent: number): number;
726
- /** Returns the nearest power of two not less then the value
723
+ /** Returns the nearest power of two not less than the value
727
724
  * @param {number} value
728
725
  * @return {number}
729
726
  * @memberof Utilities */
@@ -1124,8 +1121,7 @@ declare module "littlejsengine" {
1124
1121
  * let a = vec2(0, 1); // vector with coordinates (0, 1)
1125
1122
  * a = vec2(5); // set a to (5, 5)
1126
1123
  * b = vec2(); // set b to (0, 0)
1127
- * @memberof Utilities
1128
- */
1124
+ * @memberof Utilities */
1129
1125
  export function vec2(x?: number, y?: number): Vector2;
1130
1126
  /**
1131
1127
  * Create a color object with RGBA values, white by default
@@ -1144,29 +1140,25 @@ declare module "littlejsengine" {
1144
1140
  * @param {number} [l=1] - lightness
1145
1141
  * @param {number} [a=1] - alpha
1146
1142
  * @return {Color}
1147
- * @memberof Utilities
1148
- */
1143
+ * @memberof Utilities */
1149
1144
  export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
1150
1145
  /**
1151
1146
  * Check if object is a valid Color
1152
1147
  * @param {any} c
1153
1148
  * @return {boolean}
1154
- * @memberof Utilities
1155
- */
1149
+ * @memberof Utilities */
1156
1150
  export function isColor(c: any): boolean;
1157
1151
  /**
1158
1152
  * Check if object is a valid Vector2
1159
1153
  * @param {any} v
1160
1154
  * @return {boolean}
1161
- * @memberof Utilities
1162
- */
1155
+ * @memberof Utilities */
1163
1156
  export function isVector2(v: any): boolean;
1164
1157
  /**
1165
1158
  * Check if object is a valid number, not NaN or undefined, but it may be infinite
1166
1159
  * @param {any} n
1167
1160
  * @return {boolean}
1168
- * @memberof Utilities
1169
- */
1161
+ * @memberof Utilities */
1170
1162
  export function isNumber(n: any): boolean;
1171
1163
  /** Color - White #ffffff
1172
1164
  * @type {Color}
@@ -1238,8 +1230,7 @@ declare module "littlejsengine" {
1238
1230
  * tile(5, 8) // a tile at index 5 using a tile size of 8
1239
1231
  * tile(1, 16, 3) // a tile at index 1 of size 16 on texture 3
1240
1232
  * tile(vec2(4,8), vec2(30,10)) // a tile at index (4,8) with a size of (30,10)
1241
- * @memberof Draw
1242
- */
1233
+ * @memberof Draw */
1243
1234
  export function tile(pos?: Vector2 | number, size?: Vector2 | number, textureIndex?: number, padding?: number): TileInfo;
1244
1235
  /**
1245
1236
  * Tile Info - Stores info about how to draw a tile
@@ -1275,7 +1266,7 @@ declare module "littlejsengine" {
1275
1266
  /**
1276
1267
  * Set this tile to use a full image
1277
1268
  * @param {HTMLImageElement|OffscreenCanvas} image
1278
- * @param {WebGLTexture} [glTexture] - webgl texture
1269
+ * @param {WebGLTexture} [glTexture] - WebGL texture
1279
1270
  * @return {TileInfo}
1280
1271
  */
1281
1272
  setFullImage(image: HTMLImageElement | OffscreenCanvas, glTexture?: WebGLTexture): TileInfo;
@@ -1285,7 +1276,7 @@ declare module "littlejsengine" {
1285
1276
  /**
1286
1277
  * Create a TextureInfo, called automatically by the engine
1287
1278
  * @param {HTMLImageElement|OffscreenCanvas} image
1288
- * @param {WebGLTexture} [glTexture] - webgl texture
1279
+ * @param {WebGLTexture} [glTexture] - WebGL texture
1289
1280
  */
1290
1281
  constructor(image: HTMLImageElement | OffscreenCanvas, glTexture?: WebGLTexture);
1291
1282
  /** @property {HTMLImageElement} - image source */
@@ -1294,7 +1285,7 @@ declare module "littlejsengine" {
1294
1285
  size: Vector2;
1295
1286
  /** @property {Vector2} - inverse of the size, cached for rendering */
1296
1287
  sizeInverse: Vector2;
1297
- /** @property {WebGLTexture} - webgl texture */
1288
+ /** @property {WebGLTexture} - WebGL texture */
1298
1289
  glTexture: WebGLTexture;
1299
1290
  createWebGLTexture(): void;
1300
1291
  }
@@ -1350,15 +1341,15 @@ declare module "littlejsengine" {
1350
1341
  * @memberof Draw */
1351
1342
  export function worldToScreen(worldPos: Vector2): Vector2;
1352
1343
  /** Draw textured tile centered in world space, with color applied if using WebGL
1353
- * @param {Vector2} pos - Center of the tile in world space
1354
- * @param {Vector2} [size=(1,1)] - Size of the tile in world space
1355
- * @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
1356
- * @param {Color} [color=(1,1,1,1)] - Color to modulate with
1357
- * @param {number} [angle] - Angle to rotate by
1358
- * @param {boolean} [mirror] - If true image is flipped along the Y axis
1359
- * @param {Color} [additiveColor] - Additive color to be applied if any
1360
- * @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1361
- * @param {boolean} [screenSpace=false] - If true the pos and size are in screen space
1344
+ * @param {Vector2} pos - Center of the tile in world space
1345
+ * @param {Vector2} [size=(1,1)] - Size of the tile in world space
1346
+ * @param {TileInfo} [tileInfo] - Tile info to use, untextured if undefined
1347
+ * @param {Color} [color=(1,1,1,1)] - Color to modulate with
1348
+ * @param {number} [angle] - Angle to rotate by
1349
+ * @param {boolean} [mirror] - Is image flipped along the Y axis?
1350
+ * @param {Color} [additiveColor] - Additive color to be applied if any
1351
+ * @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering?
1352
+ * @param {boolean} [screenSpace=false] - Are the pos and size are in screen space?
1362
1353
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
1363
1354
  * @memberof Draw */
1364
1355
  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;
@@ -1391,9 +1382,9 @@ declare module "littlejsengine" {
1391
1382
  * @param {Color} [lineColor=(0,0,0,1)]
1392
1383
  * @param {Vector2} [pos=(0,0)] - Offset to apply
1393
1384
  * @param {number} [angle] - Angle to rotate by
1394
- * @param {boolean} [useWebGL] - Webgl not supported
1385
+ * @param {boolean} [useWebGL=glEnable]
1395
1386
  * @param {boolean} [screenSpace]
1396
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1387
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1397
1388
  * @memberof Draw */
1398
1389
  export function drawPoly(points: Array<Vector2>, color?: Color, lineWidth?: number, lineColor?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1399
1390
  /** Draw colored ellipse using passed in point
@@ -1403,9 +1394,9 @@ declare module "littlejsengine" {
1403
1394
  * @param {number} [angle]
1404
1395
  * @param {number} [lineWidth]
1405
1396
  * @param {Color} [lineColor=(0,0,0,1)]
1406
- * @param {boolean} [useWebGL] - Webgl not supported
1397
+ * @param {boolean} [useWebGL=glEnable]
1407
1398
  * @param {boolean} [screenSpace]
1408
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1399
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1409
1400
  * @memberof Draw */
1410
1401
  export function drawEllipse(pos: Vector2, size?: Vector2, color?: Color, angle?: number, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1411
1402
  /** Draw colored circle using passed in point
@@ -1414,9 +1405,9 @@ declare module "littlejsengine" {
1414
1405
  * @param {Color} [color=(1,1,1,1)]
1415
1406
  * @param {number} [lineWidth=0]
1416
1407
  * @param {Color} [lineColor=(0,0,0,1)]
1417
- * @param {boolean} [useWebGL] - Webgl not supported
1418
- * @param {boolean} [screenSpace=false]
1419
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1408
+ * @param {boolean} [useWebGL=glEnable]
1409
+ * @param {boolean} [screenSpace]
1410
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1420
1411
  * @memberof Draw */
1421
1412
  export function drawCircle(pos: Vector2, radius?: number, color?: Color, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1422
1413
  /** Draw directly to a 2d canvas context in world space
@@ -1425,7 +1416,7 @@ declare module "littlejsengine" {
1425
1416
  * @param {number} angle
1426
1417
  * @param {boolean} [mirror]
1427
1418
  * @param {Function} [drawFunction]
1428
- * @param {boolean} [screenSpace=false]
1419
+ * @param {boolean} [screenSpace=false]
1429
1420
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1430
1421
  * @memberof Draw */
1431
1422
  export function drawCanvas2D(pos: Vector2, size: Vector2, angle?: number, mirror?: boolean, drawFunction?: Function, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
@@ -1497,27 +1488,34 @@ declare module "littlejsengine" {
1497
1488
  * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1498
1489
  * @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
1499
1490
  * @param {Vector2} [paddingSize=(0,1)] - How much extra space to add between characters
1500
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext] - context to draw to
1501
1491
  */
1502
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D);
1492
+ constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
1503
1493
  image: any;
1504
1494
  tileSize: Vector2;
1505
1495
  paddingSize: Vector2;
1506
- context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
1507
1496
  /** Draw text in world space using the image font
1508
1497
  * @param {string} text
1509
1498
  * @param {Vector2} pos
1510
1499
  * @param {number} [scale=.25]
1511
1500
  * @param {boolean} [center]
1501
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D}[context=drawContext]
1502
+ */
1503
+ drawText(text: string, pos: Vector2, scale?: number, center?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1504
+ /** Draw text on overlay canvas in world space using the image font
1505
+ * @param {string} text
1506
+ * @param {Vector2} pos
1507
+ * @param {number} [scale]
1508
+ * @param {boolean} [center]
1512
1509
  */
1513
- drawText(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1514
- /** Draw text in screen space using the image font
1510
+ drawTextOverlay(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1511
+ /** Draw text on overlay canvas in screen space using the image font
1515
1512
  * @param {string} text
1516
1513
  * @param {Vector2} pos
1517
1514
  * @param {number} [scale]
1518
1515
  * @param {boolean} [center]
1516
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1519
1517
  */
1520
- drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1518
+ drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1521
1519
  }
1522
1520
  /** Returns true if fullscreen mode is active
1523
1521
  * @return {boolean}
@@ -1527,7 +1525,7 @@ declare module "littlejsengine" {
1527
1525
  * @memberof Draw */
1528
1526
  export function toggleFullscreen(): void;
1529
1527
  /** Set the cursor style
1530
- * @param {string} cursorStyle - CSS cursor style (auto, none, crosshair, etc)
1528
+ * @param {string} [cursorStyle] - CSS cursor style (auto, none, crosshair, etc)
1531
1529
  * @memberof Draw */
1532
1530
  export function setCursor(cursorStyle?: string): void;
1533
1531
  /** Get the camera's visible area in world space
@@ -1536,8 +1534,8 @@ declare module "littlejsengine" {
1536
1534
  export function getCameraSize(): Vector2;
1537
1535
  /**
1538
1536
  * LittleJS WebGL Interface
1539
- * - All webgl used by the engine is wrapped up here
1540
- * - Will fall back to 2D canvas rendering if webgl is not supported
1537
+ * - All WebGL used by the engine is wrapped up here
1538
+ * - Will fall back to 2D canvas rendering if WebGL is not supported
1541
1539
  * - For normal stuff you won't need to see or call anything in this file
1542
1540
  * - For advanced stuff there are helper functions to create shaders, textures, etc
1543
1541
  * - Can be disabled with glEnable to revert to 2D canvas rendering
@@ -1550,23 +1548,28 @@ declare module "littlejsengine" {
1550
1548
  * @type {HTMLCanvasElement}
1551
1549
  * @memberof WebGL */
1552
1550
  export let glCanvas: HTMLCanvasElement;
1553
- /** 2d context for glCanvas
1551
+ /** WebGL2 context for `glCanvas`
1554
1552
  * @type {WebGL2RenderingContext}
1555
1553
  * @memberof WebGL */
1556
1554
  export let glContext: WebGL2RenderingContext;
1555
+ /** Clear the canvas and setup the viewport
1556
+ * @memberof WebGL */
1557
+ export function glClearCanvas(): void;
1558
+ /** Set the WebGL texture, called automatically if using multiple textures
1559
+ * - This may also flush the gl buffer resulting in more draw calls and worse performance
1560
+ * @param {WebGLTexture} texture
1561
+ * @param {boolean} [wrap] - Should the texture wrap or clamp
1562
+ * @memberof WebGL */
1563
+ export function glSetTexture(texture: WebGLTexture, wrap?: boolean): void;
1557
1564
  /** Compile WebGL shader of the given type, will throw errors if in debug mode
1558
- * @param {String} source
1559
- * @param {Number} type
1565
+ * @param {string} source
1566
+ * @param {number} type
1560
1567
  * @return {WebGLShader}
1561
1568
  * @memberof WebGL */
1562
1569
  export function glCompileShader(source: string, type: number): WebGLShader;
1563
- /** Flush any sprites still in the buffer and copy to main canvas
1564
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
1565
- * @memberof WebGL */
1566
- export function glCopyToContext(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1567
1570
  /** Create WebGL program with given shaders
1568
- * @param {String} vsSource
1569
- * @param {String} fsSource
1571
+ * @param {string} vsSource
1572
+ * @param {string} fsSource
1570
1573
  * @return {WebGLProgram}
1571
1574
  * @memberof WebGL */
1572
1575
  export function glCreateProgram(vsSource: string, fsSource: string): WebGLProgram;
@@ -1584,49 +1587,74 @@ declare module "littlejsengine" {
1584
1587
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} image
1585
1588
  * @memberof WebGL */
1586
1589
  export function glSetTextureData(texture: WebGLTexture, image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas): void;
1587
- /** Add a sprite to the gl draw list, used by all gl draw functions
1588
- * @param {Number} x
1589
- * @param {Number} y
1590
- * @param {Number} sizeX
1591
- * @param {Number} sizeY
1592
- * @param {Number} [angle]
1593
- * @param {Number} [uv0X]
1594
- * @param {Number} [uv0Y]
1595
- * @param {Number} [uv1X]
1596
- * @param {Number} [uv1Y]
1597
- * @param {Number} [rgba=-1] - white is -1
1598
- * @param {Number} [rgbaAdditive=0] - black is 0
1599
- * @memberof WebGL */
1600
- export function glDraw(x: number, y: number, sizeX: number, sizeY: number, angle?: number, uv0X?: number, uv0Y?: number, uv1X?: number, uv1Y?: number, rgba?: number, rgbaAdditive?: number): void;
1601
1590
  /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
1602
1591
  * @memberof WebGL */
1603
1592
  export function glFlush(): void;
1604
- /** Set the WebGl texture, called automatically if using multiple textures
1605
- * - This may also flush the gl buffer resulting in more draw calls and worse performance
1606
- * @param {WebGLTexture} texture
1607
- * @param {boolean} wrap - Should the texture wrap or clamp
1593
+ /** Flush any sprites still in the buffer and copy to main canvas
1594
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
1608
1595
  * @memberof WebGL */
1609
- export function glSetTexture(texture: WebGLTexture, wrap?: boolean): void;
1610
- /** Set anti-aliasing for webgl canvas
1596
+ export function glCopyToContext(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1597
+ /** Set anti-aliasing for WebGL canvas
1598
+ * Must be called before engineInit
1611
1599
  * @param {boolean} [antialias]
1612
1600
  * @memberof WebGL */
1613
1601
  export function glSetAntialias(antialias?: boolean): void;
1614
- /** Clear the canvas and setup the viewport
1602
+ /** Add a sprite to the gl draw list, used by all gl draw functions
1603
+ * @param {number} x
1604
+ * @param {number} y
1605
+ * @param {number} sizeX
1606
+ * @param {number} sizeY
1607
+ * @param {number} [angle]
1608
+ * @param {number} [uv0X]
1609
+ * @param {number} [uv0Y]
1610
+ * @param {number} [uv1X]
1611
+ * @param {number} [uv1Y]
1612
+ * @param {number} [rgba=-1] - white is -1
1613
+ * @param {number} [rgbaAdditive=0] - black is 0
1615
1614
  * @memberof WebGL */
1616
- export function glClearCanvas(): void;
1617
- /** Should webgl be setup with anti-aliasing? must be set before calling engineInit
1615
+ export function glDraw(x: number, y: number, sizeX: number, sizeY: number, angle?: number, uv0X?: number, uv0Y?: number, uv1X?: number, uv1Y?: number, rgba?: number, rgbaAdditive?: number): void;
1616
+ /** Transform and add a polygon to the gl draw list
1617
+ * @param {Array} points - Array of Vector2 points
1618
+ * @param {number} rgba - Color of the polygon as a 32-bit integer
1619
+ * @param {number} x
1620
+ * @param {number} y
1621
+ * @param {number} sx
1622
+ * @param {number} sy
1623
+ * @param {number} angle
1624
+ * @param {boolean} [tristrip] - should tristrip algorithm be used
1625
+ * @memberof WebGL */
1626
+ export function glDrawPointsTransform(points: any[], rgba: number, x: number, y: number, sx: number, sy: number, angle: number, tristrip?: boolean): void;
1627
+ /** Transform and add a polygon to the gl draw list
1628
+ * @param {Array} points - Array of Vector2 points
1629
+ * @param {number} rgba - Color of the polygon as a 32-bit integer
1630
+ * @param {number} lineWidth - Width of the outline
1631
+ * @param {number} x
1632
+ * @param {number} y
1633
+ * @param {number} sx
1634
+ * @param {number} sy
1635
+ * @param {number} angle
1636
+ * @memberof WebGL */
1637
+ export function glDrawOutlineTransform(points: any[], rgba: number, lineWidth: number, x: number, y: number, sx: number, sy: number, angle: number): void;
1638
+ /** Add a polygon to the gl draw list
1639
+ * @param {Array} points - Array of Vector2 points in triangle strip order
1640
+ * @param {number} rgba - Color of the polygon as a 32-bit integer
1641
+ * @memberof WebGL */
1642
+ export function glDrawPoints(points: any[], rgba: number): void;
1643
+ /** Should WebGL be setup with anti-aliasing? must be set before calling engineInit
1618
1644
  * @type {boolean}
1619
1645
  * @memberof WebGL */
1620
1646
  export let glAntialias: boolean;
1621
1647
  export let glShader: any;
1648
+ export let glPolyShader: any;
1649
+ export let glPolyMode: any;
1650
+ export let glAdditive: any;
1651
+ export let glBatchAdditive: any;
1622
1652
  export let glActiveTexture: any;
1623
1653
  export let glArrayBuffer: any;
1624
1654
  export let glGeometryBuffer: any;
1625
1655
  export let glPositionData: any;
1626
1656
  export let glColorData: any;
1627
- export let glInstanceCount: any;
1628
- export let glAdditive: any;
1629
- export let glBatchAdditive: any;
1657
+ export let glBatchCount: any;
1630
1658
  /**
1631
1659
  * LittleJS Input System
1632
1660
  * - Tracks keyboard down, pressed, and released
@@ -1765,6 +1793,28 @@ declare module "littlejsengine" {
1765
1793
  * @return {boolean}
1766
1794
  * @memberof Input */
1767
1795
  export function pointerLockIsActive(): boolean;
1796
+ /**
1797
+ * LittleJS Audio System
1798
+ * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1799
+ * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1800
+ * - Caches sounds and music for fast playback
1801
+ * - Can attenuate and apply stereo panning to sounds
1802
+ * - Ability to play mp3, ogg, and wave files
1803
+ * - Speech synthesis functions
1804
+ * @namespace Audio
1805
+ */
1806
+ /** Audio context used by the engine
1807
+ * @type {AudioContext}
1808
+ * @memberof Audio */
1809
+ export let audioContext: AudioContext;
1810
+ /** Master gain node for all audio to pass through
1811
+ * @type {GainNode}
1812
+ * @memberof Audio */
1813
+ export let audioMasterGain: GainNode;
1814
+ /** Default sample rate used for sounds
1815
+ * @default 44100
1816
+ * @memberof Audio */
1817
+ export const audioDefaultSampleRate: 44100;
1768
1818
  /**
1769
1819
  * Sound Object - Stores a sound for later use and can be played positionally
1770
1820
  *
@@ -1789,46 +1839,45 @@ declare module "littlejsengine" {
1789
1839
  taper: number;
1790
1840
  /** @property {number} - How much to randomize frequency each time sound plays */
1791
1841
  randomness: any;
1792
- sampleChannels: any[][];
1842
+ /** @property {number} - Sample rate for this sound */
1793
1843
  sampleRate: number;
1844
+ /** @property {number} - Percentage of this sound currently loaded */
1845
+ loadedPercent: number;
1846
+ sampleChannels: any[][];
1794
1847
  /** Play the sound
1795
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1796
- * @param {number} [volume] - How much to scale volume by (in addition to range fade)
1797
- * @param {number} [pitch] - How much to scale pitch by (also adjusted by this.randomness)
1798
- * @param {number} [randomnessScale] - How much to scale randomness
1799
- * @param {boolean} [loop] - Should the sound loop
1800
- * @return {AudioBufferSourceNode} - The audio source node
1801
- */
1802
- play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
1803
- gainNode: GainNode;
1804
- source: AudioBufferSourceNode;
1805
- /** Set the sound volume of the most recently played instance of this sound
1848
+ * Sounds may not play until a user interaction occurs
1849
+ * @param {Vector2} [pos] - World space position to play the sound if any
1806
1850
  * @param {number} [volume] - How much to scale volume by
1851
+ * @param {number} [pitch] - How much to scale pitch by
1852
+ * @param {number} [randomnessScale] - How much to scale pitch randomness
1853
+ * @param {boolean} [loop] - Should the sound loop?
1854
+ * @param {boolean} [paused] - Should the sound start paused
1855
+ * @return {SoundInstance} - The audio source node
1807
1856
  */
1808
- setVolume(volume?: number): void;
1809
- /** Stop the last instance of this sound that was played
1810
- * @param {number} [fadeTime] - How long to fade out (seconds)
1811
- */
1812
- stop(fadeTime?: number): void;
1813
- /** Get source of most recent instance of this sound that was played
1814
- * @return {AudioBufferSourceNode}
1857
+ play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean, paused?: boolean): SoundInstance;
1858
+ /** Play a music track that loops by default
1859
+ * @param {number} [volume] - Volume to play the music at
1860
+ * @param {boolean} [loop] - Should the music loop?
1861
+ * @param {boolean} [paused] - Should the music start paused
1862
+ * @return {SoundInstance} - The audio source node
1815
1863
  */
1816
- getSource(): AudioBufferSourceNode;
1817
- /** Play the sound as a note with a semitone offset
1864
+ playMusic(volume?: number, loop?: boolean, paused?: boolean): SoundInstance;
1865
+ /** Play the sound as a musical note with a semitone offset
1866
+ * This can be used to play music with chromatic scales
1818
1867
  * @param {number} semitoneOffset - How many semitones to offset pitch
1819
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1820
- * @param {number} [volume=1] - How much to scale volume by (in addition to range fade)
1821
- * @return {AudioBufferSourceNode} - The audio source node
1868
+ * @param {Vector2} [pos] - World space position to play the sound if any
1869
+ * @param {number} [volume=1] - How much to scale volume by
1870
+ * @return {SoundInstance} - The audio source node
1822
1871
  */
1823
- playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
1872
+ playNote(semitoneOffset: number, pos?: Vector2, volume?: number): SoundInstance;
1824
1873
  /** Get how long this sound is in seconds
1825
1874
  * @return {number} - How long the sound is in seconds (undefined if loading)
1826
1875
  */
1827
1876
  getDuration(): number;
1828
- /** Check if sound is loading, for sounds fetched from a url
1829
- * @return {boolean} - True if sound is loading and not ready to play
1877
+ /** Check if sound is loaded, for sounds fetched from a url
1878
+ * @return {boolean} - True if sound is loaded and ready to play
1830
1879
  */
1831
- isLoading(): boolean;
1880
+ isLoaded(): boolean;
1832
1881
  }
1833
1882
  /**
1834
1883
  * Sound Wave Object - Stores a wave sound for later use and can be played positionally
@@ -1856,13 +1905,82 @@ declare module "littlejsengine" {
1856
1905
  * @return {Promise<void>} */
1857
1906
  loadSound(filename: string): Promise<void>;
1858
1907
  }
1859
- /** Play an mp3, ogg, or wav audio from a local file or url
1860
- * @param {string} filename - Location of sound file to play
1861
- * @param {number} [volume] - How much to scale volume by
1862
- * @param {boolean} [loop] - True if the music should loop
1863
- * @return {SoundWave} - The sound object for this file
1864
- * @memberof Audio */
1865
- export function playAudioFile(filename: string, volume?: number, loop?: boolean): SoundWave;
1908
+ /**
1909
+ * Sound Instance - Wraps an AudioBufferSourceNode for individual sound control
1910
+ * Represents a single playing instance of a sound with pause/resume capabilities
1911
+ * @example
1912
+ * // Play a sound and get an instance for control
1913
+ * const jumpSound = new Sound([.5,.5,220]);
1914
+ * const instance = jumpSound.play();
1915
+ *
1916
+ * // Control the individual instance
1917
+ * instance.setVolume(.5);
1918
+ * instance.pause();
1919
+ * instance.unpause();
1920
+ * instance.stop();
1921
+ */
1922
+ export class SoundInstance {
1923
+ /** Create a sound instance
1924
+ * @param {Sound} sound - The sound object
1925
+ * @param {number} [volume] - How much to scale volume by
1926
+ * @param {number} [rate] - The playback rate to use
1927
+ * @param {number} [pan] - How much to apply stereo panning
1928
+ * @param {boolean} [loop] - Should the sound loop?
1929
+ * @param {boolean} [paused] - Should the sound start paused? */
1930
+ constructor(sound: Sound, volume?: number, rate?: number, pan?: number, loop?: boolean, paused?: boolean);
1931
+ /** @property {Sound} - The sound object */
1932
+ sound: Sound;
1933
+ /** @property {number} - How much to scale volume by */
1934
+ volume: number;
1935
+ /** @property {number} - The playback rate to use */
1936
+ rate: number;
1937
+ /** @property {number} - How much to apply stereo panning */
1938
+ pan: number;
1939
+ /** @property {boolean} - Should the sound loop */
1940
+ loop: boolean;
1941
+ /** @property {number} - Timestamp for audio context when paused */
1942
+ pausedTime: number;
1943
+ /** @property {number} - Timestamp for audio context when started */
1944
+ startTime: number;
1945
+ /** @property {GainNode} - Gain node for the sound */
1946
+ gainNode: GainNode;
1947
+ /** @property {AudioBufferSourceNode} - Source node of the audio */
1948
+ source: AudioBufferSourceNode;
1949
+ onendedCallback: (source: any) => void;
1950
+ /** Start playing the sound instance from the offset time
1951
+ * @param {number} [offset] - Offset in seconds to start playback from
1952
+ */
1953
+ start(offset?: number): void;
1954
+ /** Set the volume of this sound instance
1955
+ * @param {number} volume */
1956
+ setVolume(volume: number): void;
1957
+ /** Stop this sound instance and reset position to the start */
1958
+ stop(fadeTime?: number): void;
1959
+ /** Pause this sound instance */
1960
+ pause(): void;
1961
+ /** Unpauses this sound instance */
1962
+ resume(): void;
1963
+ /** Check if this instance is currently playing
1964
+ * @return {boolean} - True if playing
1965
+ */
1966
+ isPlaying(): boolean;
1967
+ /** Check if this instance is paused and was not stopped
1968
+ * @return {boolean} - True if paused
1969
+ */
1970
+ isPaused(): boolean;
1971
+ /** Get the current playback time in seconds
1972
+ * @return {number} - Current playback time
1973
+ */
1974
+ getCurrentTime(): number;
1975
+ /** Get the total duration of this sound
1976
+ * @return {number} - Total duration in seconds
1977
+ */
1978
+ getDuration(): number;
1979
+ /** Get source of this sound instance
1980
+ * @return {AudioBufferSourceNode}
1981
+ */
1982
+ getSource(): AudioBufferSourceNode;
1983
+ }
1866
1984
  /** Speak text with passed in settings
1867
1985
  * @param {string} text - The text to speak
1868
1986
  * @param {string} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
@@ -1889,9 +2007,11 @@ declare module "littlejsengine" {
1889
2007
  * @param {boolean} [loop] - True if the sound should loop when it reaches the end
1890
2008
  * @param {number} [sampleRate=44100] - Sample rate for the sound
1891
2009
  * @param {GainNode} [gainNode] - Optional gain node for volume control while playing
2010
+ * @param {number} [offset] - Offset in seconds to start playback from
2011
+ * @param {Function} [onended] - Callback for when the sound ends
1892
2012
  * @return {AudioBufferSourceNode} - The audio node of the sound played
1893
2013
  * @memberof Audio */
1894
- export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number, gainNode?: GainNode): AudioBufferSourceNode;
2014
+ export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number, gainNode?: GainNode, offset?: number, onended?: Function): AudioBufferSourceNode;
1895
2015
  /** Generate and play a ZzFX sound
1896
2016
  *
1897
2017
  * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
@@ -1922,27 +2042,8 @@ declare module "littlejsengine" {
1922
2042
  * @param {number} [tremolo] - Trembling effect, rate controlled by repeat time (percent)
1923
2043
  * @param {number} [filter] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
1924
2044
  * @return {Array} - Array of audio samples
1925
- * @memberof Audio
1926
- */
1927
- export function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number, filter?: number): any[];
1928
- /** Sample rate used for all ZzFX sounds
1929
- * @default 44100
1930
2045
  * @memberof Audio */
1931
- export const zzfxR: 44100;
1932
- /**
1933
- * LittleJS Audio System
1934
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1935
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1936
- * - Caches sounds and music for fast playback
1937
- * - Can attenuate and apply stereo panning to sounds
1938
- * - Ability to play mp3, ogg, and wave files
1939
- * - Speech synthesis functions
1940
- * @namespace Audio
1941
- */
1942
- /** Audio context used by the engine
1943
- * @type {AudioContext}
1944
- * @memberof Audio */
1945
- export let audioContext: AudioContext;
2046
+ export function zzfxG(volume?: number, randomness?: number, frequency?: number, attack?: number, sustain?: number, release?: number, shape?: number, shapeCurve?: number, slide?: number, deltaSlide?: number, pitchJump?: number, pitchJumpTime?: number, repeatTime?: number, noise?: number, modulation?: number, bitCrush?: number, delay?: number, sustainVolume?: number, decay?: number, tremolo?: number, filter?: number): any[];
1946
2047
  /**
1947
2048
  * LittleJS Object System
1948
2049
  */
@@ -2115,7 +2216,7 @@ declare module "littlejsengine" {
2115
2216
  /** Keep track of all tile layers with collision
2116
2217
  * @type {Array<TileCollisionLayer>}
2117
2218
  * @memberof TileCollision */
2118
- export let tileCollisionLayers: Array<TileCollisionLayer>;
2219
+ export const tileCollisionLayers: Array<TileCollisionLayer>;
2119
2220
  /** Get tile collision data for a given cell in the grid
2120
2221
  * @param {Vector2} pos
2121
2222
  * @return {number}
@@ -2179,7 +2280,7 @@ declare module "littlejsengine" {
2179
2280
  /**
2180
2281
  * Canvas Layer - cached off screen rendering system
2181
2282
  * - Contains an offscreen canvas that can be rendered to
2182
- * - Webgl rendering is optional, call useWebGL to enable
2283
+ * - WebGL rendering is optional, call useWebGL to enable
2183
2284
  * @extends EngineObject
2184
2285
  * @example
2185
2286
  * const canvasLayer = new CanvasLayer(vec2(), vec2(200,100));
@@ -2197,7 +2298,7 @@ declare module "littlejsengine" {
2197
2298
  canvas: OffscreenCanvas;
2198
2299
  /** @property {OffscreenCanvasRenderingContext2D} - The 2D canvas context used by this layer */
2199
2300
  context: OffscreenCanvasRenderingContext2D;
2200
- /** @property {WebGLTexture} - Texture if using webgl for this layer, call useWebGL to enable */
2301
+ /** @property {WebGLTexture} - Texture if using WebGL for this layer, call useWebGL to enable */
2201
2302
  glTexture: WebGLTexture;
2202
2303
  /** Draw this canvas layer centered in world space, with color applied if using WebGL
2203
2304
  * @param {Vector2} pos - Center in world space
@@ -2210,7 +2311,7 @@ declare module "littlejsengine" {
2210
2311
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
2211
2312
  * @memberof Draw */
2212
2313
  draw(pos: Vector2, size?: Vector2, angle?: number, color?: Color, mirror?: boolean, additiveColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2213
- /** Draw onto the layer canvas in world space (bypass webgl)
2314
+ /** Draw onto the layer canvas in world space (bypass WebGL)
2214
2315
  * @param {Vector2} pos
2215
2316
  * @param {Vector2} size
2216
2317
  * @param {number} angle
@@ -2231,8 +2332,8 @@ declare module "littlejsengine" {
2231
2332
  * @param {Color} [color=(1,1,1,1)]
2232
2333
  * @param {number} [angle=0] */
2233
2334
  drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2234
- /** Create or update the webgl texture for this layer
2235
- * @param {boolean} [enable] - enable webgl rendering and update the texture */
2335
+ /** Create or update the WebGL texture for this layer
2336
+ * @param {boolean} [enable] - enable WebGL rendering and update the texture */
2236
2337
  useWebGL(enable?: boolean): void;
2237
2338
  }
2238
2339
  /**
@@ -2288,7 +2389,7 @@ declare module "littlejsengine" {
2288
2389
  * Tile Collision Layer - a tile layer with collision
2289
2390
  * - adds collision data and functions to TileLayer
2290
2391
  * - there can be multiple tile collision layers
2291
- * - tile collison layers should not overlap each other
2392
+ * - tile collision layers should not overlap each other
2292
2393
  * @extends TileLayer
2293
2394
  */
2294
2395
  export class TileCollisionLayer extends TileLayer {
@@ -2350,41 +2451,41 @@ declare module "littlejsengine" {
2350
2451
  export class ParticleEmitter extends EngineObject {
2351
2452
  /** Create a particle system with the given settings
2352
2453
  * @param {Vector2} position - World space position of the emitter
2353
- * @param {Number} [angle] - Angle to emit the particles
2354
- * @param {Number|Vector2} [emitSize] - World space size of the emitter (float for circle diameter, vec2 for rect)
2355
- * @param {Number} [emitTime] - How long to stay alive (0 is forever)
2356
- * @param {Number} [emitRate] - How many particles per second to spawn, does not emit if 0
2357
- * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
2454
+ * @param {number} [angle] - Angle to emit the particles
2455
+ * @param {number|Vector2} [emitSize] - World space size of the emitter (float for circle diameter, vec2 for rect)
2456
+ * @param {number} [emitTime] - How long to stay alive (0 is forever)
2457
+ * @param {number} [emitRate] - How many particles per second to spawn, does not emit if 0
2458
+ * @param {number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
2358
2459
  * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
2359
2460
  * @param {Color} [colorStartA=(1,1,1,1)] - Color at start of life 1, randomized between start colors
2360
2461
  * @param {Color} [colorStartB=(1,1,1,1)] - Color at start of life 2, randomized between start colors
2361
2462
  * @param {Color} [colorEndA=(1,1,1,0)] - Color at end of life 1, randomized between end colors
2362
2463
  * @param {Color} [colorEndB=(1,1,1,0)] - Color at end of life 2, randomized between end colors
2363
- * @param {Number} [particleTime] - How long particles live
2364
- * @param {Number} [sizeStart] - How big are particles at start
2365
- * @param {Number} [sizeEnd] - How big are particles at end
2366
- * @param {Number} [speed] - How fast are particles when spawned
2367
- * @param {Number} [angleSpeed] - How fast are particles rotating
2368
- * @param {Number} [damping] - How much to dampen particle speed
2369
- * @param {Number} [angleDamping] - How much to dampen particle angular speed
2370
- * @param {Number} [gravityScale] - How much gravity effect particles
2371
- * @param {Number} [particleConeAngle] - Cone for start particle angle
2372
- * @param {Number} [fadeRate] - How quick to fade particles at start/end in percent of life
2373
- * @param {Number} [randomness] - Apply extra randomness percent
2464
+ * @param {number} [particleTime] - How long particles live
2465
+ * @param {number} [sizeStart] - How big are particles at start
2466
+ * @param {number} [sizeEnd] - How big are particles at end
2467
+ * @param {number} [speed] - How fast are particles when spawned
2468
+ * @param {number} [angleSpeed] - How fast are particles rotating
2469
+ * @param {number} [damping] - How much to dampen particle speed
2470
+ * @param {number} [angleDamping] - How much to dampen particle angular speed
2471
+ * @param {number} [gravityScale] - How much gravity effect particles
2472
+ * @param {number} [particleConeAngle] - Cone for start particle angle
2473
+ * @param {number} [fadeRate] - How quick to fade particles at start/end in percent of life
2474
+ * @param {number} [randomness] - Apply extra randomness percent
2374
2475
  * @param {boolean} [collideTiles] - Do particles collide against tiles
2375
2476
  * @param {boolean} [additive] - Should particles use additive blend
2376
2477
  * @param {boolean} [randomColorLinear] - Should color be randomized linearly or across each component
2377
- * @param {Number} [renderOrder] - Render order for particles (additive is above other stuff by default)
2478
+ * @param {number} [renderOrder] - Render order for particles (additive is above other stuff by default)
2378
2479
  * @param {boolean} [localSpace] - Should it be in local space of emitter (world space is default)
2379
2480
  */
2380
2481
  constructor(position: Vector2, angle?: number, emitSize?: number | Vector2, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileInfo?: TileInfo, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number, localSpace?: boolean);
2381
- /** @property {Number|Vector2} - World space size of the emitter (float for circle diameter, vec2 for rect) */
2482
+ /** @property {number|Vector2} - World space size of the emitter (float for circle diameter, vec2 for rect) */
2382
2483
  emitSize: number | Vector2;
2383
- /** @property {Number} - How long to stay alive (0 is forever) */
2484
+ /** @property {number} - How long to stay alive (0 is forever) */
2384
2485
  emitTime: number;
2385
- /** @property {Number} - How many particles per second to spawn, does not emit if 0 */
2486
+ /** @property {number} - How many particles per second to spawn, does not emit if 0 */
2386
2487
  emitRate: number;
2387
- /** @property {Number} - Local angle to apply velocity to particles from emitter */
2488
+ /** @property {number} - Local angle to apply velocity to particles from emitter */
2388
2489
  emitConeAngle: number;
2389
2490
  /** @property {Color} - Color at start of life 1, randomized between start colors */
2390
2491
  colorStartA: Color;
@@ -2396,33 +2497,33 @@ declare module "littlejsengine" {
2396
2497
  colorEndB: Color;
2397
2498
  /** @property {boolean} - Should color be randomized linearly or across each component */
2398
2499
  randomColorLinear: boolean;
2399
- /** @property {Number} - How long particles live */
2500
+ /** @property {number} - How long particles live */
2400
2501
  particleTime: number;
2401
- /** @property {Number} - How big are particles at start */
2502
+ /** @property {number} - How big are particles at start */
2402
2503
  sizeStart: number;
2403
- /** @property {Number} - How big are particles at end */
2504
+ /** @property {number} - How big are particles at end */
2404
2505
  sizeEnd: number;
2405
- /** @property {Number} - How fast are particles when spawned */
2506
+ /** @property {number} - How fast are particles when spawned */
2406
2507
  speed: number;
2407
- /** @property {Number} - How fast are particles rotating */
2508
+ /** @property {number} - How fast are particles rotating */
2408
2509
  angleSpeed: number;
2409
- /** @property {Number} - Cone for start particle angle */
2510
+ /** @property {number} - Cone for start particle angle */
2410
2511
  particleConeAngle: number;
2411
- /** @property {Number} - How quick to fade in particles at start/end in percent of life */
2512
+ /** @property {number} - How quick to fade in particles at start/end in percent of life */
2412
2513
  fadeRate: number;
2413
- /** @property {Number} - Apply extra randomness percent */
2514
+ /** @property {number} - Apply extra randomness percent */
2414
2515
  randomness: number;
2415
2516
  /** @property {boolean} - Should particles use additive blend */
2416
2517
  additive: boolean;
2417
2518
  /** @property {boolean} - Should it be in local space of emitter */
2418
2519
  localSpace: boolean;
2419
- /** @property {Number} - If non zero the particle is drawn as a trail, stretched in the direction of velocity */
2520
+ /** @property {number} - If non zero the particle is drawn as a trail, stretched in the direction of velocity */
2420
2521
  trailScale: number;
2421
2522
  /** @property {Function} - Callback when particle is destroyed */
2422
2523
  particleDestroyCallback: any;
2423
2524
  /** @property {Function} - Callback when particle is created */
2424
2525
  particleCreateCallback: any;
2425
- /** @property {Number} - Track particle emit time */
2526
+ /** @property {number} - Track particle emit time */
2426
2527
  emitTimeBuffer: number;
2427
2528
  /** Spawn one particle
2428
2529
  * @return {Particle} */
@@ -2438,15 +2539,15 @@ declare module "littlejsengine" {
2438
2539
  * Typically this is created automatically by a ParticleEmitter
2439
2540
  * @param {Vector2} position - World space position of the particle
2440
2541
  * @param {TileInfo} tileInfo - Tile info to render particles
2441
- * @param {Number} angle - Angle to rotate the particle
2542
+ * @param {number} angle - Angle to rotate the particle
2442
2543
  * @param {Color} colorStart - Color at start of life
2443
2544
  * @param {Color} colorEnd - Color at end of life
2444
- * @param {Number} lifeTime - How long to live for
2445
- * @param {Number} sizeStart - Size at start of life
2446
- * @param {Number} sizeEnd - Size at end of life
2447
- * @param {Number} fadeRate - How quick to fade in/out
2545
+ * @param {number} lifeTime - How long to live for
2546
+ * @param {number} sizeStart - Size at start of life
2547
+ * @param {number} sizeEnd - Size at end of life
2548
+ * @param {number} fadeRate - How quick to fade in/out
2448
2549
  * @param {boolean} additive - Does it use additive blend mode
2449
- * @param {Number} trailScale - If a trail, how long to make it
2550
+ * @param {number} trailScale - If a trail, how long to make it
2450
2551
  * @param {ParticleEmitter} [localSpaceEmitter] - Parent emitter if local space
2451
2552
  * @param {Function} [destroyCallback] - Callback when particle dies
2452
2553
  */
@@ -2455,17 +2556,17 @@ declare module "littlejsengine" {
2455
2556
  colorStart: Color;
2456
2557
  /** @property {Color} - Calculated change in color */
2457
2558
  colorEndDelta: Color;
2458
- /** @property {Number} - How long to live for */
2559
+ /** @property {number} - How long to live for */
2459
2560
  lifeTime: number;
2460
- /** @property {Number} - Size at start of life */
2561
+ /** @property {number} - Size at start of life */
2461
2562
  sizeStart: number;
2462
- /** @property {Number} - Calculated change in size */
2563
+ /** @property {number} - Calculated change in size */
2463
2564
  sizeEndDelta: number;
2464
- /** @property {Number} - How quick to fade in/out */
2565
+ /** @property {number} - How quick to fade in/out */
2465
2566
  fadeRate: number;
2466
2567
  /** @property {boolean} - Is it additive */
2467
2568
  additive: boolean;
2468
- /** @property {Number} - If a trail, how long to make it */
2569
+ /** @property {number} - If a trail, how long to make it */
2469
2570
  trailScale: number;
2470
2571
  /** @property {ParticleEmitter} - Parent emitter if local space */
2471
2572
  localSpaceEmitter: ParticleEmitter;
@@ -2491,7 +2592,7 @@ declare module "littlejsengine" {
2491
2592
  /** Initialize medals with a save name used for storage
2492
2593
  * - Call this after creating all medals
2493
2594
  * - Checks if medals are unlocked
2494
- * @param {String} saveName
2595
+ * @param {string} saveName
2495
2596
  * @memberof Medals */
2496
2597
  export function medalsInit(saveName: string): void;
2497
2598
  /**
@@ -2508,20 +2609,20 @@ declare module "littlejsengine" {
2508
2609
  */
2509
2610
  export class Medal {
2510
2611
  /** Create a medal object and adds it to the list of medals
2511
- * @param {Number} id - The unique identifier of the medal
2512
- * @param {String} name - Name of the medal
2513
- * @param {String} [description] - Description of the medal
2514
- * @param {String} [icon] - Icon for the medal
2515
- * @param {String} [src] - Image location for the medal
2612
+ * @param {number} id - The unique identifier of the medal
2613
+ * @param {string} name - Name of the medal
2614
+ * @param {string} [description] - Description of the medal
2615
+ * @param {string} [icon] - Icon for the medal
2616
+ * @param {string} [src] - Image location for the medal
2516
2617
  */
2517
2618
  constructor(id: number, name: string, description?: string, icon?: string, src?: string);
2518
- /** @property {Number} - The unique identifier of the medal */
2619
+ /** @property {number} - The unique identifier of the medal */
2519
2620
  id: number;
2520
- /** @property {String} - Name of the medal */
2621
+ /** @property {string} - Name of the medal */
2521
2622
  name: string;
2522
- /** @property {String} - Description of the medal */
2623
+ /** @property {string} - Description of the medal */
2523
2624
  description: string;
2524
- /** @property {String} - Icon for the medal */
2625
+ /** @property {string} - Icon for the medal */
2525
2626
  icon: string;
2526
2627
  /** @property {boolean} - Is the medal unlocked? */
2527
2628
  unlocked: boolean;
@@ -2529,12 +2630,12 @@ declare module "littlejsengine" {
2529
2630
  /** Unlocks a medal if not already unlocked */
2530
2631
  unlock(): void;
2531
2632
  /** Render a medal
2532
- * @param {Number} [hidePercent] - How much to slide the medal off screen
2633
+ * @param {number} [hidePercent] - How much to slide the medal off screen
2533
2634
  */
2534
2635
  render(hidePercent?: number): void;
2535
2636
  /** Render the icon for a medal
2536
2637
  * @param {Vector2} pos - Screen space position
2537
- * @param {Number} size - Screen space size
2638
+ * @param {number} size - Screen space size
2538
2639
  */
2539
2640
  renderIcon(pos: Vector2, size: number): void;
2540
2641
  storageKey(): string;
@@ -2584,7 +2685,7 @@ declare module "littlejsengine" {
2584
2685
  * @param {number} id - The scoreboard id
2585
2686
  * @param {string} [user] - A user's id or name
2586
2687
  * @param {number} [social] - If true, only social scores will be loaded
2587
- * @param {number} [skip] - Number of scores to skip before start
2688
+ * @param {number} [skip] - Number of scores to skip over
2588
2689
  * @param {number} [limit] - Number of scores to include in the list
2589
2690
  * @return {Object} - The response JSON object
2590
2691
  */
@@ -2672,9 +2773,9 @@ declare module "littlejsengine" {
2672
2773
  */
2673
2774
  constructor(zzfxMusic: [any[], any[], any[], number]);
2674
2775
  sampleChannels: any[];
2675
- /** Play the music
2676
- * @param {number} [volume=1] - How much to scale volume by
2677
- * @param {boolean} [loop] - True if the music should loop
2776
+ /** Play the music that loops by default
2777
+ * @param {number} [volume] - Volume to play the music at
2778
+ * @param {boolean} [loop] - Should the music loop?
2678
2779
  * @return {AudioBufferSourceNode} - The audio source node
2679
2780
  */
2680
2781
  playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
@@ -2736,7 +2837,7 @@ declare module "littlejsengine" {
2736
2837
  * @param {Color} [color=uiSystem.defaultColor]
2737
2838
  * @param {number} [lineWidth=uiSystem.defaultLineWidth]
2738
2839
  * @param {Color} [lineColor=uiSystem.defaultLineColor]
2739
- * @param {number} [lineWidth=uiSystem.defaultCornerRadius] */
2840
+ * @param {number} [cornerRadius=uiSystem.defaultCornerRadius] */
2740
2841
  drawRect(pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, cornerRadius?: number): void;
2741
2842
  /** Draw a line to the UI context
2742
2843
  * @param {Vector2} posA
@@ -2778,27 +2879,35 @@ declare module "littlejsengine" {
2778
2879
  pos: Vector2;
2779
2880
  /** @property {Vector2} - Screen space size of the object */
2780
2881
  size: Vector2;
2781
- /** @property {Color} - color of the object */
2882
+ /** @property {Color} - Color of the object */
2782
2883
  color: Color;
2783
- /** @property {Color} - color for text */
2884
+ /** @property {string} - Text for this ui object */
2885
+ text: any;
2886
+ /** @property {Color} - Color when disabled */
2887
+ disabledColor: Color;
2888
+ /** @property {boolean} - Is this object disabled? */
2889
+ disabled: boolean;
2890
+ /** @property {Color} - Color for text */
2784
2891
  textColor: Color;
2785
- /** @property {Color} - color used when hovering over the object */
2892
+ /** @property {Color} - Color used when hovering over the object */
2786
2893
  hoverColor: Color;
2787
- /** @property {Color} - color for line drawing */
2894
+ /** @property {Color} - Color for line drawing */
2788
2895
  lineColor: Color;
2789
- /** @property {number} - width for line drawing */
2896
+ /** @property {number} - Width for line drawing */
2790
2897
  lineWidth: number;
2791
- /** @property {string} - font for this objecct */
2898
+ /** @property {number} - Corner radius for rounded rects */
2899
+ cornerRadius: number;
2900
+ /** @property {string} - Font for this objecct */
2792
2901
  font: string;
2793
- /** @property {number} - override for text height */
2902
+ /** @property {number} - Override for text height */
2794
2903
  textHeight: any;
2795
- /** @property {boolean} - should this object be drawn */
2904
+ /** @property {boolean} - Should this object be drawn */
2796
2905
  visible: boolean;
2797
- /** @property {Array<UIObject>} - a list of this object's children */
2906
+ /** @property {Array<UIObject>} - A list of this object's children */
2798
2907
  children: any[];
2799
- /** @property {UIObject} - this object's parent, position is in parent space */
2908
+ /** @property {UIObject} - This object's parent, position is in parent space */
2800
2909
  parent: any;
2801
- /** @property {number} - Extra size added when checking if element is touched */
2910
+ /** @property {number} - Extra size added to make small buttons easier to touch on mobile devices */
2802
2911
  extraTouchSize: number;
2803
2912
  /** @property {Sound} - Sound when interactive element is pressed */
2804
2913
  soundPress: any;
@@ -2824,7 +2933,7 @@ declare module "littlejsengine" {
2824
2933
  update(): void;
2825
2934
  /** Render the object, called automatically by plugin once each frame */
2826
2935
  render(): void;
2827
- /** Special update for when object is invisible */
2936
+ /** Special update when object is not visible */
2828
2937
  updateInvisible(): void;
2829
2938
  /** Called when the mouse enters the object */
2830
2939
  onEnter(): void;
@@ -2852,9 +2961,7 @@ declare module "littlejsengine" {
2852
2961
  * @param {string} [font=uiSystem.defaultFont]
2853
2962
  */
2854
2963
  constructor(pos?: Vector2, size?: Vector2, text?: string, align?: string, font?: string);
2855
- /** @property {string} */
2856
2964
  text: string;
2857
- /** @property {string} */
2858
2965
  align: string;
2859
2966
  }
2860
2967
  /**
@@ -2890,12 +2997,7 @@ declare module "littlejsengine" {
2890
2997
  * @param {Color} [color=uiSystem.defaultButtonColor]
2891
2998
  */
2892
2999
  constructor(pos?: Vector2, size?: Vector2, text?: string, color?: Color);
2893
- /** @property {string} */
2894
3000
  text: string;
2895
- /** @property {Color} */
2896
- disabledColor: Color;
2897
- /** @property {boolean} */
2898
- disabled: boolean;
2899
3001
  }
2900
3002
  /**
2901
3003
  * UICheckbox - A UI object that acts as a checkbox
@@ -2906,10 +3008,13 @@ declare module "littlejsengine" {
2906
3008
  * @param {Vector2} [pos]
2907
3009
  * @param {Vector2} [size]
2908
3010
  * @param {boolean} [checked]
3011
+ * @param {string} [text]
3012
+ * @param {Color} [color=uiSystem.defaultButtonColor]
2909
3013
  */
2910
- constructor(pos?: Vector2, size?: Vector2, checked?: boolean);
2911
- /** @property {boolean} */
3014
+ constructor(pos?: Vector2, size?: Vector2, checked?: boolean, text?: string, color?: Color);
3015
+ /** @property {boolean} - Current percentage value of this scrollbar 0-1 */
2912
3016
  checked: boolean;
3017
+ text: string;
2913
3018
  }
2914
3019
  /**
2915
3020
  * UIScrollbar - A UI object that acts as a scrollbar
@@ -2925,12 +3030,11 @@ declare module "littlejsengine" {
2925
3030
  * @param {Color} [handleColor=WHITE]
2926
3031
  */
2927
3032
  constructor(pos?: Vector2, size?: Vector2, value?: number, text?: string, color?: Color, handleColor?: Color);
2928
- /** @property {number} */
3033
+ /** @property {number} - Current percentage value of this scrollbar 0-1 */
2929
3034
  value: number;
2930
- /** @property {string} */
2931
- text: string;
2932
- /** @property {Color} */
3035
+ /** @property {Color} - Color for the handle part of the scrollbar */
2933
3036
  handleColor: Color;
3037
+ text: string;
2934
3038
  }
2935
3039
  /**
2936
3040
  * LittleJS Box2D Physics Plugin
@@ -2960,7 +3064,9 @@ declare module "littlejsengine" {
2960
3064
  * @param {boolean} enable
2961
3065
  * @memberof Box2D */
2962
3066
  export function box2dSetDebug(enable: boolean): void;
2963
- /** Box2d Init - Call with await before starting LittleJS to init box2d
3067
+ /** Box2d Init - Call with await to init box2d
3068
+ * @example
3069
+ * await box2dInit();
2964
3070
  * @return {Promise<Box2dPlugin>}
2965
3071
  * @memberof Box2D */
2966
3072
  export function box2dInit(): Promise<Box2dPlugin>;
@@ -3808,7 +3914,7 @@ declare module "littlejsengine" {
3808
3914
  getCorrectionFactor(): number;
3809
3915
  }
3810
3916
  /** Draw a scalable nine-slice UI element in world space
3811
- * This function can apply color and additive color if webgl is enabled
3917
+ * This function can apply color and additive color if WebGL is enabled
3812
3918
  * @param {Vector2} pos - World space position
3813
3919
  * @param {Vector2} size - World space size
3814
3920
  * @param {TileInfo} startTile - Starting tile for the nine-slice pattern
@@ -3839,7 +3945,7 @@ declare module "littlejsengine" {
3839
3945
  * @memberof DrawUtilities */
3840
3946
  export function drawNineSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number, angle?: number): void;
3841
3947
  /** Draw a scalable three-slice UI element in world space
3842
- * This function can apply color and additive color if webgl is enabled
3948
+ * This function can apply color and additive color if WebGL is enabled
3843
3949
  * @param {Vector2} pos - World space position
3844
3950
  * @param {Vector2} size - World space size
3845
3951
  * @param {TileInfo} startTile - Starting tile for the three-slice pattern