littlejsengine 1.13.1 → 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 (83) hide show
  1. package/README.md +15 -11
  2. package/copyToGithub.bat +28 -0
  3. package/dist/littlejs.d.ts +430 -304
  4. package/dist/littlejs.esm.js +1745 -982
  5. package/dist/littlejs.esm.min.js +1 -1
  6. package/dist/littlejs.js +1716 -965
  7. package/dist/littlejs.min.js +1 -1
  8. package/dist/littlejs.release.js +1673 -922
  9. package/examples/box2d/game.js +2 -2
  10. package/examples/box2d/gameObjects.js +2 -2
  11. package/examples/box2d/scenes.js +1 -1
  12. package/examples/breakout/game.js +30 -25
  13. package/examples/breakoutTutorial/README.md +44 -41
  14. package/examples/breakoutTutorial/game.js +2 -2
  15. package/examples/electron/build.bat +7 -0
  16. package/examples/electron/build.js +124 -0
  17. package/examples/electron/electron.js +35 -0
  18. package/examples/electron/game.js +140 -0
  19. package/examples/electron/index.html +13 -0
  20. package/examples/electron/package.json +12 -0
  21. package/examples/electron/tiles.png +0 -0
  22. package/examples/empty/game.js +1 -0
  23. package/examples/htmlMenu/game.js +1 -1
  24. package/examples/index.html +332 -160
  25. package/examples/module/game.js +5 -2
  26. package/examples/particles/index.html +12 -3
  27. package/examples/platformer/gameEffects.js +20 -19
  28. package/examples/platformer/gameLevel.js +6 -1
  29. package/examples/shorts/base.html +1 -1
  30. package/examples/shorts/blending.js +9 -5
  31. package/examples/shorts/box2d.js +1 -1
  32. package/examples/shorts/box2dCar.js +1 -1
  33. package/examples/shorts/clock.js +1 -1
  34. package/examples/shorts/colors.js +2 -2
  35. package/examples/shorts/flappyGame.js +2 -1
  36. package/examples/shorts/helloWorld.js +1 -1
  37. package/examples/shorts/maze.js +1 -1
  38. package/examples/shorts/music.js +106 -0
  39. package/examples/shorts/nineSlice.js +9 -9
  40. package/examples/shorts/parallax.js +71 -0
  41. package/examples/shorts/piano.js +9 -10
  42. package/examples/shorts/postProcess.js +25 -8
  43. package/examples/shorts/raycasting.js +2 -2
  44. package/examples/shorts/shapes.js +7 -15
  45. package/examples/shorts/slidingPuzzle.js +2 -2
  46. package/examples/shorts/song.mp3 +0 -0
  47. package/examples/shorts/starfield.js +5 -7
  48. package/examples/shorts/systemFont.js +1 -1
  49. package/examples/shorts/uiSystem.js +16 -8
  50. package/examples/starter/build.js +9 -8
  51. package/examples/starter/game.js +5 -2
  52. package/examples/starter/index.html +2 -2
  53. package/examples/stress/index.html +13 -8
  54. package/examples/style.css +19 -6
  55. package/examples/typescript/build.js +1 -1
  56. package/examples/typescript/game.js +2 -2
  57. package/examples/typescript/game.ts +5 -2
  58. package/examples/uiSystem/game.js +13 -12
  59. package/package.json +2 -2
  60. package/plugins/box2d.js +24 -97
  61. package/plugins/drawUtilities.js +29 -23
  62. package/plugins/newgrounds.js +6 -6
  63. package/plugins/pluginExport.js +1 -1
  64. package/plugins/postProcess.js +7 -0
  65. package/plugins/uiSystem.js +106 -82
  66. package/plugins/zzfxm.js +10 -10
  67. package/reference.md +90 -54
  68. package/src/engine.js +28 -23
  69. package/src/engineAudio.js +285 -110
  70. package/src/engineBuild.js +9 -9
  71. package/src/engineDebug.js +28 -28
  72. package/src/engineDraw.js +346 -202
  73. package/src/engineExport.js +28 -16
  74. package/src/engineInput.js +58 -68
  75. package/src/engineMedals.js +29 -29
  76. package/src/engineObject.js +28 -25
  77. package/src/engineParticles.js +67 -60
  78. package/src/engineRelease.js +1 -1
  79. package/src/engineSettings.js +70 -16
  80. package/src/engineTileLayer.js +34 -34
  81. package/src/engineUtilities.js +69 -62
  82. package/src/engineWebGL.js +467 -65
  83. /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
@@ -262,6 +262,12 @@ declare module "littlejsengine" {
262
262
  * @default
263
263
  * @memberof Settings */
264
264
  export let cameraScale: number;
265
+ /** Enable applying color to tiles when using canvas2d
266
+ * - This is slower but should be the same as WebGL rendering
267
+ * @type {boolean}
268
+ * @default
269
+ * @memberof Settings */
270
+ export let canvasColorTiles: boolean;
265
271
  /** The max size of the canvas, centered if window is larger
266
272
  * @type {Vector2}
267
273
  * @default Vector2(1920,1080)
@@ -273,13 +279,19 @@ declare module "littlejsengine" {
273
279
  * @default Vector2()
274
280
  * @memberof Settings */
275
281
  export let canvasFixedSize: Vector2;
276
- /** Use nearest neighbor canvas scaling for more pixelated look
277
- * - Must be set before startup to take effect
282
+ /** Use nearest canvas scaling for more pixelated look
278
283
  * - If enabled sets css image-rendering:pixelated
279
284
  * @type {boolean}
280
285
  * @default
281
286
  * @memberof Settings */
282
287
  export let canvasPixelated: boolean;
288
+ /** Use nearest canvas scaling for more pixelated look
289
+ * - If enabled sets css image-rendering:pixelated
290
+ * - This defaults to false because text looks better with smoothing
291
+ * @type {boolean}
292
+ * @default
293
+ * @memberof Settings */
294
+ export let overlayCanvasPixelated: boolean;
283
295
  /** Disables texture filtering for crisper pixel art
284
296
  * @type {boolean}
285
297
  * @default
@@ -290,13 +302,12 @@ declare module "littlejsengine" {
290
302
  * @default
291
303
  * @memberof Settings */
292
304
  export let fontDefault: string;
293
- /** Enable to show the LittleJS splash screen be shown on startup
305
+ /** Enable to show the LittleJS splash screen on startup
294
306
  * @type {boolean}
295
307
  * @default
296
308
  * @memberof Settings */
297
309
  export let showSplashScreen: boolean;
298
310
  /** Disables all rendering, audio, and input for servers
299
- * - Must be set before startup to take effect
300
311
  * @type {boolean}
301
312
  * @default
302
313
  * @memberof Settings */
@@ -356,8 +367,7 @@ declare module "littlejsengine" {
356
367
  * @default
357
368
  * @memberof Settings */
358
369
  export let particleEmitRateScale: number;
359
- /** Enable webgl rendering, webgl can be disabled and removed from build (with some features disabled)
360
- * - Must be set before startup to take effect
370
+ /** Enable WebGL accelerated rendering
361
371
  * @type {boolean}
362
372
  * @default
363
373
  * @memberof Settings */
@@ -367,19 +377,18 @@ declare module "littlejsengine" {
367
377
  * @default
368
378
  * @memberof Settings */
369
379
  export let gamepadsEnable: boolean;
370
- /** 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)
371
381
  * @type {boolean}
372
382
  * @default
373
383
  * @memberof Settings */
374
384
  export let gamepadDirectionEmulateStick: boolean;
375
- /** 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)
376
386
  * @type {boolean}
377
387
  * @default
378
388
  * @memberof Settings */
379
389
  export let inputWASDEmulateDirection: boolean;
380
390
  /** True if touch gamepad should appear on mobile devices
381
391
  * - Supports left analog stick, 4 face buttons and start button (button 9)
382
- * - Must be set before startup to take effect
383
392
  * @type {boolean}
384
393
  * @default
385
394
  * @memberof Settings */
@@ -451,6 +460,13 @@ declare module "littlejsengine" {
451
460
  * @param {number} scale
452
461
  * @memberof Settings */
453
462
  export function setCameraScale(scale: number): void;
463
+ /** Set if tiles should be colorized when using canvas2d
464
+ * This can be slower but results should look nearly identical to WebGL rendering
465
+ * It can be enabled/disabled at any time
466
+ * Optimized for performance, and will use faster method if color is white or untextured
467
+ * @param {boolean} colorTiles
468
+ * @memberof Settings */
469
+ export function setCanvasColorTiles(colorTiles: boolean): void;
454
470
  /** Set max size of the canvas
455
471
  * @param {Vector2} size
456
472
  * @memberof Settings */
@@ -459,10 +475,17 @@ declare module "littlejsengine" {
459
475
  * @param {Vector2} size
460
476
  * @memberof Settings */
461
477
  export function setCanvasFixedSize(size: Vector2): void;
462
- /** Use nearest neighbor scaling algorithm for canvas for more pixelated look
478
+ /** Use nearest scaling algorithm for canvas for more pixelated look
479
+ * - If enabled sets css image-rendering:pixelated
463
480
  * @param {boolean} pixelated
464
481
  * @memberof Settings */
465
482
  export function setCanvasPixelated(pixelated: boolean): void;
483
+ /** Use nearest scaling algorithm for canvas for more pixelated look
484
+ * - If enabled sets css image-rendering:pixelated
485
+ * - This defaults to false because text looks better with smoothing
486
+ * @param {boolean} pixelated
487
+ * @memberof Settings */
488
+ export function setOverlayCanvasPixelated(pixelated: boolean): void;
466
489
  /** Disables texture filtering for crisper pixel art
467
490
  * @param {boolean} pixelated
468
491
  * @memberof Settings */
@@ -471,7 +494,7 @@ declare module "littlejsengine" {
471
494
  * @param {string} font
472
495
  * @memberof Settings */
473
496
  export function setFontDefault(font: string): void;
474
- /** Set if the LittleJS splash screen be shown on startup
497
+ /** Set if the LittleJS splash screen should be shown on startup
475
498
  * @param {boolean} show
476
499
  * @memberof Settings */
477
500
  export function setShowSplashScreen(show: boolean): void;
@@ -479,7 +502,7 @@ declare module "littlejsengine" {
479
502
  * @param {boolean} headless
480
503
  * @memberof Settings */
481
504
  export function setHeadlessMode(headless: boolean): void;
482
- /** Set if webgl rendering is enabled
505
+ /** Set if WebGL rendering is enabled
483
506
  * @param {boolean} enable
484
507
  * @memberof Settings */
485
508
  export function setGLEnable(enable: boolean): void;
@@ -507,7 +530,7 @@ declare module "littlejsengine" {
507
530
  * @param {number} damp
508
531
  * @memberof Settings */
509
532
  export function setObjectDefaultAngleDamping(damp: number): void;
510
- /** Set how much to bounce when a collision occur
533
+ /** Set how much to bounce when a collision occurs
511
534
  * @param {number} restitution
512
535
  * @memberof Settings */
513
536
  export function setObjectDefaultRestitution(restitution: number): void;
@@ -697,16 +720,17 @@ declare module "littlejsengine" {
697
720
  * @return {number}
698
721
  * @memberof Utilities */
699
722
  export function smoothStep(percent: number): number;
700
- /** Returns the nearest power of two not less then the value
723
+ /** Returns the nearest power of two not less than the value
701
724
  * @param {number} value
702
725
  * @return {number}
703
726
  * @memberof Utilities */
704
727
  export function nearestPowerOfTwo(value: number): number;
705
728
  /** Returns true if two axis aligned bounding boxes are overlapping
729
+ * this can be used for simple collision detection between objects
706
730
  * @param {Vector2} posA - Center of box A
707
731
  * @param {Vector2} sizeA - Size of box A
708
732
  * @param {Vector2} posB - Center of box B
709
- * @param {Vector2} [sizeB=(0,0)] - Size of box B, a point if undefined
733
+ * @param {Vector2} [sizeB=(0,0)] - Size of box B, uses a point if undefined
710
734
  * @return {boolean} - True if overlapping
711
735
  * @memberof Utilities */
712
736
  export function isOverlapping(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB?: Vector2): boolean;
@@ -722,9 +746,10 @@ declare module "littlejsengine" {
722
746
  * @param {number} [frequency] - Frequency of the wave in Hz
723
747
  * @param {number} [amplitude] - Amplitude (max height) of the wave
724
748
  * @param {number} [t=time] - Value to use for time of the wave
749
+ * @param {number} [offset] - Value to use for time offset of the wave
725
750
  * @return {number} - Value waving between 0 and amplitude
726
751
  * @memberof Utilities */
727
- export function wave(frequency?: number, amplitude?: number, t?: number): number;
752
+ export function wave(frequency?: number, amplitude?: number, t?: number, offset?: number): number;
728
753
  /** Formats seconds to mm:ss style for display purposes
729
754
  * @param {number} t - time in seconds
730
755
  * @return {string}
@@ -1096,8 +1121,7 @@ declare module "littlejsengine" {
1096
1121
  * let a = vec2(0, 1); // vector with coordinates (0, 1)
1097
1122
  * a = vec2(5); // set a to (5, 5)
1098
1123
  * b = vec2(); // set b to (0, 0)
1099
- * @memberof Utilities
1100
- */
1124
+ * @memberof Utilities */
1101
1125
  export function vec2(x?: number, y?: number): Vector2;
1102
1126
  /**
1103
1127
  * Create a color object with RGBA values, white by default
@@ -1116,16 +1140,26 @@ declare module "littlejsengine" {
1116
1140
  * @param {number} [l=1] - lightness
1117
1141
  * @param {number} [a=1] - alpha
1118
1142
  * @return {Color}
1119
- * @memberof Utilities
1120
- */
1143
+ * @memberof Utilities */
1121
1144
  export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
1122
1145
  /**
1123
1146
  * Check if object is a valid Color
1124
1147
  * @param {any} c
1125
1148
  * @return {boolean}
1126
- * @memberof Utilities
1127
- */
1149
+ * @memberof Utilities */
1128
1150
  export function isColor(c: any): boolean;
1151
+ /**
1152
+ * Check if object is a valid Vector2
1153
+ * @param {any} v
1154
+ * @return {boolean}
1155
+ * @memberof Utilities */
1156
+ export function isVector2(v: any): boolean;
1157
+ /**
1158
+ * Check if object is a valid number, not NaN or undefined, but it may be infinite
1159
+ * @param {any} n
1160
+ * @return {boolean}
1161
+ * @memberof Utilities */
1162
+ export function isNumber(n: any): boolean;
1129
1163
  /** Color - White #ffffff
1130
1164
  * @type {Color}
1131
1165
  * @memberof Utilities */
@@ -1186,18 +1220,17 @@ declare module "littlejsengine" {
1186
1220
  * Create a tile info object using a grid based system
1187
1221
  * - This can take vecs or floats for easier use and conversion
1188
1222
  * - If an index is passed in, the tile size and index will determine the position
1189
- * @param {Vector2|number} [pos=0] - Index of tile in sheet
1223
+ * @param {Vector2|number} [pos=0] - Index of tile in sheet
1190
1224
  * @param {Vector2|number} [size=tileSizeDefault] - Size of tile in pixels
1191
- * @param {number} [textureIndex] - Texture index to use
1192
- * @param {number} [padding] - How many pixels padding around tiles
1225
+ * @param {number} [textureIndex] - Texture index to use
1226
+ * @param {number} [padding] - How many pixels padding around tiles
1193
1227
  * @return {TileInfo}
1194
1228
  * @example
1195
1229
  * tile(2) // a tile at index 2 using the default tile size of 16
1196
1230
  * tile(5, 8) // a tile at index 5 using a tile size of 8
1197
1231
  * tile(1, 16, 3) // a tile at index 1 of size 16 on texture 3
1198
1232
  * tile(vec2(4,8), vec2(30,10)) // a tile at index (4,8) with a size of (30,10)
1199
- * @memberof Draw
1200
- */
1233
+ * @memberof Draw */
1201
1234
  export function tile(pos?: Vector2 | number, size?: Vector2 | number, textureIndex?: number, padding?: number): TileInfo;
1202
1235
  /**
1203
1236
  * Tile Info - Stores info about how to draw a tile
@@ -1233,7 +1266,7 @@ declare module "littlejsengine" {
1233
1266
  /**
1234
1267
  * Set this tile to use a full image
1235
1268
  * @param {HTMLImageElement|OffscreenCanvas} image
1236
- * @param {WebGLTexture} [glTexture] - webgl texture
1269
+ * @param {WebGLTexture} [glTexture] - WebGL texture
1237
1270
  * @return {TileInfo}
1238
1271
  */
1239
1272
  setFullImage(image: HTMLImageElement | OffscreenCanvas, glTexture?: WebGLTexture): TileInfo;
@@ -1243,7 +1276,7 @@ declare module "littlejsengine" {
1243
1276
  /**
1244
1277
  * Create a TextureInfo, called automatically by the engine
1245
1278
  * @param {HTMLImageElement|OffscreenCanvas} image
1246
- * @param {WebGLTexture} [glTexture] - webgl texture
1279
+ * @param {WebGLTexture} [glTexture] - WebGL texture
1247
1280
  */
1248
1281
  constructor(image: HTMLImageElement | OffscreenCanvas, glTexture?: WebGLTexture);
1249
1282
  /** @property {HTMLImageElement} - image source */
@@ -1252,7 +1285,7 @@ declare module "littlejsengine" {
1252
1285
  size: Vector2;
1253
1286
  /** @property {Vector2} - inverse of the size, cached for rendering */
1254
1287
  sizeInverse: Vector2;
1255
- /** @property {WebGLTexture} - webgl texture */
1288
+ /** @property {WebGLTexture} - WebGL texture */
1256
1289
  glTexture: WebGLTexture;
1257
1290
  createWebGLTexture(): void;
1258
1291
  }
@@ -1308,15 +1341,15 @@ declare module "littlejsengine" {
1308
1341
  * @memberof Draw */
1309
1342
  export function worldToScreen(worldPos: Vector2): Vector2;
1310
1343
  /** Draw textured tile centered in world space, with color applied if using WebGL
1311
- * @param {Vector2} pos - Center of the tile in world space
1312
- * @param {Vector2} [size=(1,1)] - Size of the tile in world space
1313
- * @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
1314
- * @param {Color} [color=(1,1,1,1)] - Color to modulate with
1315
- * @param {number} [angle] - Angle to rotate by
1316
- * @param {boolean} [mirror] - If true image is flipped along the Y axis
1317
- * @param {Color} [additiveColor] - Additive color to be applied if any
1318
- * @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1319
- * @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?
1320
1353
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
1321
1354
  * @memberof Draw */
1322
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;
@@ -1326,7 +1359,7 @@ declare module "littlejsengine" {
1326
1359
  * @param {Color} [color=(1,1,1,1)]
1327
1360
  * @param {number} [angle]
1328
1361
  * @param {boolean} [useWebGL=glEnable]
1329
- * @param {boolean} [screenSpace=false]
1362
+ * @param {boolean} [screenSpace]
1330
1363
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1331
1364
  * @memberof Draw */
1332
1365
  export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
@@ -1335,49 +1368,55 @@ declare module "littlejsengine" {
1335
1368
  * @param {Vector2} posB
1336
1369
  * @param {number} [thickness]
1337
1370
  * @param {Color} [color=(1,1,1,1)]
1371
+ * @param {Vector2} [pos=(0,0)] - Offset to apply
1372
+ * @param {number} [angle] - Angle to rotate by
1338
1373
  * @param {boolean} [useWebGL=glEnable]
1339
- * @param {boolean} [screenSpace=false]
1374
+ * @param {boolean} [screenSpace]
1340
1375
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1341
1376
  * @memberof Draw */
1342
- export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1377
+ export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1343
1378
  /** Draw colored polygon using passed in points
1344
- * @param {Array<Vector2>} points - Array of Vector2 points
1379
+ * @param {Array<Vector2>} points - Array of Vector2 points
1345
1380
  * @param {Color} [color=(1,1,1,1)]
1346
- * @param {number} [lineWidth=0]
1381
+ * @param {number} [lineWidth]
1347
1382
  * @param {Color} [lineColor=(0,0,0,1)]
1348
- * @param {boolean} [screenSpace=false]
1349
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1383
+ * @param {Vector2} [pos=(0,0)] - Offset to apply
1384
+ * @param {number} [angle] - Angle to rotate by
1385
+ * @param {boolean} [useWebGL=glEnable]
1386
+ * @param {boolean} [screenSpace]
1387
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1350
1388
  * @memberof Draw */
1351
- export function drawPoly(points: Array<Vector2>, color?: Color, lineWidth?: number, lineColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
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;
1352
1390
  /** Draw colored ellipse using passed in point
1353
1391
  * @param {Vector2} pos
1354
- * @param {number} [width=1]
1355
- * @param {number} [height=1]
1356
- * @param {number} [angle=0]
1392
+ * @param {Vector2} [size=(1,1)]
1357
1393
  * @param {Color} [color=(1,1,1,1)]
1358
- * @param {number} [lineWidth=0]
1394
+ * @param {number} [angle]
1395
+ * @param {number} [lineWidth]
1359
1396
  * @param {Color} [lineColor=(0,0,0,1)]
1360
- * @param {boolean} [screenSpace=false]
1361
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1397
+ * @param {boolean} [useWebGL=glEnable]
1398
+ * @param {boolean} [screenSpace]
1399
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1362
1400
  * @memberof Draw */
1363
- export function drawEllipse(pos: Vector2, width?: number, height?: number, angle?: number, color?: Color, lineWidth?: number, lineColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1401
+ export function drawEllipse(pos: Vector2, size?: Vector2, color?: Color, angle?: number, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1364
1402
  /** Draw colored circle using passed in point
1365
1403
  * @param {Vector2} pos
1366
1404
  * @param {number} [radius=1]
1367
1405
  * @param {Color} [color=(1,1,1,1)]
1368
1406
  * @param {number} [lineWidth=0]
1369
1407
  * @param {Color} [lineColor=(0,0,0,1)]
1370
- * @param {boolean} [screenSpace=false]
1371
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1408
+ * @param {boolean} [useWebGL=glEnable]
1409
+ * @param {boolean} [screenSpace]
1410
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1372
1411
  * @memberof Draw */
1373
- export function drawCircle(pos: Vector2, radius?: number, color?: Color, lineWidth?: number, lineColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1412
+ export function drawCircle(pos: Vector2, radius?: number, color?: Color, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1374
1413
  /** Draw directly to a 2d canvas context in world space
1375
1414
  * @param {Vector2} pos
1376
1415
  * @param {Vector2} size
1377
1416
  * @param {number} angle
1378
1417
  * @param {boolean} [mirror]
1379
1418
  * @param {Function} [drawFunction]
1380
- * @param {boolean} [screenSpace=false]
1419
+ * @param {boolean} [screenSpace=false]
1381
1420
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1382
1421
  * @memberof Draw */
1383
1422
  export function drawCanvas2D(pos: Vector2, size: Vector2, angle?: number, mirror?: boolean, drawFunction?: Function, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
@@ -1424,10 +1463,9 @@ declare module "littlejsengine" {
1424
1463
  export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, maxWidth?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1425
1464
  /** Enable normal or additive blend mode
1426
1465
  * @param {boolean} [additive]
1427
- * @param {boolean} [useWebGL=glEnable]
1428
1466
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1429
1467
  * @memberof Draw */
1430
- export function setBlendMode(additive?: boolean, useWebGL?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1468
+ export function setBlendMode(additive?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1431
1469
  /** Combines all LittleJS canvases onto the main canvas and clears them
1432
1470
  * This is necessary for things like saving a screenshot
1433
1471
  * @memberof Draw */
@@ -1450,27 +1488,34 @@ declare module "littlejsengine" {
1450
1488
  * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1451
1489
  * @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
1452
1490
  * @param {Vector2} [paddingSize=(0,1)] - How much extra space to add between characters
1453
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext] - context to draw to
1454
1491
  */
1455
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D);
1492
+ constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
1456
1493
  image: any;
1457
1494
  tileSize: Vector2;
1458
1495
  paddingSize: Vector2;
1459
- context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
1460
1496
  /** Draw text in world space using the image font
1461
1497
  * @param {string} text
1462
1498
  * @param {Vector2} pos
1463
1499
  * @param {number} [scale=.25]
1464
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]
1465
1509
  */
1466
- drawText(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1467
- /** 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
1468
1512
  * @param {string} text
1469
1513
  * @param {Vector2} pos
1470
1514
  * @param {number} [scale]
1471
1515
  * @param {boolean} [center]
1516
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
1472
1517
  */
1473
- drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean): void;
1518
+ drawTextScreen(text: string, pos: Vector2, scale?: number, center?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1474
1519
  }
1475
1520
  /** Returns true if fullscreen mode is active
1476
1521
  * @return {boolean}
@@ -1480,7 +1525,7 @@ declare module "littlejsengine" {
1480
1525
  * @memberof Draw */
1481
1526
  export function toggleFullscreen(): void;
1482
1527
  /** Set the cursor style
1483
- * @param {string} cursorStyle - CSS cursor style (auto, none, crosshair, etc)
1528
+ * @param {string} [cursorStyle] - CSS cursor style (auto, none, crosshair, etc)
1484
1529
  * @memberof Draw */
1485
1530
  export function setCursor(cursorStyle?: string): void;
1486
1531
  /** Get the camera's visible area in world space
@@ -1489,36 +1534,42 @@ declare module "littlejsengine" {
1489
1534
  export function getCameraSize(): Vector2;
1490
1535
  /**
1491
1536
  * LittleJS WebGL Interface
1492
- * - All webgl used by the engine is wrapped up here
1537
+ * - All WebGL used by the engine is wrapped up here
1538
+ * - Will fall back to 2D canvas rendering if WebGL is not supported
1493
1539
  * - For normal stuff you won't need to see or call anything in this file
1494
1540
  * - For advanced stuff there are helper functions to create shaders, textures, etc
1495
1541
  * - Can be disabled with glEnable to revert to 2D canvas rendering
1496
1542
  * - Batches sprite rendering on GPU for incredibly fast performance
1497
1543
  * - Sprite transform math is done in the shader where possible
1498
- * - Supports shadertoy style post processing shaders
1544
+ * - Supports shadertoy style post processing shaders via plugin
1499
1545
  * @namespace WebGL
1500
1546
  */
1501
1547
  /** The WebGL canvas which appears above the main canvas and below the overlay canvas
1502
1548
  * @type {HTMLCanvasElement}
1503
1549
  * @memberof WebGL */
1504
1550
  export let glCanvas: HTMLCanvasElement;
1505
- /** 2d context for glCanvas
1551
+ /** WebGL2 context for `glCanvas`
1506
1552
  * @type {WebGL2RenderingContext}
1507
1553
  * @memberof WebGL */
1508
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;
1509
1564
  /** Compile WebGL shader of the given type, will throw errors if in debug mode
1510
- * @param {String} source
1511
- * @param {Number} type
1565
+ * @param {string} source
1566
+ * @param {number} type
1512
1567
  * @return {WebGLShader}
1513
1568
  * @memberof WebGL */
1514
1569
  export function glCompileShader(source: string, type: number): WebGLShader;
1515
- /** Flush any sprites still in the buffer and copy to main canvas
1516
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
1517
- * @memberof WebGL */
1518
- export function glCopyToContext(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1519
1570
  /** Create WebGL program with given shaders
1520
- * @param {String} vsSource
1521
- * @param {String} fsSource
1571
+ * @param {string} vsSource
1572
+ * @param {string} fsSource
1522
1573
  * @return {WebGLProgram}
1523
1574
  * @memberof WebGL */
1524
1575
  export function glCreateProgram(vsSource: string, fsSource: string): WebGLProgram;
@@ -1536,49 +1587,74 @@ declare module "littlejsengine" {
1536
1587
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} image
1537
1588
  * @memberof WebGL */
1538
1589
  export function glSetTextureData(texture: WebGLTexture, image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas): void;
1539
- /** Add a sprite to the gl draw list, used by all gl draw functions
1540
- * @param {Number} x
1541
- * @param {Number} y
1542
- * @param {Number} sizeX
1543
- * @param {Number} sizeY
1544
- * @param {Number} [angle]
1545
- * @param {Number} [uv0X]
1546
- * @param {Number} [uv0Y]
1547
- * @param {Number} [uv1X]
1548
- * @param {Number} [uv1Y]
1549
- * @param {Number} [rgba=-1] - white is -1
1550
- * @param {Number} [rgbaAdditive=0] - black is 0
1551
- * @memberof WebGL */
1552
- 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;
1553
1590
  /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
1554
1591
  * @memberof WebGL */
1555
1592
  export function glFlush(): void;
1556
- /** Set the WebGl texture, called automatically if using multiple textures
1557
- * - This may also flush the gl buffer resulting in more draw calls and worse performance
1558
- * @param {WebGLTexture} texture
1559
- * @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
1560
1595
  * @memberof WebGL */
1561
- export function glSetTexture(texture: WebGLTexture, wrap?: boolean): void;
1562
- /** 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
1563
1599
  * @param {boolean} [antialias]
1564
1600
  * @memberof WebGL */
1565
1601
  export function glSetAntialias(antialias?: boolean): void;
1566
- /** 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
1567
1614
  * @memberof WebGL */
1568
- export function glClearCanvas(): void;
1569
- /** 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
1570
1644
  * @type {boolean}
1571
1645
  * @memberof WebGL */
1572
1646
  export let glAntialias: boolean;
1573
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;
1574
1652
  export let glActiveTexture: any;
1575
1653
  export let glArrayBuffer: any;
1576
1654
  export let glGeometryBuffer: any;
1577
1655
  export let glPositionData: any;
1578
1656
  export let glColorData: any;
1579
- export let glInstanceCount: any;
1580
- export let glAdditive: any;
1581
- export let glBatchAdditive: any;
1657
+ export let glBatchCount: any;
1582
1658
  /**
1583
1659
  * LittleJS Input System
1584
1660
  * - Tracks keyboard down, pressed, and released
@@ -1717,6 +1793,28 @@ declare module "littlejsengine" {
1717
1793
  * @return {boolean}
1718
1794
  * @memberof Input */
1719
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;
1720
1818
  /**
1721
1819
  * Sound Object - Stores a sound for later use and can be played positionally
1722
1820
  *
@@ -1741,46 +1839,45 @@ declare module "littlejsengine" {
1741
1839
  taper: number;
1742
1840
  /** @property {number} - How much to randomize frequency each time sound plays */
1743
1841
  randomness: any;
1744
- sampleChannels: any[][];
1842
+ /** @property {number} - Sample rate for this sound */
1745
1843
  sampleRate: number;
1844
+ /** @property {number} - Percentage of this sound currently loaded */
1845
+ loadedPercent: number;
1846
+ sampleChannels: any[][];
1746
1847
  /** Play the sound
1747
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1748
- * @param {number} [volume] - How much to scale volume by (in addition to range fade)
1749
- * @param {number} [pitch] - How much to scale pitch by (also adjusted by this.randomness)
1750
- * @param {number} [randomnessScale] - How much to scale randomness
1751
- * @param {boolean} [loop] - Should the sound loop
1752
- * @return {AudioBufferSourceNode} - The audio source node
1753
- */
1754
- play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
1755
- gainNode: GainNode;
1756
- source: AudioBufferSourceNode;
1757
- /** 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
1758
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
1759
1856
  */
1760
- setVolume(volume?: number): void;
1761
- /** Stop the last instance of this sound that was played
1762
- * @param {number} [fadeTime] - How long to fade out (seconds)
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
1763
1863
  */
1764
- stop(fadeTime?: number): void;
1765
- /** Get source of most recent instance of this sound that was played
1766
- * @return {AudioBufferSourceNode}
1767
- */
1768
- getSource(): AudioBufferSourceNode;
1769
- /** 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
1770
1867
  * @param {number} semitoneOffset - How many semitones to offset pitch
1771
- * @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
1772
- * @param {number} [volume=1] - How much to scale volume by (in addition to range fade)
1773
- * @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
1774
1871
  */
1775
- playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
1872
+ playNote(semitoneOffset: number, pos?: Vector2, volume?: number): SoundInstance;
1776
1873
  /** Get how long this sound is in seconds
1777
1874
  * @return {number} - How long the sound is in seconds (undefined if loading)
1778
1875
  */
1779
1876
  getDuration(): number;
1780
- /** Check if sound is loading, for sounds fetched from a url
1781
- * @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
1782
1879
  */
1783
- isLoading(): boolean;
1880
+ isLoaded(): boolean;
1784
1881
  }
1785
1882
  /**
1786
1883
  * Sound Wave Object - Stores a wave sound for later use and can be played positionally
@@ -1808,13 +1905,82 @@ declare module "littlejsengine" {
1808
1905
  * @return {Promise<void>} */
1809
1906
  loadSound(filename: string): Promise<void>;
1810
1907
  }
1811
- /** Play an mp3, ogg, or wav audio from a local file or url
1812
- * @param {string} filename - Location of sound file to play
1813
- * @param {number} [volume] - How much to scale volume by
1814
- * @param {boolean} [loop] - True if the music should loop
1815
- * @return {SoundWave} - The sound object for this file
1816
- * @memberof Audio */
1817
- 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
+ }
1818
1984
  /** Speak text with passed in settings
1819
1985
  * @param {string} text - The text to speak
1820
1986
  * @param {string} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
@@ -1841,9 +2007,11 @@ declare module "littlejsengine" {
1841
2007
  * @param {boolean} [loop] - True if the sound should loop when it reaches the end
1842
2008
  * @param {number} [sampleRate=44100] - Sample rate for the sound
1843
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
1844
2012
  * @return {AudioBufferSourceNode} - The audio node of the sound played
1845
2013
  * @memberof Audio */
1846
- 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;
1847
2015
  /** Generate and play a ZzFX sound
1848
2016
  *
1849
2017
  * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
@@ -1874,27 +2042,8 @@ declare module "littlejsengine" {
1874
2042
  * @param {number} [tremolo] - Trembling effect, rate controlled by repeat time (percent)
1875
2043
  * @param {number} [filter] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
1876
2044
  * @return {Array} - Array of audio samples
1877
- * @memberof Audio
1878
- */
1879
- 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[];
1880
- /** Sample rate used for all ZzFX sounds
1881
- * @default 44100
1882
- * @memberof Audio */
1883
- export const zzfxR: 44100;
1884
- /**
1885
- * LittleJS Audio System
1886
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1887
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1888
- * - Caches sounds and music for fast playback
1889
- * - Can attenuate and apply stereo panning to sounds
1890
- * - Ability to play mp3, ogg, and wave files
1891
- * - Speech synthesis functions
1892
- * @namespace Audio
1893
- */
1894
- /** Audio context used by the engine
1895
- * @type {AudioContext}
1896
2045
  * @memberof Audio */
1897
- 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[];
1898
2047
  /**
1899
2048
  * LittleJS Object System
1900
2049
  */
@@ -2067,7 +2216,7 @@ declare module "littlejsengine" {
2067
2216
  /** Keep track of all tile layers with collision
2068
2217
  * @type {Array<TileCollisionLayer>}
2069
2218
  * @memberof TileCollision */
2070
- export let tileCollisionLayers: Array<TileCollisionLayer>;
2219
+ export const tileCollisionLayers: Array<TileCollisionLayer>;
2071
2220
  /** Get tile collision data for a given cell in the grid
2072
2221
  * @param {Vector2} pos
2073
2222
  * @return {number}
@@ -2131,7 +2280,7 @@ declare module "littlejsengine" {
2131
2280
  /**
2132
2281
  * Canvas Layer - cached off screen rendering system
2133
2282
  * - Contains an offscreen canvas that can be rendered to
2134
- * - Webgl rendering is optional, call useWebGL to enable
2283
+ * - WebGL rendering is optional, call useWebGL to enable
2135
2284
  * @extends EngineObject
2136
2285
  * @example
2137
2286
  * const canvasLayer = new CanvasLayer(vec2(), vec2(200,100));
@@ -2149,7 +2298,7 @@ declare module "littlejsengine" {
2149
2298
  canvas: OffscreenCanvas;
2150
2299
  /** @property {OffscreenCanvasRenderingContext2D} - The 2D canvas context used by this layer */
2151
2300
  context: OffscreenCanvasRenderingContext2D;
2152
- /** @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 */
2153
2302
  glTexture: WebGLTexture;
2154
2303
  /** Draw this canvas layer centered in world space, with color applied if using WebGL
2155
2304
  * @param {Vector2} pos - Center in world space
@@ -2162,7 +2311,7 @@ declare module "littlejsengine" {
2162
2311
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
2163
2312
  * @memberof Draw */
2164
2313
  draw(pos: Vector2, size?: Vector2, angle?: number, color?: Color, mirror?: boolean, additiveColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2165
- /** Draw onto the layer canvas in world space (bypass webgl)
2314
+ /** Draw onto the layer canvas in world space (bypass WebGL)
2166
2315
  * @param {Vector2} pos
2167
2316
  * @param {Vector2} size
2168
2317
  * @param {number} angle
@@ -2183,8 +2332,8 @@ declare module "littlejsengine" {
2183
2332
  * @param {Color} [color=(1,1,1,1)]
2184
2333
  * @param {number} [angle=0] */
2185
2334
  drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2186
- /** Create or update the webgl texture for this layer
2187
- * @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 */
2188
2337
  useWebGL(enable?: boolean): void;
2189
2338
  }
2190
2339
  /**
@@ -2240,7 +2389,7 @@ declare module "littlejsengine" {
2240
2389
  * Tile Collision Layer - a tile layer with collision
2241
2390
  * - adds collision data and functions to TileLayer
2242
2391
  * - there can be multiple tile collision layers
2243
- * - tile collison layers should not overlap each other
2392
+ * - tile collision layers should not overlap each other
2244
2393
  * @extends TileLayer
2245
2394
  */
2246
2395
  export class TileCollisionLayer extends TileLayer {
@@ -2302,41 +2451,41 @@ declare module "littlejsengine" {
2302
2451
  export class ParticleEmitter extends EngineObject {
2303
2452
  /** Create a particle system with the given settings
2304
2453
  * @param {Vector2} position - World space position of the emitter
2305
- * @param {Number} [angle] - Angle to emit the particles
2306
- * @param {Number|Vector2} [emitSize] - World space size of the emitter (float for circle diameter, vec2 for rect)
2307
- * @param {Number} [emitTime] - How long to stay alive (0 is forever)
2308
- * @param {Number} [emitRate] - How many particles per second to spawn, does not emit if 0
2309
- * @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
2310
2459
  * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
2311
2460
  * @param {Color} [colorStartA=(1,1,1,1)] - Color at start of life 1, randomized between start colors
2312
2461
  * @param {Color} [colorStartB=(1,1,1,1)] - Color at start of life 2, randomized between start colors
2313
2462
  * @param {Color} [colorEndA=(1,1,1,0)] - Color at end of life 1, randomized between end colors
2314
2463
  * @param {Color} [colorEndB=(1,1,1,0)] - Color at end of life 2, randomized between end colors
2315
- * @param {Number} [particleTime] - How long particles live
2316
- * @param {Number} [sizeStart] - How big are particles at start
2317
- * @param {Number} [sizeEnd] - How big are particles at end
2318
- * @param {Number} [speed] - How fast are particles when spawned
2319
- * @param {Number} [angleSpeed] - How fast are particles rotating
2320
- * @param {Number} [damping] - How much to dampen particle speed
2321
- * @param {Number} [angleDamping] - How much to dampen particle angular speed
2322
- * @param {Number} [gravityScale] - How much gravity effect particles
2323
- * @param {Number} [particleConeAngle] - Cone for start particle angle
2324
- * @param {Number} [fadeRate] - How quick to fade particles at start/end in percent of life
2325
- * @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
2326
2475
  * @param {boolean} [collideTiles] - Do particles collide against tiles
2327
2476
  * @param {boolean} [additive] - Should particles use additive blend
2328
2477
  * @param {boolean} [randomColorLinear] - Should color be randomized linearly or across each component
2329
- * @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)
2330
2479
  * @param {boolean} [localSpace] - Should it be in local space of emitter (world space is default)
2331
2480
  */
2332
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);
2333
- /** @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) */
2334
2483
  emitSize: number | Vector2;
2335
- /** @property {Number} - How long to stay alive (0 is forever) */
2484
+ /** @property {number} - How long to stay alive (0 is forever) */
2336
2485
  emitTime: number;
2337
- /** @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 */
2338
2487
  emitRate: number;
2339
- /** @property {Number} - Local angle to apply velocity to particles from emitter */
2488
+ /** @property {number} - Local angle to apply velocity to particles from emitter */
2340
2489
  emitConeAngle: number;
2341
2490
  /** @property {Color} - Color at start of life 1, randomized between start colors */
2342
2491
  colorStartA: Color;
@@ -2348,33 +2497,33 @@ declare module "littlejsengine" {
2348
2497
  colorEndB: Color;
2349
2498
  /** @property {boolean} - Should color be randomized linearly or across each component */
2350
2499
  randomColorLinear: boolean;
2351
- /** @property {Number} - How long particles live */
2500
+ /** @property {number} - How long particles live */
2352
2501
  particleTime: number;
2353
- /** @property {Number} - How big are particles at start */
2502
+ /** @property {number} - How big are particles at start */
2354
2503
  sizeStart: number;
2355
- /** @property {Number} - How big are particles at end */
2504
+ /** @property {number} - How big are particles at end */
2356
2505
  sizeEnd: number;
2357
- /** @property {Number} - How fast are particles when spawned */
2506
+ /** @property {number} - How fast are particles when spawned */
2358
2507
  speed: number;
2359
- /** @property {Number} - How fast are particles rotating */
2508
+ /** @property {number} - How fast are particles rotating */
2360
2509
  angleSpeed: number;
2361
- /** @property {Number} - Cone for start particle angle */
2510
+ /** @property {number} - Cone for start particle angle */
2362
2511
  particleConeAngle: number;
2363
- /** @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 */
2364
2513
  fadeRate: number;
2365
- /** @property {Number} - Apply extra randomness percent */
2514
+ /** @property {number} - Apply extra randomness percent */
2366
2515
  randomness: number;
2367
2516
  /** @property {boolean} - Should particles use additive blend */
2368
2517
  additive: boolean;
2369
2518
  /** @property {boolean} - Should it be in local space of emitter */
2370
2519
  localSpace: boolean;
2371
- /** @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 */
2372
2521
  trailScale: number;
2373
2522
  /** @property {Function} - Callback when particle is destroyed */
2374
2523
  particleDestroyCallback: any;
2375
2524
  /** @property {Function} - Callback when particle is created */
2376
2525
  particleCreateCallback: any;
2377
- /** @property {Number} - Track particle emit time */
2526
+ /** @property {number} - Track particle emit time */
2378
2527
  emitTimeBuffer: number;
2379
2528
  /** Spawn one particle
2380
2529
  * @return {Particle} */
@@ -2390,15 +2539,15 @@ declare module "littlejsengine" {
2390
2539
  * Typically this is created automatically by a ParticleEmitter
2391
2540
  * @param {Vector2} position - World space position of the particle
2392
2541
  * @param {TileInfo} tileInfo - Tile info to render particles
2393
- * @param {Number} angle - Angle to rotate the particle
2542
+ * @param {number} angle - Angle to rotate the particle
2394
2543
  * @param {Color} colorStart - Color at start of life
2395
2544
  * @param {Color} colorEnd - Color at end of life
2396
- * @param {Number} lifeTime - How long to live for
2397
- * @param {Number} sizeStart - Size at start of life
2398
- * @param {Number} sizeEnd - Size at end of life
2399
- * @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
2400
2549
  * @param {boolean} additive - Does it use additive blend mode
2401
- * @param {Number} trailScale - If a trail, how long to make it
2550
+ * @param {number} trailScale - If a trail, how long to make it
2402
2551
  * @param {ParticleEmitter} [localSpaceEmitter] - Parent emitter if local space
2403
2552
  * @param {Function} [destroyCallback] - Callback when particle dies
2404
2553
  */
@@ -2407,17 +2556,17 @@ declare module "littlejsengine" {
2407
2556
  colorStart: Color;
2408
2557
  /** @property {Color} - Calculated change in color */
2409
2558
  colorEndDelta: Color;
2410
- /** @property {Number} - How long to live for */
2559
+ /** @property {number} - How long to live for */
2411
2560
  lifeTime: number;
2412
- /** @property {Number} - Size at start of life */
2561
+ /** @property {number} - Size at start of life */
2413
2562
  sizeStart: number;
2414
- /** @property {Number} - Calculated change in size */
2563
+ /** @property {number} - Calculated change in size */
2415
2564
  sizeEndDelta: number;
2416
- /** @property {Number} - How quick to fade in/out */
2565
+ /** @property {number} - How quick to fade in/out */
2417
2566
  fadeRate: number;
2418
2567
  /** @property {boolean} - Is it additive */
2419
2568
  additive: boolean;
2420
- /** @property {Number} - If a trail, how long to make it */
2569
+ /** @property {number} - If a trail, how long to make it */
2421
2570
  trailScale: number;
2422
2571
  /** @property {ParticleEmitter} - Parent emitter if local space */
2423
2572
  localSpaceEmitter: ParticleEmitter;
@@ -2443,7 +2592,7 @@ declare module "littlejsengine" {
2443
2592
  /** Initialize medals with a save name used for storage
2444
2593
  * - Call this after creating all medals
2445
2594
  * - Checks if medals are unlocked
2446
- * @param {String} saveName
2595
+ * @param {string} saveName
2447
2596
  * @memberof Medals */
2448
2597
  export function medalsInit(saveName: string): void;
2449
2598
  /**
@@ -2460,20 +2609,20 @@ declare module "littlejsengine" {
2460
2609
  */
2461
2610
  export class Medal {
2462
2611
  /** Create a medal object and adds it to the list of medals
2463
- * @param {Number} id - The unique identifier of the medal
2464
- * @param {String} name - Name of the medal
2465
- * @param {String} [description] - Description of the medal
2466
- * @param {String} [icon] - Icon for the medal
2467
- * @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
2468
2617
  */
2469
2618
  constructor(id: number, name: string, description?: string, icon?: string, src?: string);
2470
- /** @property {Number} - The unique identifier of the medal */
2619
+ /** @property {number} - The unique identifier of the medal */
2471
2620
  id: number;
2472
- /** @property {String} - Name of the medal */
2621
+ /** @property {string} - Name of the medal */
2473
2622
  name: string;
2474
- /** @property {String} - Description of the medal */
2623
+ /** @property {string} - Description of the medal */
2475
2624
  description: string;
2476
- /** @property {String} - Icon for the medal */
2625
+ /** @property {string} - Icon for the medal */
2477
2626
  icon: string;
2478
2627
  /** @property {boolean} - Is the medal unlocked? */
2479
2628
  unlocked: boolean;
@@ -2481,12 +2630,12 @@ declare module "littlejsengine" {
2481
2630
  /** Unlocks a medal if not already unlocked */
2482
2631
  unlock(): void;
2483
2632
  /** Render a medal
2484
- * @param {Number} [hidePercent] - How much to slide the medal off screen
2633
+ * @param {number} [hidePercent] - How much to slide the medal off screen
2485
2634
  */
2486
2635
  render(hidePercent?: number): void;
2487
2636
  /** Render the icon for a medal
2488
2637
  * @param {Vector2} pos - Screen space position
2489
- * @param {Number} size - Screen space size
2638
+ * @param {number} size - Screen space size
2490
2639
  */
2491
2640
  renderIcon(pos: Vector2, size: number): void;
2492
2641
  storageKey(): string;
@@ -2536,7 +2685,7 @@ declare module "littlejsengine" {
2536
2685
  * @param {number} id - The scoreboard id
2537
2686
  * @param {string} [user] - A user's id or name
2538
2687
  * @param {number} [social] - If true, only social scores will be loaded
2539
- * @param {number} [skip] - Number of scores to skip before start
2688
+ * @param {number} [skip] - Number of scores to skip over
2540
2689
  * @param {number} [limit] - Number of scores to include in the list
2541
2690
  * @return {Object} - The response JSON object
2542
2691
  */
@@ -2624,9 +2773,9 @@ declare module "littlejsengine" {
2624
2773
  */
2625
2774
  constructor(zzfxMusic: [any[], any[], any[], number]);
2626
2775
  sampleChannels: any[];
2627
- /** Play the music
2628
- * @param {number} [volume=1] - How much to scale volume by
2629
- * @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?
2630
2779
  * @return {AudioBufferSourceNode} - The audio source node
2631
2780
  */
2632
2781
  playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
@@ -2688,7 +2837,7 @@ declare module "littlejsengine" {
2688
2837
  * @param {Color} [color=uiSystem.defaultColor]
2689
2838
  * @param {number} [lineWidth=uiSystem.defaultLineWidth]
2690
2839
  * @param {Color} [lineColor=uiSystem.defaultLineColor]
2691
- * @param {number} [lineWidth=uiSystem.defaultCornerRadius] */
2840
+ * @param {number} [cornerRadius=uiSystem.defaultCornerRadius] */
2692
2841
  drawRect(pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, cornerRadius?: number): void;
2693
2842
  /** Draw a line to the UI context
2694
2843
  * @param {Vector2} posA
@@ -2730,27 +2879,35 @@ declare module "littlejsengine" {
2730
2879
  pos: Vector2;
2731
2880
  /** @property {Vector2} - Screen space size of the object */
2732
2881
  size: Vector2;
2733
- /** @property {Color} - color of the object */
2882
+ /** @property {Color} - Color of the object */
2734
2883
  color: Color;
2735
- /** @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 */
2736
2891
  textColor: Color;
2737
- /** @property {Color} - color used when hovering over the object */
2892
+ /** @property {Color} - Color used when hovering over the object */
2738
2893
  hoverColor: Color;
2739
- /** @property {Color} - color for line drawing */
2894
+ /** @property {Color} - Color for line drawing */
2740
2895
  lineColor: Color;
2741
- /** @property {number} - width for line drawing */
2896
+ /** @property {number} - Width for line drawing */
2742
2897
  lineWidth: number;
2743
- /** @property {string} - font for this objecct */
2898
+ /** @property {number} - Corner radius for rounded rects */
2899
+ cornerRadius: number;
2900
+ /** @property {string} - Font for this objecct */
2744
2901
  font: string;
2745
- /** @property {number} - override for text height */
2902
+ /** @property {number} - Override for text height */
2746
2903
  textHeight: any;
2747
- /** @property {boolean} - should this object be drawn */
2904
+ /** @property {boolean} - Should this object be drawn */
2748
2905
  visible: boolean;
2749
- /** @property {Array<UIObject>} - a list of this object's children */
2906
+ /** @property {Array<UIObject>} - A list of this object's children */
2750
2907
  children: any[];
2751
- /** @property {UIObject} - this object's parent, position is in parent space */
2908
+ /** @property {UIObject} - This object's parent, position is in parent space */
2752
2909
  parent: any;
2753
- /** @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 */
2754
2911
  extraTouchSize: number;
2755
2912
  /** @property {Sound} - Sound when interactive element is pressed */
2756
2913
  soundPress: any;
@@ -2776,7 +2933,7 @@ declare module "littlejsengine" {
2776
2933
  update(): void;
2777
2934
  /** Render the object, called automatically by plugin once each frame */
2778
2935
  render(): void;
2779
- /** Special update for when object is invisible */
2936
+ /** Special update when object is not visible */
2780
2937
  updateInvisible(): void;
2781
2938
  /** Called when the mouse enters the object */
2782
2939
  onEnter(): void;
@@ -2804,9 +2961,7 @@ declare module "littlejsengine" {
2804
2961
  * @param {string} [font=uiSystem.defaultFont]
2805
2962
  */
2806
2963
  constructor(pos?: Vector2, size?: Vector2, text?: string, align?: string, font?: string);
2807
- /** @property {string} */
2808
2964
  text: string;
2809
- /** @property {string} */
2810
2965
  align: string;
2811
2966
  }
2812
2967
  /**
@@ -2842,12 +2997,7 @@ declare module "littlejsengine" {
2842
2997
  * @param {Color} [color=uiSystem.defaultButtonColor]
2843
2998
  */
2844
2999
  constructor(pos?: Vector2, size?: Vector2, text?: string, color?: Color);
2845
- /** @property {string} */
2846
3000
  text: string;
2847
- /** @property {Color} */
2848
- disabledColor: Color;
2849
- /** @property {boolean} */
2850
- disabled: boolean;
2851
3001
  }
2852
3002
  /**
2853
3003
  * UICheckbox - A UI object that acts as a checkbox
@@ -2858,10 +3008,13 @@ declare module "littlejsengine" {
2858
3008
  * @param {Vector2} [pos]
2859
3009
  * @param {Vector2} [size]
2860
3010
  * @param {boolean} [checked]
3011
+ * @param {string} [text]
3012
+ * @param {Color} [color=uiSystem.defaultButtonColor]
2861
3013
  */
2862
- constructor(pos?: Vector2, size?: Vector2, checked?: boolean);
2863
- /** @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 */
2864
3016
  checked: boolean;
3017
+ text: string;
2865
3018
  }
2866
3019
  /**
2867
3020
  * UIScrollbar - A UI object that acts as a scrollbar
@@ -2877,12 +3030,11 @@ declare module "littlejsengine" {
2877
3030
  * @param {Color} [handleColor=WHITE]
2878
3031
  */
2879
3032
  constructor(pos?: Vector2, size?: Vector2, value?: number, text?: string, color?: Color, handleColor?: Color);
2880
- /** @property {number} */
3033
+ /** @property {number} - Current percentage value of this scrollbar 0-1 */
2881
3034
  value: number;
2882
- /** @property {string} */
2883
- text: string;
2884
- /** @property {Color} */
3035
+ /** @property {Color} - Color for the handle part of the scrollbar */
2885
3036
  handleColor: Color;
3037
+ text: string;
2886
3038
  }
2887
3039
  /**
2888
3040
  * LittleJS Box2D Physics Plugin
@@ -2912,7 +3064,9 @@ declare module "littlejsengine" {
2912
3064
  * @param {boolean} enable
2913
3065
  * @memberof Box2D */
2914
3066
  export function box2dSetDebug(enable: boolean): void;
2915
- /** 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();
2916
3070
  * @return {Promise<Box2dPlugin>}
2917
3071
  * @memberof Box2D */
2918
3072
  export function box2dInit(): Promise<Box2dPlugin>;
@@ -2972,42 +3126,10 @@ declare module "littlejsengine" {
2972
3126
  * @param {Vector2} pos
2973
3127
  * @param {number} angle
2974
3128
  * @param {Color} [color]
2975
- * @param {Color} [outlineColor]
2976
- * @param {number} [lineWidth]
2977
- * @param {CanvasRenderingContext2D} [context] */
2978
- drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2979
- /** draws a circle
2980
- * @param {Vector2} pos
2981
- * @param {number} radius
2982
- * @param {Color} [color]
2983
- * @param {Color} [outlineColor]
3129
+ * @param {Color} [lineColor]
2984
3130
  * @param {number} [lineWidth]
2985
3131
  * @param {CanvasRenderingContext2D} [context] */
2986
- drawCircle(pos: Vector2, radius: number, color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2987
- /** draws a polygon
2988
- * @param {Vector2} pos
2989
- * @param {number} angle
2990
- * @param {Array<Vector2>} points
2991
- * @param {Color} [color]
2992
- * @param {Color} [outlineColor]
2993
- * @param {number} [lineWidth]
2994
- * @param {CanvasRenderingContext2D} [context] */
2995
- drawPoly(pos: Vector2, angle: number, points: Array<Vector2>, color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2996
- /** draws a line
2997
- * @param {Vector2} pos
2998
- * @param {number} angle
2999
- * @param {Vector2} posA
3000
- * @param {Vector2} posB
3001
- * @param {Color} [color]
3002
- * @param {number} [lineWidth]
3003
- * @param {CanvasRenderingContext2D} [context] */
3004
- drawLine(pos: Vector2, angle: number, posA: Vector2, posB: Vector2, color?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3005
- /** performs a fill or stroke as a helper to the other draw functions
3006
- * @param {Color} [color]
3007
- * @param {Color} [outlineColor]
3008
- * @param {number} [lineWidth]
3009
- * @param {CanvasRenderingContext2D} [context] */
3010
- drawFillStroke(color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3132
+ drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3011
3133
  /** converts a box2d vec2 to a Vector2
3012
3134
  * @param {Object} v */
3013
3135
  vec2From(v: any): Vector2;
@@ -3042,13 +3164,13 @@ declare module "littlejsengine" {
3042
3164
  * @param {number} [renderOrder] */
3043
3165
  constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, bodyType?: number, renderOrder?: number);
3044
3166
  body: any;
3045
- outlineColor: Color;
3167
+ lineColor: Color;
3046
3168
  /** Draws all this object's fixtures
3047
3169
  * @param {Color} [color]
3048
- * @param {Color} [outlineColor]
3170
+ * @param {Color} [lineColor]
3049
3171
  * @param {number} [lineWidth]
3050
3172
  * @param {CanvasRenderingContext2D} [context] */
3051
- drawFixtures(color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3173
+ drawFixtures(color?: Color, lineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3052
3174
  /** Called when a contact begins
3053
3175
  * @param {Box2dObject} otherObject */
3054
3176
  beginContact(otherObject: Box2dObject): void;
@@ -3792,19 +3914,20 @@ declare module "littlejsengine" {
3792
3914
  getCorrectionFactor(): number;
3793
3915
  }
3794
3916
  /** Draw a scalable nine-slice UI element in world space
3795
- * 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
3796
3918
  * @param {Vector2} pos - World space position
3797
3919
  * @param {Vector2} size - World space size
3798
3920
  * @param {TileInfo} startTile - Starting tile for the nine-slice pattern
3799
3921
  * @param {Color} [color] - Color to modulate with
3800
- * @param {number} [borderSize=1] - Width of the border sections
3922
+ * @param {number} [borderSize] - Width of the border sections
3801
3923
  * @param {Color} [additiveColor] - Additive color
3802
- * @param {number} [extraSpace=.01] - Extra spacing adjustment
3924
+ * @param {number} [extraSpace] - Extra spacing adjustment
3925
+ * @param {number} [angle] - Angle to rotate by
3803
3926
  * @param {boolean} [useWebGL=glEnable] - Use WebGL for rendering
3804
3927
  * @param {boolean} [screenSpace] - Use screen space coordinates
3805
3928
  * @param {CanvasRenderingContext2D} [context] - Canvas context to use
3806
3929
  * @memberof DrawUtilities */
3807
- export function drawNineSlice(pos: Vector2, size: Vector2, startTile: TileInfo, color?: Color, borderSize?: number, additiveColor?: Color, extraSpace?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
3930
+ export function drawNineSlice(pos: Vector2, size: Vector2, startTile: TileInfo, color?: Color, borderSize?: number, additiveColor?: Color, extraSpace?: number, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
3808
3931
  /**
3809
3932
  * LittleJS Drawing Utilities Plugin
3810
3933
  * - Extra drawing functions for LittleJS
@@ -3816,31 +3939,34 @@ declare module "littlejsengine" {
3816
3939
  * @param {Vector2} pos - Screen space position
3817
3940
  * @param {Vector2} size - Screen space size
3818
3941
  * @param {TileInfo} startTile - Starting tile for the nine-slice pattern
3819
- * @param {number} [borderSize=1] - Width of the border sections
3820
- * @param {number} [extraSpace=.01] - Extra spacing adjustment
3942
+ * @param {number} [borderSize] - Width of the border sections
3943
+ * @param {number} [extraSpace] - Extra spacing adjustment
3944
+ * @param {number} [angle] - Angle to rotate by
3821
3945
  * @memberof DrawUtilities */
3822
- export function drawNineSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number): void;
3946
+ export function drawNineSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number, angle?: number): void;
3823
3947
  /** Draw a scalable three-slice UI element in world space
3824
- * 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
3825
3949
  * @param {Vector2} pos - World space position
3826
3950
  * @param {Vector2} size - World space size
3827
3951
  * @param {TileInfo} startTile - Starting tile for the three-slice pattern
3828
3952
  * @param {Color} [color] - Color to modulate with
3829
- * @param {number} [borderSize=1] - Width of the border sections
3953
+ * @param {number} [borderSize] - Width of the border sections
3830
3954
  * @param {Color} [additiveColor] - Additive color
3831
- * @param {number} [extraSpace=.01] - Extra spacing adjustment
3955
+ * @param {number} [extraSpace] - Extra spacing adjustment
3956
+ * @param {number} [angle] - Angle to rotate by
3832
3957
  * @param {boolean} [useWebGL=glEnable] - Use WebGL for rendering
3833
3958
  * @param {boolean} [screenSpace] - Use screen space coordinates
3834
3959
  * @param {CanvasRenderingContext2D} [context] - Canvas context to use
3835
3960
  * @memberof DrawUtilities */
3836
- export function drawThreeSlice(pos: Vector2, size: Vector2, startTile: TileInfo, color?: Color, borderSize?: number, additiveColor?: Color, extraSpace?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
3961
+ 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;
3837
3962
  /** Draw a scalable three-slice UI element to the overlay canvas in screen space
3838
3963
  * This function can not apply color because it draws using the overlay 2d context
3839
3964
  * @param {Vector2} pos - Screen space position
3840
3965
  * @param {Vector2} size - Screen space size
3841
3966
  * @param {TileInfo} startTile - Starting tile for the three-slice pattern
3842
- * @param {number} [borderSize=1] - Width of the border sections
3843
- * @param {number} [extraSpace=.01] - Extra spacing adjustment
3967
+ * @param {number} [borderSize] - Width of the border sections
3968
+ * @param {number} [extraSpace] - Extra spacing adjustment
3969
+ * @param {number} [angle] - Angle to rotate by
3844
3970
  * @memberof DrawUtilities */
3845
- export function drawThreeSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number): void;
3971
+ export function drawThreeSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number, angle?: number): void;
3846
3972
  }