littlejsengine 1.11.13 → 1.12.4

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 (79) hide show
  1. package/dist/littlejs.d.ts +1418 -109
  2. package/dist/littlejs.esm.js +3495 -581
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +3258 -399
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +3147 -379
  7. package/examples/box2d/game.js +73 -45
  8. package/examples/box2d/gameObjects.js +96 -92
  9. package/examples/box2d/index.html +2 -7
  10. package/examples/box2d/scenes.js +82 -92
  11. package/examples/breakout/game.js +62 -30
  12. package/examples/breakout/gameObjects.js +45 -47
  13. package/examples/breakout/index.html +1 -5
  14. package/examples/breakoutTutorial/game.js +36 -29
  15. package/examples/breakoutTutorial/index.html +1 -3
  16. package/examples/empty/game.js +5 -2
  17. package/examples/empty/index.html +1 -3
  18. package/examples/htmlMenu/game.js +25 -19
  19. package/examples/htmlMenu/index.html +5 -7
  20. package/examples/index.html +2 -3
  21. package/examples/module/game.js +32 -34
  22. package/examples/module/index.html +1 -1
  23. package/examples/particles/index.html +27 -22
  24. package/examples/platformer/game.js +71 -48
  25. package/examples/platformer/gameCharacter.js +42 -34
  26. package/examples/platformer/gameEffects.js +82 -75
  27. package/examples/platformer/gameLevel.js +67 -38
  28. package/examples/platformer/{gameLevelData.js → gameLevelData.json} +1 -11
  29. package/examples/platformer/gameObjects.js +70 -64
  30. package/examples/platformer/gamePlayer.js +12 -7
  31. package/examples/platformer/index.html +1 -9
  32. package/examples/puzzle/game.js +58 -42
  33. package/examples/puzzle/index.html +1 -3
  34. package/examples/shorts/base.html +2 -2
  35. package/examples/shorts/particles.js +1 -1
  36. package/examples/shorts/platformer.js +1 -1
  37. package/examples/shorts/tileLayer.js +5 -6
  38. package/examples/shorts/tiles.png +0 -0
  39. package/examples/starter/build.js +4 -4
  40. package/examples/starter/game.js +9 -12
  41. package/examples/starter/index.html +13 -13
  42. package/examples/stress/index.html +44 -43
  43. package/examples/typescript/build.js +17 -18
  44. package/examples/typescript/game.js +32 -34
  45. package/examples/typescript/game.ts +32 -34
  46. package/examples/typescript/index.html +1 -1
  47. package/examples/uiSystem/game.js +33 -36
  48. package/examples/uiSystem/index.html +1 -5
  49. package/package.json +3 -3
  50. package/plugins/box2d.js +1556 -640
  51. package/plugins/{Box2D_v2.3.1_min.wasm.js → box2d.wasm.js} +1 -1
  52. package/plugins/newgrounds.js +7 -8
  53. package/plugins/pluginExport.js +50 -0
  54. package/plugins/postProcess.js +94 -93
  55. package/plugins/uiSystem.js +145 -161
  56. package/plugins/zzfxm.js +163 -0
  57. package/reference.md +29 -27
  58. package/src/engine.js +15 -20
  59. package/src/engineAudio.js +74 -204
  60. package/src/engineBuild.js +29 -4
  61. package/src/engineDebug.js +105 -9
  62. package/src/engineDraw.js +27 -14
  63. package/src/engineExport.js +12 -8
  64. package/src/engineInput.js +3 -1
  65. package/src/engineObject.js +18 -14
  66. package/src/engineParticles.js +6 -1
  67. package/src/engineRelease.js +6 -1
  68. package/src/engineSettings.js +8 -8
  69. package/src/engineTileLayer.js +179 -96
  70. package/src/engineUtilities.js +5 -11
  71. package/src/engineWebGL.js +19 -7
  72. package/examples/starter/build/index.html +0 -2
  73. package/examples/starter/build/index.js +0 -1
  74. package/examples/starter/build/tiles.png +0 -0
  75. package/examples/starter/game.zip +0 -0
  76. package/examples/typescript/build/dist/littlejs.esm.js +0 -4834
  77. package/examples/typescript/build/examples/typescript/build.js +0 -24
  78. package/examples/typescript/build/examples/typescript/game.js +0 -102
  79. /package/plugins/{Box2D_v2.3.1_min.wasm.wasm → box2d.wasm.wasm} +0 -0
@@ -216,6 +216,18 @@ declare module "littlejsengine" {
216
216
  * @param {string} filename
217
217
  * @memberof Debug */
218
218
  export function debugSaveDataURL(dataURL: string, filename: string): void;
219
+ /** Show error as full page of red text
220
+ * @memberof Debug */
221
+ export function debugShowErrors(): void;
222
+ /** Check if video capture is active
223
+ * @memberof Debug */
224
+ export function debugVideoCaptureIsActive(): boolean;
225
+ /** Start capturing video
226
+ * @memberof Debug */
227
+ export function debugVideoCaptureStart(): void;
228
+ /** Stop capturing video and save to disk
229
+ * @memberof Debug */
230
+ export function debugVideoCaptureStop(): void;
219
231
  /**
220
232
  * LittleJS Engine Settings
221
233
  * - All settings for the engine are here
@@ -242,7 +254,7 @@ declare module "littlejsengine" {
242
254
  * @default Vector2()
243
255
  * @memberof Settings */
244
256
  export let canvasFixedSize: Vector2;
245
- /** Use nearest neighbor scaling algorithm for canvas for more pixelated look
257
+ /** Use nearest neighbor canvas scaling for more pixelated look
246
258
  * - Must be set before startup to take effect
247
259
  * - If enabled sets css image-rendering:pixelated
248
260
  * @type {boolean}
@@ -315,11 +327,11 @@ declare module "littlejsengine" {
315
327
  * @default
316
328
  * @memberof Settings */
317
329
  export let objectMaxSpeed: number;
318
- /** How much gravity to apply to objects along the Y axis, negative is down
319
- * @type {number}
330
+ /** How much gravity to apply to objects, negative Y is down
331
+ * @type {Vector2}
320
332
  * @default
321
333
  * @memberof Settings */
322
- export let gravity: number;
334
+ export let gravity: Vector2;
323
335
  /** Scales emit rate of particles, useful for low graphics mode (0 disables particle emitters)
324
336
  * @type {number}
325
337
  * @default
@@ -494,10 +506,10 @@ declare module "littlejsengine" {
494
506
  * @param {number} speed
495
507
  * @memberof Settings */
496
508
  export function setObjectMaxSpeed(speed: number): void;
497
- /** Set how much gravity to apply to objects along the Y axis
498
- * @param {number} newGravity
509
+ /** Set how much gravity to apply to objects
510
+ * @param {Vector2} newGravity
499
511
  * @memberof Settings */
500
- export function setGravity(newGravity: number): void;
512
+ export function setGravity(newGravity: Vector2): void;
501
513
  /** Set to scales emit rate of particles
502
514
  * @param {number} scale
503
515
  * @memberof Settings */
@@ -1031,18 +1043,17 @@ declare module "littlejsengine" {
1031
1043
  valueOf(): number;
1032
1044
  }
1033
1045
  /**
1034
- * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
1035
- * @param {Vector2|number} [x]
1036
- * @param {number} [y]
1046
+ * Create a 2d vector, can take 1 or 2 scalar values
1047
+ * @param {number} [x]
1048
+ * @param {number} [y] - if y is undefined, x is used for both
1037
1049
  * @return {Vector2}
1038
1050
  * @example
1039
1051
  * let a = vec2(0, 1); // vector with coordinates (0, 1)
1040
- * let b = vec2(a); // copy a into b
1041
1052
  * a = vec2(5); // set a to (5, 5)
1042
1053
  * b = vec2(); // set b to (0, 0)
1043
1054
  * @memberof Utilities
1044
1055
  */
1045
- export function vec2(x?: Vector2 | number, y?: number): Vector2;
1056
+ export function vec2(x?: number, y?: number): Vector2;
1046
1057
  /**
1047
1058
  * Create a color object with RGBA values, white by default
1048
1059
  * @param {number} [r=1] - red
@@ -1180,6 +1191,8 @@ declare module "littlejsengine" {
1180
1191
  image: HTMLImageElement;
1181
1192
  /** @property {Vector2} - size of the image */
1182
1193
  size: Vector2;
1194
+ /** @property {Vector2} - inverse of the size, cached for rendering */
1195
+ sizeInverse: Vector2;
1183
1196
  /** @property {WebGLTexture} - webgl texture */
1184
1197
  glTexture: WebGLTexture;
1185
1198
  }
@@ -1241,7 +1254,7 @@ declare module "littlejsengine" {
1241
1254
  * @param {Color} [color=(1,1,1,1)] - Color to modulate with
1242
1255
  * @param {number} [angle] - Angle to rotate by
1243
1256
  * @param {boolean} [mirror] - If true image is flipped along the Y axis
1244
- * @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
1257
+ * @param {Color} [additiveColor] - Additive color to be applied if any
1245
1258
  * @param {boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1246
1259
  * @param {boolean} [screenSpace=false] - If true the pos and size are in screen space
1247
1260
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
@@ -1455,6 +1468,11 @@ declare module "littlejsengine" {
1455
1468
  * @return {WebGLTexture}
1456
1469
  * @memberof WebGL */
1457
1470
  export function glCreateTexture(image: HTMLImageElement): WebGLTexture;
1471
+ /** Set WebGL texture data from an image
1472
+ * @param {WebGLTexture} texture
1473
+ * @param {HTMLImageElement} image
1474
+ * @memberof WebGL */
1475
+ export function glSetTextureData(texture: WebGLTexture, image: HTMLImageElement): void;
1458
1476
  /** Add a sprite to the gl draw list, used by all gl draw functions
1459
1477
  * @param {Number} x
1460
1478
  * @param {Number} y
@@ -1465,10 +1483,10 @@ declare module "littlejsengine" {
1465
1483
  * @param {Number} uv0Y
1466
1484
  * @param {Number} uv1X
1467
1485
  * @param {Number} uv1Y
1468
- * @param {Number} rgba
1469
- * @param {Number} [rgbaAdditive=0]
1486
+ * @param {Number} [rgba=-1] - white is -1
1487
+ * @param {Number} [rgbaAdditive=0] - black is 0
1470
1488
  * @memberof WebGL */
1471
- 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;
1489
+ 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;
1472
1490
  /** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
1473
1491
  * @memberof WebGL */
1474
1492
  export function glFlush(): void;
@@ -1574,6 +1592,15 @@ declare module "littlejsengine" {
1574
1592
  * @type {boolean}
1575
1593
  * @memberof Input */
1576
1594
  export let isUsingGamepad: boolean;
1595
+ /** Prevents input continuing to the default browser handling (true by default)
1596
+ * @type {boolean}
1597
+ * @memberof Input */
1598
+ export let inputPreventDefault: boolean;
1599
+ /** Prevents input continuing to the default browser handling
1600
+ * This is useful to disable for html menus so the browser can handle input normally
1601
+ * @param {boolean} preventDefault
1602
+ * @memberof Input */
1603
+ export function setInputPreventDefault(preventDefault: boolean): void;
1577
1604
  /** Returns true if gamepad button is down
1578
1605
  * @param {number} button
1579
1606
  * @param {number} [gamepad]
@@ -1692,49 +1719,6 @@ declare module "littlejsengine" {
1692
1719
  */
1693
1720
  constructor(filename: string, randomness?: number, range?: number, taper?: number, onloadCallback?: Function);
1694
1721
  }
1695
- /**
1696
- * Music Object - Stores a zzfx music track for later use
1697
- *
1698
- * <a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a>
1699
- * @example
1700
- * // create some music
1701
- * const music_example = new Music(
1702
- * [
1703
- * [ // instruments
1704
- * [,0,400] // simple note
1705
- * ],
1706
- * [ // patterns
1707
- * [ // pattern 1
1708
- * [ // channel 0
1709
- * 0, -1, // instrument 0, left speaker
1710
- * 1, 0, 9, 1 // channel notes
1711
- * ],
1712
- * [ // channel 1
1713
- * 0, 1, // instrument 0, right speaker
1714
- * 0, 12, 17, -1 // channel notes
1715
- * ]
1716
- * ],
1717
- * ],
1718
- * [0, 0, 0, 0], // sequence, play pattern 0 four times
1719
- * 90 // BPM
1720
- * ]);
1721
- *
1722
- * // play the music
1723
- * music_example.play();
1724
- */
1725
- export class Music extends Sound {
1726
- /** Create a music object and cache the zzfx music samples for later use
1727
- * @param {[Array, Array, Array, number]} zzfxMusic - Array of zzfx music parameters
1728
- */
1729
- constructor(zzfxMusic: [any[], any[], any[], number]);
1730
- sampleChannels: any[];
1731
- /** Play the music
1732
- * @param {number} [volume=1] - How much to scale volume by
1733
- * @param {boolean} [loop] - True if the music should loop
1734
- * @return {AudioBufferSourceNode} - The audio source node
1735
- */
1736
- playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
1737
- }
1738
1722
  /** Play an mp3, ogg, or wav audio from a local file or url
1739
1723
  * @param {string} filename - Location of sound file to play
1740
1724
  * @param {number} [volume] - How much to scale volume by
@@ -1760,20 +1744,6 @@ declare module "littlejsengine" {
1760
1744
  * @return {number} - The frequency of the note
1761
1745
  * @memberof Audio */
1762
1746
  export function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1763
- /**
1764
- * LittleJS Audio System
1765
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1766
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1767
- * - Caches sounds and music for fast playback
1768
- * - Can attenuate and apply stereo panning to sounds
1769
- * - Ability to play mp3, ogg, and wave files
1770
- * - Speech synthesis functions
1771
- * @namespace Audio
1772
- */
1773
- /** Audio context used by the engine
1774
- * @type {AudioContext}
1775
- * @memberof Audio */
1776
- export let audioContext: AudioContext;
1777
1747
  /** Play cached audio samples with given settings
1778
1748
  * @param {Array} sampleChannels - Array of arrays of samples to play (for stereo playback)
1779
1749
  * @param {number} [volume] - How much to scale volume by
@@ -1792,6 +1762,50 @@ declare module "littlejsengine" {
1792
1762
  * @return {AudioBufferSourceNode} - The audio node of the sound played
1793
1763
  * @memberof Audio */
1794
1764
  export function zzfx(...zzfxSound: any[]): AudioBufferSourceNode;
1765
+ /** Generate samples for a ZzFX sound
1766
+ * @param {number} [volume] - Volume scale (percent)
1767
+ * @param {number} [randomness] - How much to randomize frequency (percent Hz)
1768
+ * @param {number} [frequency] - Frequency of sound (Hz)
1769
+ * @param {number} [attack] - Attack time, how fast sound starts (seconds)
1770
+ * @param {number} [sustain] - Sustain time, how long sound holds (seconds)
1771
+ * @param {number} [release] - Release time, how fast sound fades out (seconds)
1772
+ * @param {number} [shape] - Shape of the sound wave
1773
+ * @param {number} [shapeCurve] - Squareness of wave (0=square, 1=normal, 2=pointy)
1774
+ * @param {number} [slide] - How much to slide frequency (kHz/s)
1775
+ * @param {number} [deltaSlide] - How much to change slide (kHz/s/s)
1776
+ * @param {number} [pitchJump] - Frequency of pitch jump (Hz)
1777
+ * @param {number} [pitchJumpTime] - Time of pitch jump (seconds)
1778
+ * @param {number} [repeatTime] - Resets some parameters periodically (seconds)
1779
+ * @param {number} [noise] - How much random noise to add (percent)
1780
+ * @param {number} [modulation] - Frequency of modulation wave, negative flips phase (Hz)
1781
+ * @param {number} [bitCrush] - Resamples at a lower frequency in (samples*100)
1782
+ * @param {number} [delay] - Overlap sound with itself for reverb and flanger effects (seconds)
1783
+ * @param {number} [sustainVolume] - Volume level for sustain (percent)
1784
+ * @param {number} [decay] - Decay time, how long to reach sustain after attack (seconds)
1785
+ * @param {number} [tremolo] - Trembling effect, rate controlled by repeat time (percent)
1786
+ * @param {number} [filter] - Filter cutoff frequency, positive for HPF, negative for LPF (Hz)
1787
+ * @return {Array} - Array of audio samples
1788
+ * @memberof Audio
1789
+ */
1790
+ 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[];
1791
+ /** Sample rate used for all ZzFX sounds
1792
+ * @default 44100
1793
+ * @memberof Audio */
1794
+ export const zzfxR: 44100;
1795
+ /**
1796
+ * LittleJS Audio System
1797
+ * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1798
+ * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1799
+ * - Caches sounds and music for fast playback
1800
+ * - Can attenuate and apply stereo panning to sounds
1801
+ * - Ability to play mp3, ogg, and wave files
1802
+ * - Speech synthesis functions
1803
+ * @namespace Audio
1804
+ */
1805
+ /** Audio context used by the engine
1806
+ * @type {AudioContext}
1807
+ * @memberof Audio */
1808
+ export let audioContext: AudioContext;
1795
1809
  /**
1796
1810
  * LittleJS Object System
1797
1811
  */
@@ -1871,7 +1885,7 @@ declare module "littlejsengine" {
1871
1885
  /** @property {boolean} - Limit object speed using linear or circular math */
1872
1886
  clampSpeedLinear: boolean;
1873
1887
  /** @property {EngineObject} - Object we are standing on, if any */
1874
- groundObject: any;
1888
+ groundObject: EngineObject | TileCollisionLayer;
1875
1889
  /** @property {EngineObject} - Parent of object if in local space */
1876
1890
  parent: any;
1877
1891
  /** @property {Vector2} - Local position if child */
@@ -1953,42 +1967,27 @@ declare module "littlejsengine" {
1953
1967
  * LittleJS Tile Layer System
1954
1968
  * - Caches arrays of tiles to off screen canvas for fast rendering
1955
1969
  * - Unlimited numbers of layers, allocates canvases as needed
1956
- * - Interfaces with EngineObject for collision
1957
- * - Collision layer is separate from visible layers
1958
- * - It is recommended to have a visible layer that matches the collision
1959
1970
  * - Tile layers can be drawn to using their context with canvas2d
1960
1971
  * - Drawn directly to the main canvas without using WebGL
1972
+ * - Tile layers can also have collision with EngineObjects
1961
1973
  * @namespace TileCollision
1962
1974
  */
1963
- /** The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access
1964
- * @type {Array<number>}
1965
- * @memberof TileCollision */
1966
- export let tileCollision: Array<number>;
1967
- /** Size of the tile collision layer 2d grid
1968
- * @type {Vector2}
1969
- * @memberof TileCollision */
1970
- export let tileCollisionSize: Vector2;
1971
- /** Clear and initialize tile collision
1972
- * @param {Vector2} size - width and height of tile collision 2d grid
1975
+ /** Keep track of all tile layers with collision
1976
+ * @type {Array<TileCollisionLayer>}
1973
1977
  * @memberof TileCollision */
1974
- export function initTileCollision(size: Vector2): void;
1975
- /** Set tile collision data for a given cell in the grid
1976
- * @param {Vector2} pos
1977
- * @param {number} [data]
1978
- * @memberof TileCollision */
1979
- export function setTileCollisionData(pos: Vector2, data?: number): void;
1978
+ export let tileCollisionLayers: Array<TileCollisionLayer>;
1980
1979
  /** Get tile collision data for a given cell in the grid
1981
- * @param {Vector2} pos
1982
- * @return {number}
1983
- * @memberof TileCollision */
1980
+ * @param {Vector2} pos
1981
+ * @return {number}
1982
+ * @memberof TileCollision */
1984
1983
  export function getTileCollisionData(pos: Vector2): number;
1985
- /** Check if collision with another object should occur
1984
+ /** Check if a tile layer collides with another object
1986
1985
  * @param {Vector2} pos
1987
1986
  * @param {Vector2} [size=(0,0)]
1988
1987
  * @param {EngineObject} [object]
1989
- * @return {boolean}
1988
+ * @return {TileCollisionLayer}
1990
1989
  * @memberof TileCollision */
1991
- export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
1990
+ export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): TileCollisionLayer;
1992
1991
  /** Return the center of first tile hit, undefined if nothing was hit.
1993
1992
  * This does not return the exact intersection, but the center of the tile hit.
1994
1993
  * @param {Vector2} posStart
@@ -1998,7 +1997,7 @@ declare module "littlejsengine" {
1998
1997
  * @memberof TileCollision */
1999
1998
  export function tileCollisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
2000
1999
  /**
2001
- * Tile layer data object stores info about how to render a tile
2000
+ * Tile layer data object stores info about how to draw a tile
2002
2001
  * @example
2003
2002
  * // create tile layer data with tile index 0 and random orientation and color
2004
2003
  * const tileIndex = 0;
@@ -2030,20 +2029,18 @@ declare module "littlejsengine" {
2030
2029
  * - Each Tile layer is rendered to an off screen canvas
2031
2030
  * - To allow dynamic modifications, layers are rendered using canvas 2d
2032
2031
  * - Some devices like mobile phones are limited to 4k texture resolution
2033
- * - So with 16x16 tiles this limits layers to 256x256 on mobile devices
2032
+ * - For with 16x16 tiles this limits layers to 256x256 on mobile devices
2034
2033
  * @extends EngineObject
2035
2034
  * @example
2036
- * // create tile collision and visible tile layer
2037
- * initTileCollision(vec2(200,100));
2038
- * const tileLayer = new TileLayer();
2035
+ * const tileLayer = new TileLayer(vec2(), vec2(200,100));
2039
2036
  */
2040
2037
  export class TileLayer extends EngineObject {
2041
2038
  /** Create a tile layer object
2042
- * @param {Vector2} [position=(0,0)] - World space position
2043
- * @param {Vector2} [size=tileCollisionSize] - World space size
2044
- * @param {TileInfo} [tileInfo] - Tile info for layer
2045
- * @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
2046
- * @param {number} [renderOrder] - Objects are sorted by renderOrder
2039
+ * @param {Vector2} [position=(0,0)] - World space position
2040
+ * @param {Vector2} [size=(1,1)] - World space size
2041
+ * @param {TileInfo} [tileInfo] - Tile info for layer
2042
+ * @param {Vector2} [scale=(1,1)] - How much to scale this layer when rendered
2043
+ * @param {number} [renderOrder] - Objects are sorted by renderOrder
2047
2044
  */
2048
2045
  constructor(position?: Vector2, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
2049
2046
  /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
@@ -2104,6 +2101,48 @@ declare module "littlejsengine" {
2104
2101
  * @param {number} [angle=0] */
2105
2102
  drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2106
2103
  }
2104
+ /**
2105
+ * Tile Collision Layer - a tile layer with collision
2106
+ * - adds collision data and functions to TileLayer
2107
+ * - there can be multiple tile collision layers
2108
+ * - tile collison layers should not overlap each other
2109
+ * @extends TileLayer
2110
+ */
2111
+ export class TileCollisionLayer extends TileLayer {
2112
+ /** Create a tile layer object
2113
+ * @param {Vector2} [position=(0,0)] - World space position
2114
+ * @param {Vector2} [size=(0,0)] - World space size
2115
+ * @param {TileInfo} [tileInfo] - Tile info for layer
2116
+ * @param {number} [renderOrder] - Objects are sorted by renderOrder
2117
+ */
2118
+ constructor(position?: Vector2, size?: Vector2, tileInfo?: TileInfo, renderOrder?: number);
2119
+ /** @property {Array<number>} - The tile collision grid */
2120
+ collisionData: any[];
2121
+ /** Clear and initialize tile collision to new size
2122
+ * @param {Vector2} size - width and height of tile collision 2d grid */
2123
+ initCollision(size: Vector2): void;
2124
+ /** Set tile collision data for a given cell in the grid
2125
+ * @param {Vector2} pos
2126
+ * @param {number} [data] */
2127
+ setCollisionData(pos: Vector2, data?: number): void;
2128
+ /** Get tile collision data for a given cell in the grid
2129
+ * @param {Vector2} pos
2130
+ * @return {number} */
2131
+ getCollisionData(pos: Vector2): number;
2132
+ /** Check if collision with another object should occur
2133
+ * @param {Vector2} pos
2134
+ * @param {Vector2} [size=(0,0)]
2135
+ * @param {EngineObject} [object]
2136
+ * @return {boolean} */
2137
+ collisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
2138
+ /** Return the center of first tile hit, undefined if nothing was hit.
2139
+ * This does not return the exact intersection, but the center of the tile hit.
2140
+ * @param {Vector2} posStart
2141
+ * @param {Vector2} posEnd
2142
+ * @param {EngineObject} [object]
2143
+ * @return {Vector2} */
2144
+ collisionRaycast(posStart: Vector2, posEnd: Vector2, object?: EngineObject): Vector2;
2145
+ }
2107
2146
  /**
2108
2147
  * LittleJS Particle System
2109
2148
  */
@@ -2316,4 +2355,1274 @@ declare module "littlejsengine" {
2316
2355
  renderIcon(pos: Vector2, size: number): void;
2317
2356
  storageKey(): string;
2318
2357
  }
2358
+ /**
2359
+ * LittleJS Newgrounds API
2360
+ * - NewgroundsMedal extends Medal with Newgrounds API functionality
2361
+ * - Call new NewgroundsPlugin() to setup Newgrounds
2362
+ * - Uses CryptoJS for encryption if optional cipher is provided
2363
+ * - Keeps connection alive and logs views
2364
+ * - Functions to interact with scoreboards
2365
+ * - Functions to unlock medals
2366
+ */
2367
+ /** Global Newgrounds object
2368
+ * @type {NewgroundsPlugin}
2369
+ * @memberof Medal */
2370
+ export let newgrounds: NewgroundsPlugin;
2371
+ /**
2372
+ * Newgrounds API object
2373
+ */
2374
+ export class NewgroundsPlugin {
2375
+ /** Create the global newgrounds object
2376
+ * @param {string} app_id - The newgrounds App ID
2377
+ * @param {string} [cipher] - The encryption Key (AES-128/Base64)
2378
+ * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
2379
+ * @example
2380
+ * // create the newgrounds object, replace the app id with your own
2381
+ * const app_id = 'your_app_id_here';
2382
+ * new NewgroundsPlugin(app_id);
2383
+ */
2384
+ constructor(app_id: string, cipher?: string, cryptoJS?: any);
2385
+ app_id: string;
2386
+ cipher: string;
2387
+ cryptoJS: any;
2388
+ host: string;
2389
+ session_id: string;
2390
+ medals: any;
2391
+ scoreboards: any;
2392
+ /** Send message to unlock a medal by id
2393
+ * @param {number} id - The medal id */
2394
+ unlockMedal(id: number): any;
2395
+ /** Send message to post score
2396
+ * @param {number} id - The scoreboard id
2397
+ * @param {number} value - The score value */
2398
+ postScore(id: number, value: number): any;
2399
+ /** Get scores from a scoreboard
2400
+ * @param {number} id - The scoreboard id
2401
+ * @param {string} [user] - A user's id or name
2402
+ * @param {number} [social] - If true, only social scores will be loaded
2403
+ * @param {number} [skip] - Number of scores to skip before start
2404
+ * @param {number} [limit] - Number of scores to include in the list
2405
+ * @return {Object} - The response JSON object
2406
+ */
2407
+ getScores(id: number, user?: string, social?: number, skip?: number, limit?: number): any;
2408
+ /** Send message to log a view */
2409
+ logView(): any;
2410
+ /** Send a message to call a component of the Newgrounds API
2411
+ * @param {string} component - Name of the component
2412
+ * @param {Object} [parameters] - Parameters to use for call
2413
+ * @param {boolean} [async] - If true, don't wait for response before continuing
2414
+ * @return {Object} - The response JSON object
2415
+ */
2416
+ call(component: string, parameters?: any, async?: boolean): any;
2417
+ }
2418
+ /**
2419
+ * Newgrounds medal auto unlocks in newgrounds API
2420
+ * @extends Medal
2421
+ */
2422
+ export class NewgroundsMedal extends Medal {
2423
+ }
2424
+ /**
2425
+ * LittleJS Post Processing Plugin
2426
+ * - Supports shadertoy style post processing shaders
2427
+ * - call new new PostProcessPlugin() to setup post processing
2428
+ * - can be enabled to pass other canvases through a final shader
2429
+ */
2430
+ /** Global Post Process plugin object
2431
+ * @type {PostProcessPlugin} */
2432
+ export let postProcess: PostProcessPlugin;
2433
+ /**
2434
+ * UI System Global Object
2435
+ */
2436
+ export class PostProcessPlugin {
2437
+ /** Create global post processing shader
2438
+ * @param {string} shaderCode
2439
+ * @param {boolean} [includeOverlay]
2440
+ * @example
2441
+ * // create the post process plugin object
2442
+ * new PostProcessPlugin(shaderCode);
2443
+ */
2444
+ constructor(shaderCode: string, includeOverlay?: boolean);
2445
+ /** @property {WebGLProgram} - Shader for post processing */
2446
+ shader: WebGLProgram;
2447
+ /** @property {WebGLTexture} - Texture for post processing */
2448
+ texture: WebGLTexture;
2449
+ /** @property {boolean} - Should overlay canvas be included in post processing */
2450
+ includeOverlay: boolean;
2451
+ }
2452
+ /**
2453
+ * LittleJS ZzFXM Plugin
2454
+ */
2455
+ /**
2456
+ * Music Object - Stores a zzfx music track for later use
2457
+ *
2458
+ * <a href=https://keithclark.github.io/ZzFXM/>Create music with the ZzFXM tracker.</a>
2459
+ * @example
2460
+ * // create some music
2461
+ * const music_example = new Music(
2462
+ * [
2463
+ * [ // instruments
2464
+ * [,0,400] // simple note
2465
+ * ],
2466
+ * [ // patterns
2467
+ * [ // pattern 1
2468
+ * [ // channel 0
2469
+ * 0, -1, // instrument 0, left speaker
2470
+ * 1, 0, 9, 1 // channel notes
2471
+ * ],
2472
+ * [ // channel 1
2473
+ * 0, 1, // instrument 0, right speaker
2474
+ * 0, 12, 17, -1 // channel notes
2475
+ * ]
2476
+ * ],
2477
+ * ],
2478
+ * [0, 0, 0, 0], // sequence, play pattern 0 four times
2479
+ * 90 // BPM
2480
+ * ]);
2481
+ *
2482
+ * // play the music
2483
+ * music_example.play();
2484
+ */
2485
+ export class ZzFXMusic extends Sound {
2486
+ /** Create a music object and cache the zzfx music samples for later use
2487
+ * @param {[Array, Array, Array, number]} zzfxMusic - Array of zzfx music parameters
2488
+ */
2489
+ constructor(zzfxMusic: [any[], any[], any[], number]);
2490
+ sampleChannels: any[];
2491
+ /** Play the music
2492
+ * @param {number} [volume=1] - How much to scale volume by
2493
+ * @param {boolean} [loop] - True if the music should loop
2494
+ * @return {AudioBufferSourceNode} - The audio source node
2495
+ */
2496
+ playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
2497
+ }
2498
+ /**
2499
+ * LittleJS User Interface Plugin
2500
+ * - call new UISystemPlugin() to setup the UI system
2501
+ * - Nested Menus
2502
+ * - Text
2503
+ * - Buttons
2504
+ * - Checkboxes
2505
+ * - Images
2506
+ */
2507
+ /** Global UI system plugin object
2508
+ * @type {UISystemPlugin} */
2509
+ export let uiSystem: UISystemPlugin;
2510
+ /**
2511
+ * UI System Global Object
2512
+ */
2513
+ export class UISystemPlugin {
2514
+ /** Create the global UI system object
2515
+ * @param {CanvasRenderingContext2D} [context]
2516
+ * @example
2517
+ * // create the ui plugin object
2518
+ * new UISystemPlugin;
2519
+ */
2520
+ constructor(context?: CanvasRenderingContext2D);
2521
+ /** @property {Color} - Default fill color for UI elements */
2522
+ defaultColor: Color;
2523
+ /** @property {Color} - Default outline color for UI elements */
2524
+ defaultLineColor: Color;
2525
+ /** @property {Color} - Default text color for UI elements */
2526
+ defaultTextColor: Color;
2527
+ /** @property {Color} - Default button color for UI elements */
2528
+ defaultButtonColor: Color;
2529
+ /** @property {Color} - Default hover color for UI elements */
2530
+ defaultHoverColor: Color;
2531
+ /** @property {number} - Default line width for UI elements */
2532
+ defaultLineWidth: number;
2533
+ /** @property {string} - Default font for UI elements */
2534
+ defaultFont: string;
2535
+ /** @property {Array<UIObject>} - List of all UI elements */
2536
+ uiObjects: any[];
2537
+ /** @property {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} - Context to render UI elements to */
2538
+ uiContext: CanvasRenderingContext2D;
2539
+ /** Draw a rectangle to the UI context
2540
+ * @param {Vector2} pos
2541
+ * @param {Vector2} size
2542
+ * @param {Color} [color=uiSystem.defaultColor]
2543
+ * @param {number} [lineWidth=uiSystem.defaultLineWidth]
2544
+ * @param {Color} [lineColor=uiSystem.defaultLineColor] */
2545
+ drawRect(pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color): void;
2546
+ /** Draw a line to the UI context
2547
+ * @param {Vector2} posA
2548
+ * @param {Vector2} posB
2549
+ * @param {number} [lineWidth=uiSystem.defaultLineWidth]
2550
+ * @param {Color} [lineColor=uiSystem.defaultLineColor] */
2551
+ drawLine(posA: Vector2, posB: Vector2, lineWidth?: number, lineColor?: Color): void;
2552
+ /** Draw a tile to the UI context
2553
+ * @param {Vector2} pos
2554
+ * @param {Vector2} size
2555
+ * @param {TileInfo} tileInfo
2556
+ * @param {Color} [color=uiSystem.defaultColor]
2557
+ * @param {number} [angle]
2558
+ * @param {boolean} [mirror] */
2559
+ drawTile(pos: Vector2, size: Vector2, tileInfo: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
2560
+ /** Draw text to the UI context
2561
+ * @param {string} text
2562
+ * @param {Vector2} pos
2563
+ * @param {Vector2} size
2564
+ * @param {Color} [color=uiSystem.defaultColor]
2565
+ * @param {number} [lineWidth=uiSystem.defaultLineWidth]
2566
+ * @param {Color} [lineColor=uiSystem.defaultLineColor]
2567
+ * @param {string} [align]
2568
+ * @param {string} [font=uiSystem.defaultFont] */
2569
+ drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string): void;
2570
+ }
2571
+ /**
2572
+ * UI Object - Base level object for all UI elements
2573
+ */
2574
+ export class UIObject {
2575
+ /** Create a UIObject
2576
+ * @param {Vector2} [pos=(0,0)]
2577
+ * @param {Vector2} [size=(1,1)]
2578
+ */
2579
+ constructor(pos?: Vector2, size?: Vector2);
2580
+ /** @property {Vector2} - Local position of the object */
2581
+ localPos: Vector2;
2582
+ /** @property {Vector2} - Screen space position of the object */
2583
+ pos: Vector2;
2584
+ /** @property {Vector2} - Screen space size of the object */
2585
+ size: Vector2;
2586
+ /** @property {Color} */
2587
+ color: Color;
2588
+ /** @property {Color} */
2589
+ lineColor: Color;
2590
+ /** @property {Color} */
2591
+ textColor: Color;
2592
+ /** @property {Color} */
2593
+ hoverColor: Color;
2594
+ /** @property {number} */
2595
+ lineWidth: number;
2596
+ /** @property {string} */
2597
+ font: string;
2598
+ /** @property {boolean} */
2599
+ visible: boolean;
2600
+ /** @property {Array<UIObject>} */
2601
+ children: any[];
2602
+ /** @property {UIObject} */
2603
+ parent: any;
2604
+ /** Add a child UIObject to this object
2605
+ * @param {UIObject} child
2606
+ */
2607
+ addChild(child: UIObject): void;
2608
+ /** Remove a child UIObject from this object
2609
+ * @param {UIObject} child
2610
+ */
2611
+ removeChild(child: UIObject): void;
2612
+ /** Update the object, called automatically by plugin once each frame */
2613
+ update(): void;
2614
+ mouseIsOver: boolean;
2615
+ mouseIsHeld: boolean;
2616
+ /** Render the object, called automatically by plugin once each frame */
2617
+ render(): void;
2618
+ /** Called when the mouse enters the object */
2619
+ onEnter(): void;
2620
+ /** Called when the mouse leaves the object */
2621
+ onLeave(): void;
2622
+ /** Called when the mouse is pressed while over the object */
2623
+ onPress(): void;
2624
+ /** Called when the mouse is released while over the object */
2625
+ onRelease(): void;
2626
+ /** Called when the state of this object changes */
2627
+ onChange(): void;
2628
+ }
2629
+ /**
2630
+ * UIText - A UI object that displays text
2631
+ * @extends UIObject
2632
+ */
2633
+ export class UIText extends UIObject {
2634
+ /** Create a UIText object
2635
+ * @param {Vector2} [pos]
2636
+ * @param {Vector2} [size]
2637
+ * @param {string} [text]
2638
+ * @param {string} [align]
2639
+ * @param {string} [font=uiSystem.defaultFont]
2640
+ */
2641
+ constructor(pos?: Vector2, size?: Vector2, text?: string, align?: string, font?: string);
2642
+ /** @property {string} */
2643
+ text: string;
2644
+ /** @property {string} */
2645
+ align: string;
2646
+ }
2647
+ /**
2648
+ * UITile - A UI object that displays a tile image
2649
+ * @extends UIObject
2650
+ */
2651
+ export class UITile extends UIObject {
2652
+ /** Create a UITile object
2653
+ * @param {Vector2} [pos]
2654
+ * @param {Vector2} [size]
2655
+ * @param {TileInfo} [tileInfo]
2656
+ * @param {Color} [color=WHITE]
2657
+ * @param {number} [angle]
2658
+ * @param {boolean} [mirror]
2659
+ */
2660
+ constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean);
2661
+ /** @property {TileInfo} - Tile image to use */
2662
+ tileInfo: TileInfo;
2663
+ /** @property {number} - Angle to rotate in radians */
2664
+ angle: number;
2665
+ /** @property {boolean} - Should it be mirrored? */
2666
+ mirror: boolean;
2667
+ }
2668
+ /**
2669
+ * UIButton - A UI object that acts as a button
2670
+ * @extends UIObject
2671
+ */
2672
+ export class UIButton extends UIObject {
2673
+ /** Create a UIButton object
2674
+ * @param {Vector2} [pos]
2675
+ * @param {Vector2} [size]
2676
+ * @param {string} [text]
2677
+ * @param {Color} [color=uiSystem.defaultButtonColor]
2678
+ */
2679
+ constructor(pos?: Vector2, size?: Vector2, text?: string, color?: Color);
2680
+ /** @property {string} */
2681
+ text: string;
2682
+ }
2683
+ /**
2684
+ * UICheckbox - A UI object that acts as a checkbox
2685
+ * @extends UIObject
2686
+ */
2687
+ export class UICheckbox extends UIObject {
2688
+ /** Create a UICheckbox object
2689
+ * @param {Vector2} [pos]
2690
+ * @param {Vector2} [size]
2691
+ * @param {boolean} [checked]
2692
+ */
2693
+ constructor(pos?: Vector2, size?: Vector2, checked?: boolean);
2694
+ /** @property {boolean} */
2695
+ checked: boolean;
2696
+ }
2697
+ /**
2698
+ * UIScrollbar - A UI object that acts as a scrollbar
2699
+ * @extends UIObject
2700
+ */
2701
+ export class UIScrollbar extends UIObject {
2702
+ /** Create a UIScrollbar object
2703
+ * @param {Vector2} [pos]
2704
+ * @param {Vector2} [size]
2705
+ * @param {number} [value]
2706
+ * @param {string} [text]
2707
+ * @param {Color} [color=uiSystem.defaultButtonColor]
2708
+ * @param {Color} [handleColor=WHITE]
2709
+ */
2710
+ constructor(pos?: Vector2, size?: Vector2, value?: number, text?: string, color?: Color, handleColor?: Color);
2711
+ /** @property {number} */
2712
+ value: number;
2713
+ /** @property {string} */
2714
+ text: string;
2715
+ handleColor: Color;
2716
+ }
2717
+ /**
2718
+ * LittleJS Box2D Physics Plugin
2719
+ * - Box2dObject extends EngineObject with Box2D physics
2720
+ * - Call box2dEngineInit() to start instead of normal engineInit()
2721
+ * - You will also need to include box2d.wasm.js
2722
+ * - Uses box2d.js super fast web assembly port of Box2D
2723
+ * - More info: https://github.com/kripken/box2d.js
2724
+ * - Fully wraps everything in Box2d
2725
+ * - Functions to create polygon, circle, and edge shapes
2726
+ * - Raycasting and querying
2727
+ * - Joint creation
2728
+ * - Contact begin and end callbacks
2729
+ * - Debug physics drawing
2730
+ */
2731
+ /** Global Box2d Plugin object
2732
+ * @type {Box2dPlugin} */
2733
+ export let box2d: Box2dPlugin;
2734
+ /** Enable Box2D debug drawing
2735
+ * @type {boolean}
2736
+ * @default */
2737
+ export let box2dDebug: boolean;
2738
+ /** Enable Box2D debug drawing
2739
+ * @param {boolean} enable */
2740
+ export function box2dSetDebug(enable: boolean): void;
2741
+ /** Box2d Init - Startup LittleJS engine with your callback functions
2742
+ * @param {Function|function():Promise} gameInit - Called once after the engine starts up
2743
+ * @param {Function} gameUpdate - Called every frame before objects are updated
2744
+ * @param {Function} gameUpdatePost - Called after physics and objects are updated, even when paused
2745
+ * @param {Function} gameRender - Called before objects are rendered, for drawing the background
2746
+ * @param {Function} gameRenderPost - Called after objects are rendered, useful for drawing UI
2747
+ * @param {Array<string>} [imageSources=[]] - List of images to load
2748
+ * @param {HTMLElement} [rootElement] - Root element to attach to, the document body by default */
2749
+ export function box2dEngineInit(gameInit: Function | (() => Promise<any>), gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: Array<string>, rootElement?: HTMLElement): void;
2750
+ /**
2751
+ * Box2D Global Object
2752
+ * - Wraps Box2d world and provides global functions
2753
+ */
2754
+ export class Box2dPlugin {
2755
+ /** Create the global UI system object
2756
+ * @param {Object} instance */
2757
+ constructor(instance: any);
2758
+ instance: any;
2759
+ world: any;
2760
+ /** @property {number} - Velocity iterations per update*/
2761
+ velocityIterations: number;
2762
+ /** @property {number} - Position iterations per update*/
2763
+ positionIterations: number;
2764
+ /** @property {number} - Static, zero mass, zero velocity, may be manually moved */
2765
+ bodyTypeStatic: any;
2766
+ /** @property {number} - Kinematic, zero mass, non-zero velocity set by user, moved by solver */
2767
+ bodyTypeKinematic: any;
2768
+ /** @property {number} - Dynamic, positive mass, non-zero velocity determined by forces, moved by solver */
2769
+ bodyTypeDynamic: any;
2770
+ /** Step the physics world simulation
2771
+ * @param {number} [frames] */
2772
+ step(frames?: number): void;
2773
+ /** raycast and return a list of all the results
2774
+ * @param {Vector2} start
2775
+ * @param {Vector2} end */
2776
+ raycastAll(start: Vector2, end: Vector2): any[];
2777
+ /** raycast and return the first result
2778
+ * @param {Vector2} start
2779
+ * @param {Vector2} end */
2780
+ raycast(start: Vector2, end: Vector2): any;
2781
+ /** box aabb cast and return all the objects
2782
+ * @param {Vector2} pos
2783
+ * @param {Vector2} size */
2784
+ boxCastAll(pos: Vector2, size: Vector2): any[];
2785
+ /** box aabb cast and return the first object
2786
+ * @param {Vector2} pos
2787
+ * @param {Vector2} size */
2788
+ boxCast(pos: Vector2, size: Vector2): undefined;
2789
+ /** circle cast and return all the objects
2790
+ * @param {Vector2} pos
2791
+ * @param {number} diameter */
2792
+ circleCastAll(pos: Vector2, diameter: number): any[];
2793
+ /** circle cast and return the first object
2794
+ * @param {Vector2} pos
2795
+ * @param {number} diameter */
2796
+ circleCast(pos: Vector2, diameter: number): any;
2797
+ /** point cast and return the first object
2798
+ * @param {Vector2} pos
2799
+ * @param {boolean} dynamicOnly */
2800
+ pointCast(pos: Vector2, dynamicOnly?: boolean): undefined;
2801
+ /** draws a fixture
2802
+ * @param {Object} fixture
2803
+ * @param {Vector2} pos
2804
+ * @param {number} angle
2805
+ * @param {Color} [color]
2806
+ * @param {Color} [outlineColor]
2807
+ * @param {number} [lineWidth]
2808
+ * @param {CanvasRenderingContext2D} [context] */
2809
+ drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2810
+ /** draws a circle
2811
+ * @param {Vector2} pos
2812
+ * @param {number} radius
2813
+ * @param {Color} [color]
2814
+ * @param {Color} [outlineColor]
2815
+ * @param {number} [lineWidth]
2816
+ * @param {CanvasRenderingContext2D} [context] */
2817
+ drawCircle(pos: Vector2, radius: number, color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2818
+ /** draws a polygon
2819
+ * @param {Vector2} pos
2820
+ * @param {number} angle
2821
+ * @param {Array<Vector2>} points
2822
+ * @param {Color} [color]
2823
+ * @param {Color} [outlineColor]
2824
+ * @param {number} [lineWidth]
2825
+ * @param {CanvasRenderingContext2D} [context] */
2826
+ drawPoly(pos: Vector2, angle: number, points: Array<Vector2>, color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2827
+ /** draws a line
2828
+ * @param {Vector2} pos
2829
+ * @param {number} angle
2830
+ * @param {Vector2} posA
2831
+ * @param {Vector2} posB
2832
+ * @param {Color} [color]
2833
+ * @param {number} [lineWidth]
2834
+ * @param {CanvasRenderingContext2D} [context] */
2835
+ drawLine(pos: Vector2, angle: number, posA: Vector2, posB: Vector2, color?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2836
+ /** performs a fill or stroke as a helper to the other draw functions
2837
+ * @param {Color} [color]
2838
+ * @param {Color} [outlineColor]
2839
+ * @param {number} [lineWidth]
2840
+ * @param {CanvasRenderingContext2D} [context] */
2841
+ drawFillStroke(color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2842
+ /** converts a box2d vec2 to a Vector2
2843
+ * @param {Object} v */
2844
+ vec2From(v: any): Vector2;
2845
+ /** converts a box2d vec2 pointer to a Vector2
2846
+ * @param {Object} v */
2847
+ vec2FromPointer(v: any): Vector2;
2848
+ /** converts a Vector2 to a box2 vec2
2849
+ * @param {Vector2} v */
2850
+ vec2dTo(v: Vector2): any;
2851
+ /** checks if a box2d object is null
2852
+ * @param {Object} o */
2853
+ isNull(o: any): boolean;
2854
+ /** casts a box2d object to its correct type
2855
+ * @param {Object} o */
2856
+ castObjectType(o: any): any;
2857
+ }
2858
+ /**
2859
+ * Box2D Object - extend with your own custom physics objects
2860
+ * - A LittleJS object with Box2D physics
2861
+ * - Each object has a Box2D body which can have multiple fixtures and joints
2862
+ * - Provides interface for Box2D body and fixture functions
2863
+ * @extends EngineObject
2864
+ */
2865
+ export class Box2dObject extends EngineObject {
2866
+ /** Create a LittleJS object with Box2d physics
2867
+ * @param {Vector2} [pos]
2868
+ * @param {Vector2} [size]
2869
+ * @param {TileInfo} [tileInfo]
2870
+ * @param {number} [angle]
2871
+ * @param {Color} [color]
2872
+ * @param {number} [bodyType]
2873
+ * @param {number} [renderOrder] */
2874
+ constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, bodyType?: number, renderOrder?: number);
2875
+ body: any;
2876
+ outlineColor: Color;
2877
+ /** Draws all this object's fixtures
2878
+ * @param {Color} [color]
2879
+ * @param {Color} [outlineColor]
2880
+ * @param {number} [lineWidth]
2881
+ * @param {CanvasRenderingContext2D} [context] */
2882
+ drawFixtures(color?: Color, outlineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
2883
+ /** Called when a contact begins
2884
+ * @param {Box2dObject} otherObject */
2885
+ beginContact(otherObject: Box2dObject): void;
2886
+ /** Called when a contact ends
2887
+ * @param {Box2dObject} otherObject */
2888
+ endContact(otherObject: Box2dObject): void;
2889
+ /** Add a shape fixture to the body
2890
+ * @param {Object} shape
2891
+ * @param {number} [density]
2892
+ * @param {number} [friction]
2893
+ * @param {number} [restitution]
2894
+ * @param {boolean} [isSensor] */
2895
+ addShape(shape: any, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2896
+ /** Add a box shape to the body
2897
+ * @param {Vector2} [size]
2898
+ * @param {Vector2} [offset]
2899
+ * @param {number} [angle]
2900
+ * @param {number} [density]
2901
+ * @param {number} [friction]
2902
+ * @param {number} [restitution]
2903
+ * @param {boolean} [isSensor] */
2904
+ addBox(size?: Vector2, offset?: Vector2, angle?: number, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2905
+ /** Add a polygon shape to the body
2906
+ * @param {Array<Vector2>} points
2907
+ * @param {number} [density]
2908
+ * @param {number} [friction]
2909
+ * @param {number} [restitution]
2910
+ * @param {boolean} [isSensor] */
2911
+ addPoly(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2912
+ /** Add a regular polygon shape to the body
2913
+ * @param {number} [diameter]
2914
+ * @param {number} [sides]
2915
+ * @param {number} [density]
2916
+ * @param {number} [friction]
2917
+ * @param {number} [restitution]
2918
+ * @param {boolean} [isSensor] */
2919
+ addRegularPoly(diameter?: number, sides?: number, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2920
+ /** Add a random polygon shape to the body
2921
+ * @param {number} [diameter]
2922
+ * @param {number} [density]
2923
+ * @param {number} [friction]
2924
+ * @param {number} [restitution]
2925
+ * @param {boolean} [isSensor] */
2926
+ addRandomPoly(diameter?: number, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2927
+ /** Add a circle shape to the body
2928
+ * @param {number} [diameter]
2929
+ * @param {Vector2} [offset]
2930
+ * @param {number} [density]
2931
+ * @param {number} [friction]
2932
+ * @param {number} [restitution]
2933
+ * @param {boolean} [isSensor] */
2934
+ addCircle(diameter?: number, offset?: Vector2, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2935
+ /** Add an edge shape to the body
2936
+ * @param {Vector2} point1
2937
+ * @param {Vector2} point2
2938
+ * @param {number} [density]
2939
+ * @param {number} [friction]
2940
+ * @param {number} [restitution]
2941
+ * @param {boolean} [isSensor] */
2942
+ addEdge(point1: Vector2, point2: Vector2, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any;
2943
+ /** Add an edge loop to the body, an edge loop connects the end points
2944
+ * @param {Array<Vector2>} points
2945
+ * @param {number} [density]
2946
+ * @param {number} [friction]
2947
+ * @param {number} [restitution]
2948
+ * @param {boolean} [isSensor] */
2949
+ addEdgeLoop(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
2950
+ /** Add an edge list to the body
2951
+ * @param {Array<Vector2>} points
2952
+ * @param {number} [density]
2953
+ * @param {number} [friction]
2954
+ * @param {number} [restitution]
2955
+ * @param {boolean} [isSensor] */
2956
+ addEdgeList(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
2957
+ /** Gets the center of mass
2958
+ * @return {Vector2} */
2959
+ getCenterOfMass(): Vector2;
2960
+ /** Gets the linear velocity
2961
+ * @return {Vector2} */
2962
+ getLinearVelocity(): Vector2;
2963
+ /** Gets the angular velocity
2964
+ * @return {Vector2} */
2965
+ getAngularVelocity(): Vector2;
2966
+ /** Gets the mass
2967
+ * @return {number} */
2968
+ getMass(): number;
2969
+ /** Gets the rotational inertia
2970
+ * @return {number} */
2971
+ getInertia(): number;
2972
+ /** Check if this object is awake
2973
+ * @return {boolean} */
2974
+ getIsAwake(): boolean;
2975
+ /** Gets the physics body type
2976
+ * @return {number} */
2977
+ getBodyType(): number;
2978
+ /** Sets the position and angle
2979
+ * @param {Vector2} pos
2980
+ * @param {number} angle */
2981
+ setTransform(pos: Vector2, angle: number): void;
2982
+ /** Sets the position
2983
+ * @param {Vector2} pos */
2984
+ setPosition(pos: Vector2): void;
2985
+ /** Sets the angle
2986
+ * @param {number} angle */
2987
+ setAngle(angle: number): void;
2988
+ /** Sets the linear velocity
2989
+ * @param {Vector2} velocity */
2990
+ setLinearVelocity(velocity: Vector2): void;
2991
+ /** Sets the angular velocity
2992
+ * @param {number} angularVelocity */
2993
+ setAngularVelocity(angularVelocity: number): void;
2994
+ /** Sets the linear damping
2995
+ * @param {number} damping */
2996
+ setLinearDamping(damping: number): void;
2997
+ /** Sets the angular damping
2998
+ * @param {number} damping */
2999
+ setAngularDamping(damping: number): void;
3000
+ /** Sets the gravity scale
3001
+ * @param {number} [scale] */
3002
+ setGravityScale(scale?: number): void;
3003
+ /** Should this body be treated like a bullet for continuous collision detection?
3004
+ * @param {boolean} [isBullet] */
3005
+ setBullet(isBullet?: boolean): void;
3006
+ /** Set the sleep state of the body
3007
+ * @param {boolean} [isAwake] */
3008
+ setAwake(isAwake?: boolean): void;
3009
+ /** Set the physics body type
3010
+ * @param {number} type */
3011
+ setBodyType(type: number): void;
3012
+ /** Set whether the body is allowed to sleep
3013
+ * @param {boolean} [isAllowed] */
3014
+ setSleepingAllowed(isAllowed?: boolean): void;
3015
+ /** Set whether the body can rotate
3016
+ * @param {boolean} [isFixed] */
3017
+ setFixedRotation(isFixed?: boolean): void;
3018
+ /** Set the center of mass of the body
3019
+ * @param {Vector2} center */
3020
+ setCenterOfMass(center: Vector2): void;
3021
+ /** Set the mass of the body
3022
+ * @param {number} mass */
3023
+ setMass(mass: number): void;
3024
+ /** Set the moment of inertia of the body
3025
+ * @param {number} momentOfInertia */
3026
+ setMomentOfInertia(momentOfInertia: number): void;
3027
+ /** Reset the mass, center of mass, and moment */
3028
+ resetMassData(): void;
3029
+ /** Set the mass data of the body
3030
+ * @param {Vector2} [localCenter]
3031
+ * @param {number} [mass]
3032
+ * @param {number} [momentOfInertia] */
3033
+ setMassData(localCenter?: Vector2, mass?: number, momentOfInertia?: number): void;
3034
+ /** Set the collision filter data for this body
3035
+ * @param {number} [categoryBits]
3036
+ * @param {number} [ignoreCategoryBits]
3037
+ * @param {number} [groupIndex] */
3038
+ setFilterData(categoryBits?: number, ignoreCategoryBits?: number, groupIndex?: number): void;
3039
+ /** Set if this body is a sensor
3040
+ * @param {boolean} [isSensor] */
3041
+ setSensor(isSensor?: boolean): void;
3042
+ /** Apply force to this object
3043
+ * @param {Vector2} force
3044
+ * @param {Vector2} [pos] */
3045
+ applyForce(force: Vector2, pos?: Vector2): void;
3046
+ /** Apply acceleration to this object
3047
+ * @param {Vector2} acceleration
3048
+ * @param {Vector2} [pos] */
3049
+ applyAcceleration(acceleration: Vector2, pos?: Vector2): void;
3050
+ /** Apply torque to this object
3051
+ * @param {number} torque */
3052
+ applyTorque(torque: number): void;
3053
+ /** Apply angular acceleration to this object
3054
+ * @param {number} acceleration */
3055
+ applyAngularAcceleration(acceleration: number): void;
3056
+ /** Check if this object has any fixtures
3057
+ * @return {boolean} */
3058
+ hasFixtures(): boolean;
3059
+ /** Get list of fixtures for this object
3060
+ * @return {Array<Object>} */
3061
+ getFixtureList(): Array<any>;
3062
+ /** Check if this object has any joints
3063
+ * @return {boolean} */
3064
+ hasJoints(): boolean;
3065
+ /** Get list of joints for this object
3066
+ * @return {Array<Object>} */
3067
+ getJointList(): Array<any>;
3068
+ }
3069
+ /**
3070
+ * Box2D Raycast Result
3071
+ * - Holds results from a box2d raycast queries
3072
+ * - Automatically created by box2d raycast functions
3073
+ */
3074
+ export class Box2dRaycastResult {
3075
+ /** Create a raycast result
3076
+ * @param {Object} fixture
3077
+ * @param {Vector2} point
3078
+ * @param {Vector2} normal
3079
+ * @param {number} fraction */
3080
+ constructor(fixture: any, point: Vector2, normal: Vector2, fraction: number);
3081
+ /** @property {Box2dObject} - The box2d object */
3082
+ object: any;
3083
+ /** @property {Object} - The fixture that was hit */
3084
+ fixture: any;
3085
+ /** @property {Vector2} - The hit point */
3086
+ point: Vector2;
3087
+ /** @property {Vector2} - The hit normal */
3088
+ normal: Vector2;
3089
+ /** @property {number} - Distance fraction at the point of intersection */
3090
+ fraction: number;
3091
+ }
3092
+ /**
3093
+ * Box2D Joint
3094
+ * - Base class for Box2D joints
3095
+ * - A joint is used to connect objects together
3096
+ */
3097
+ export class Box2dJoint {
3098
+ /** Create a box2d joint, the base class is not intended to be used directly
3099
+ * @param {Object} jointDef */
3100
+ constructor(jointDef: any);
3101
+ box2dJoint: any;
3102
+ /** Destroy this joint */
3103
+ destroy(): void;
3104
+ /** Get the first object attached to this joint
3105
+ * @return {Box2dObject} */
3106
+ getObjectA(): Box2dObject;
3107
+ /** Get the second object attached to this joint
3108
+ * @return {Box2dObject} */
3109
+ getObjectB(): Box2dObject;
3110
+ /** Get the first anchor for this joint in world coordinates
3111
+ * @return {Vector2} */
3112
+ getAnchorA(): Vector2;
3113
+ /** Get the second anchor for this joint in world coordinates
3114
+ * @return {Vector2} */
3115
+ getAnchorB(): Vector2;
3116
+ /** Get the reaction force on bodyB at the joint anchor given a time step
3117
+ * @param {number} time
3118
+ * @return {Vector2} */
3119
+ getReactionForce(time: number): Vector2;
3120
+ /** Get the reaction torque on bodyB in N*m given a time step
3121
+ * @param {number} time
3122
+ * @return {number} */
3123
+ getReactionTorque(time: number): number;
3124
+ /** Check if the connected bodies should collide
3125
+ * @return {boolean} */
3126
+ getCollideConnected(): boolean;
3127
+ /** Check if either connected body is active
3128
+ * @return {boolean} */
3129
+ isActive(): boolean;
3130
+ }
3131
+ /**
3132
+ * Box2D Target Joint, also known as a mouse joint
3133
+ * - Used to make a point on a object track a specific world point target
3134
+ * - This a soft constraint with a max force
3135
+ * - This allows the constraint to stretch and without applying huge forces
3136
+ * @extends Box2dJoint
3137
+ */
3138
+ export class Box2dTargetJoint extends Box2dJoint {
3139
+ /** Create a target joint
3140
+ * @param {Box2dObject} object
3141
+ * @param {Box2dObject} fixedObject
3142
+ * @param {Vector2} worldPos */
3143
+ constructor(object: Box2dObject, fixedObject: Box2dObject, worldPos: Vector2);
3144
+ /** Set the target point in world coordinates
3145
+ * @param {Vector2} pos */
3146
+ setTarget(pos: Vector2): void;
3147
+ /** Get the target point in world coordinates
3148
+ * @return {Vector2} */
3149
+ getTarget(): Vector2;
3150
+ /** Sets the maximum force in Newtons
3151
+ * @param {number} force */
3152
+ setMaxForce(force: number): void;
3153
+ /** Gets the maximum force in Newtons
3154
+ * @return {number} */
3155
+ getMaxForce(): number;
3156
+ /** Sets the joint frequency in Hertz
3157
+ * @param {number} hz */
3158
+ setFrequency(hz: number): void;
3159
+ /** Gets the joint frequency in Hertz
3160
+ * @return {number} */
3161
+ getFrequency(): number;
3162
+ }
3163
+ /**
3164
+ * Box2D Distance Joint
3165
+ * - Constrains two points on two objects to remain at a fixed distance
3166
+ * - You can view this as a massless, rigid rod
3167
+ * @extends Box2dJoint
3168
+ */
3169
+ export class Box2dDistanceJoint extends Box2dJoint {
3170
+ /** Create a distance joint
3171
+ * @param {Box2dObject} objectA
3172
+ * @param {Box2dObject} objectB
3173
+ * @param {Vector2} anchorA
3174
+ * @param {Vector2} anchorB
3175
+ * @param {boolean} [collide] */
3176
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchorA: Vector2, anchorB: Vector2, collide?: boolean);
3177
+ /** Get the local anchor point relative to objectA's origin
3178
+ * @return {Vector2} */
3179
+ getLocalAnchorA(): Vector2;
3180
+ /** Get the local anchor point relative to objectB's origin
3181
+ * @return {Vector2} */
3182
+ getLocalAnchorB(): Vector2;
3183
+ /** Set the length of the joint
3184
+ * @param {number} length */
3185
+ setLength(length: number): void;
3186
+ /** Get the length of the joint
3187
+ * @return {number} */
3188
+ getLength(): number;
3189
+ /** Set the frequency in Hertz
3190
+ * @param {number} hz */
3191
+ setFrequency(hz: number): void;
3192
+ /** Get the frequency in Hertz
3193
+ * @return {number} */
3194
+ getFrequency(): number;
3195
+ /** Set the damping ratio
3196
+ * @param {number} ratio */
3197
+ setDampingRatio(ratio: number): void;
3198
+ /** Get the damping ratio
3199
+ * @return {number} */
3200
+ getDampingRatio(): number;
3201
+ }
3202
+ /**
3203
+ * Box2D Pin Joint
3204
+ * - Pins two objects together at a point
3205
+ * @extends Box2dDistanceJoint
3206
+ */
3207
+ export class Box2dPinJoint extends Box2dDistanceJoint {
3208
+ /** Create a pin joint
3209
+ * @param {Box2dObject} objectA
3210
+ * @param {Box2dObject} objectB
3211
+ * @param {Vector2} [pos]
3212
+ * @param {boolean} [collide] */
3213
+ constructor(objectA: Box2dObject, objectB: Box2dObject, pos?: Vector2, collide?: boolean);
3214
+ }
3215
+ /**
3216
+ * Box2D Rope Joint
3217
+ * - Enforces a maximum distance between two points on two objects
3218
+ * @extends Box2dJoint
3219
+ */
3220
+ export class Box2dRopeJoint extends Box2dJoint {
3221
+ /** Create a rope joint
3222
+ * @param {Box2dObject} objectA
3223
+ * @param {Box2dObject} objectB
3224
+ * @param {Vector2} anchorA
3225
+ * @param {Vector2} anchorB
3226
+ * @param {number} extraLength
3227
+ * @param {boolean} [collide] */
3228
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchorA: Vector2, anchorB: Vector2, extraLength?: number, collide?: boolean);
3229
+ /** Get the local anchor point relative to objectA's origin
3230
+ * @return {Vector2} */
3231
+ getLocalAnchorA(): Vector2;
3232
+ /** Get the local anchor point relative to objectB's origin
3233
+ * @return {Vector2} */
3234
+ getLocalAnchorB(): Vector2;
3235
+ /** Set the max length of the joint
3236
+ * @param {number} length */
3237
+ setMaxLength(length: number): void;
3238
+ /** Get the max length of the joint
3239
+ * @return {number} */
3240
+ getMaxLength(): number;
3241
+ }
3242
+ /**
3243
+ * Box2D Revolute Joint
3244
+ * - Constrains two objects to share a point while they are free to rotate around the point
3245
+ * - The relative rotation about the shared point is the joint angle
3246
+ * - You can limit the relative rotation with a joint limit
3247
+ * - You can use a motor to drive the relative rotation about the shared point
3248
+ * - A maximum motor torque is provided so that infinite forces are not generated
3249
+ * @extends Box2dJoint
3250
+ */
3251
+ export class Box2dRevoluteJoint extends Box2dJoint {
3252
+ /** Create a revolute joint
3253
+ * @param {Box2dObject} objectA
3254
+ * @param {Box2dObject} objectB
3255
+ * @param {Vector2} anchor
3256
+ * @param {boolean} [collide] */
3257
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchor: Vector2, collide?: boolean);
3258
+ /** Get the local anchor point relative to objectA's origin
3259
+ * @return {Vector2} */
3260
+ getLocalAnchorA(): Vector2;
3261
+ /** Get the local anchor point relative to objectB's origin
3262
+ * @return {Vector2} */
3263
+ getLocalAnchorB(): Vector2;
3264
+ /** Get the reference angle, objectB angle minus objectA angle in the reference state
3265
+ * @return {number} */
3266
+ getReferenceAngle(): number;
3267
+ /** Get the current joint angle
3268
+ * @return {number} */
3269
+ getJointAngle(): number;
3270
+ /** Get the current joint angle speed in radians per second
3271
+ * @return {number} */
3272
+ getJointSpeed(): number;
3273
+ /** Is the joint limit enabled?
3274
+ * @return {boolean} */
3275
+ isLimitEnabled(): boolean;
3276
+ /** Enable/disable the joint limit
3277
+ * @param {boolean} [enable] */
3278
+ enableLimit(enable?: boolean): any;
3279
+ /** Get the lower joint limit
3280
+ * @return {number} */
3281
+ getLowerLimit(): number;
3282
+ /** Get the upper joint limit
3283
+ * @return {number} */
3284
+ getUpperLimit(): number;
3285
+ /** Set the joint limits
3286
+ * @param {number} min
3287
+ * @param {number} max */
3288
+ setLimits(min: number, max: number): any;
3289
+ /** Is the joint motor enabled?
3290
+ * @return {boolean} */
3291
+ isMotorEnabled(): boolean;
3292
+ /** Enable/disable the joint motor
3293
+ * @param {boolean} [enable] */
3294
+ enableMotor(enable?: boolean): any;
3295
+ /** Set the motor speed
3296
+ * @param {number} speed */
3297
+ setMotorSpeed(speed: number): any;
3298
+ /** Get the motor speed
3299
+ * @return {number} */
3300
+ getMotorSpeed(): number;
3301
+ /** Set the motor torque
3302
+ * @param {number} torque */
3303
+ setMaxMotorTorque(torque: number): any;
3304
+ /** Get the max motor torque
3305
+ * @return {number} */
3306
+ getMaxMotorTorque(): number;
3307
+ /** Get the motor torque given a time step
3308
+ * @param {number} time
3309
+ * @return {number} */
3310
+ getMotorTorque(time: number): number;
3311
+ }
3312
+ /**
3313
+ * Box2D Gear Joint
3314
+ * - A gear joint is used to connect two joints together
3315
+ * - Either joint can be a revolute or prismatic joint
3316
+ * - You specify a gear ratio to bind the motions together
3317
+ * @extends Box2dJoint
3318
+ */
3319
+ export class Box2dGearJoint extends Box2dJoint {
3320
+ /** Create a gear joint
3321
+ * @param {Box2dObject} objectA
3322
+ * @param {Box2dObject} objectB
3323
+ * @param {Box2dJoint} joint1
3324
+ * @param {Box2dJoint} joint2
3325
+ * @param {ratio} [ratio] */
3326
+ constructor(objectA: Box2dObject, objectB: Box2dObject, joint1: Box2dJoint, joint2: Box2dJoint, ratio?: ratio);
3327
+ joint1: Box2dJoint;
3328
+ joint2: Box2dJoint;
3329
+ /** Get the first joint
3330
+ * @return {Box2dJoint} */
3331
+ getJoint1(): Box2dJoint;
3332
+ /** Get the second joint
3333
+ * @return {Box2dJoint} */
3334
+ getJoint2(): Box2dJoint;
3335
+ /** Set the gear ratio
3336
+ * @param {number} ratio */
3337
+ setRatio(ratio: number): any;
3338
+ /** Get the gear ratio
3339
+ * @return {number} */
3340
+ getRatio(): number;
3341
+ }
3342
+ /**
3343
+ * Box2D Prismatic Joint
3344
+ * - Provides one degree of freedom: translation along an axis fixed in objectA
3345
+ * - Relative rotation is prevented
3346
+ * - You can use a joint limit to restrict the range of motion
3347
+ * - You can use a joint motor to drive the motion or to model joint friction
3348
+ * @extends Box2dJoint
3349
+ */
3350
+ export class Box2dPrismaticJoint extends Box2dJoint {
3351
+ /** Create a prismatic joint
3352
+ * @param {Box2dObject} objectA
3353
+ * @param {Box2dObject} objectB
3354
+ * @param {Vector2} anchor
3355
+ * @param {Vector2} worldAxis
3356
+ * @param {boolean} [collide] */
3357
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchor: Vector2, worldAxis?: Vector2, collide?: boolean);
3358
+ /** Get the local anchor point relative to objectA's origin
3359
+ * @return {Vector2} */
3360
+ getLocalAnchorA(): Vector2;
3361
+ /** Get the local anchor point relative to objectB's origin
3362
+ * @return {Vector2} */
3363
+ getLocalAnchorB(): Vector2;
3364
+ /** Get the local joint axis relative to bodyA
3365
+ * @return {Vector2} */
3366
+ getLocalAxisA(): Vector2;
3367
+ /** Get the reference angle
3368
+ * @return {number} */
3369
+ getReferenceAngle(): number;
3370
+ /** Get the current joint translation
3371
+ * @return {number} */
3372
+ getJointTranslation(): number;
3373
+ /** Get the current joint translation speed
3374
+ * @return {number} */
3375
+ getJointSpeed(): number;
3376
+ /** Is the joint limit enabled?
3377
+ * @return {boolean} */
3378
+ isLimitEnabled(): boolean;
3379
+ /** Enable/disable the joint limit
3380
+ * @param {boolean} [enable] */
3381
+ enableLimit(enable?: boolean): any;
3382
+ /** Get the lower joint limit
3383
+ * @return {number} */
3384
+ getLowerLimit(): number;
3385
+ /** Get the upper joint limit
3386
+ * @return {number} */
3387
+ getUpperLimit(): number;
3388
+ /** Set the joint limits
3389
+ * @param {number} min
3390
+ * @param {number} max */
3391
+ setLimits(min: number, max: number): any;
3392
+ /** Is the motor enabled?
3393
+ * @return {boolean} */
3394
+ isMotorEnabled(): boolean;
3395
+ /** Enable/disable the joint motor
3396
+ * @param {boolean} [enable] */
3397
+ enableMotor(enable?: boolean): any;
3398
+ /** Set the motor speed
3399
+ * @param {number} speed */
3400
+ setMotorSpeed(speed: number): any;
3401
+ /** Get the motor speed
3402
+ * @return {number} */
3403
+ getMotorSpeed(): number;
3404
+ /** Set the maximum motor force
3405
+ * @param {number} force */
3406
+ setMaxMotorForce(force: number): any;
3407
+ /** Get the maximum motor force
3408
+ * @return {number} */
3409
+ getMaxMotorForce(): number;
3410
+ /** Get the motor force given a time step
3411
+ * @param {number} time
3412
+ * @return {number} */
3413
+ getMotorForce(time: number): number;
3414
+ }
3415
+ /**
3416
+ * Box2D Wheel Joint
3417
+ * - Provides two degrees of freedom: translation along an axis fixed in objectA and rotation
3418
+ * - You can use a joint limit to restrict the range of motion
3419
+ * - You can use a joint motor to drive the motion or to model joint friction
3420
+ * - This joint is designed for vehicle suspensions
3421
+ * @extends Box2dJoint
3422
+ */
3423
+ export class Box2dWheelJoint extends Box2dJoint {
3424
+ /** Create a wheel joint
3425
+ * @param {Box2dObject} objectA
3426
+ * @param {Box2dObject} objectB
3427
+ * @param {Vector2} anchor
3428
+ * @param {Vector2} worldAxis
3429
+ * @param {boolean} [collide] */
3430
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchor: Vector2, worldAxis?: Vector2, collide?: boolean);
3431
+ /** Get the local anchor point relative to objectA's origin
3432
+ * @return {Vector2} */
3433
+ getLocalAnchorA(): Vector2;
3434
+ /** Get the local anchor point relative to objectB's origin
3435
+ * @return {Vector2} */
3436
+ getLocalAnchorB(): Vector2;
3437
+ /** Get the local joint axis relative to bodyA
3438
+ * @return {Vector2} */
3439
+ getLocalAxisA(): Vector2;
3440
+ /** Get the current joint translation
3441
+ * @return {number} */
3442
+ getJointTranslation(): number;
3443
+ /** Get the current joint translation speed
3444
+ * @return {number} */
3445
+ getJointSpeed(): number;
3446
+ /** Is the joint motor enabled?
3447
+ * @return {boolean} */
3448
+ isMotorEnabled(): boolean;
3449
+ /** Enable/disable the joint motor
3450
+ * @param {boolean} [enable] */
3451
+ enableMotor(enable?: boolean): any;
3452
+ /** Set the motor speed
3453
+ * @param {number} speed */
3454
+ setMotorSpeed(speed: number): any;
3455
+ /** Get the motor speed
3456
+ * @return {number} */
3457
+ getMotorSpeed(): number;
3458
+ /** Set the maximum motor torque
3459
+ * @param {number} torque */
3460
+ setMaxMotorTorque(torque: number): any;
3461
+ /** Get the max motor torque
3462
+ * @return {number} */
3463
+ getMaxMotorTorque(): number;
3464
+ /** Get the motor torque for a time step
3465
+ * @return {number} */
3466
+ getMotorTorque(time: any): number;
3467
+ /** Set the spring frequency in Hertz
3468
+ * @param {number} hz */
3469
+ setSpringFrequencyHz(hz: number): any;
3470
+ /** Get the spring frequency in Hertz
3471
+ * @return {number} */
3472
+ getSpringFrequencyHz(): number;
3473
+ /** Set the spring damping ratio
3474
+ * @param {number} ratio */
3475
+ setSpringDampingRatio(ratio: number): any;
3476
+ /** Get the spring damping ratio
3477
+ * @return {number} */
3478
+ getSpringDampingRatio(): number;
3479
+ }
3480
+ /**
3481
+ * Box2D Weld Joint
3482
+ * - Glues two objects together
3483
+ * @extends Box2dJoint
3484
+ */
3485
+ export class Box2dWeldJoint extends Box2dJoint {
3486
+ /** Create a weld joint
3487
+ * @param {Box2dObject} objectA
3488
+ * @param {Box2dObject} objectB
3489
+ * @param {Vector2} anchor
3490
+ * @param {boolean} [collide] */
3491
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchor: Vector2, collide?: boolean);
3492
+ /** Get the local anchor point relative to objectA's origin
3493
+ * @return {Vector2} */
3494
+ getLocalAnchorA(): Vector2;
3495
+ /** Get the local anchor point relative to objectB's origin
3496
+ * @return {Vector2} */
3497
+ getLocalAnchorB(): Vector2;
3498
+ /** Get the reference angle
3499
+ * @return {number} */
3500
+ getReferenceAngle(): number;
3501
+ /** Set the frequency in Hertz
3502
+ * @param {number} hz */
3503
+ setFrequency(hz: number): any;
3504
+ /** Get the frequency in Hertz
3505
+ * @return {number} */
3506
+ getFrequency(): number;
3507
+ /** Set the damping ratio
3508
+ * @param {number} ratio */
3509
+ setSpringDampingRatio(ratio: number): any;
3510
+ /** Get the damping ratio
3511
+ * @return {number} */
3512
+ getSpringDampingRatio(): number;
3513
+ }
3514
+ /**
3515
+ * Box2D Friction Joint
3516
+ * - Used to apply top-down friction
3517
+ * - Provides 2D translational friction and angular friction
3518
+ * @extends Box2dJoint
3519
+ */
3520
+ export class Box2dFrictionJoint extends Box2dJoint {
3521
+ /** Create a friction joint
3522
+ * @param {Box2dObject} objectA
3523
+ * @param {Box2dObject} objectB
3524
+ * @param {Vector2} anchor
3525
+ * @param {boolean} [collide] */
3526
+ constructor(objectA: Box2dObject, objectB: Box2dObject, anchor: Vector2, collide?: boolean);
3527
+ /** Get the local anchor point relative to objectA's origin
3528
+ * @return {Vector2} */
3529
+ getLocalAnchorA(): Vector2;
3530
+ /** Get the local anchor point relative to objectB's origin
3531
+ * @return {Vector2} */
3532
+ getLocalAnchorB(): Vector2;
3533
+ /** Set the maximum friction force
3534
+ * @param {number} force */
3535
+ setMaxForce(force: number): void;
3536
+ /** Get the maximum friction force
3537
+ * @return {number} */
3538
+ getMaxForce(): number;
3539
+ /** Set the maximum friction torque
3540
+ * @param {number} torque */
3541
+ setMaxTorque(torque: number): void;
3542
+ /** Get the maximum friction torque
3543
+ * @return {number} */
3544
+ getMaxTorque(): number;
3545
+ }
3546
+ /**
3547
+ * Box2D Pulley Joint
3548
+ * - Connects to two objects and two fixed ground points
3549
+ * - The pulley supports a ratio such that: length1 + ratio * length2 <= constant
3550
+ * - The force transmitted is scaled by the ratio
3551
+ * @extends Box2dJoint
3552
+ */
3553
+ export class Box2dPulleyJoint extends Box2dJoint {
3554
+ /** Create a pulley joint
3555
+ * @param {Box2dObject} objectA
3556
+ * @param {Box2dObject} objectB
3557
+ * @param {Vector2} groundAnchorA
3558
+ * @param {Vector2} groundAnchorB
3559
+ * @param {Vector2} anchorA
3560
+ * @param {Vector2} anchorB
3561
+ * @param {number} [ratio]
3562
+ * @param {boolean} [collide] */
3563
+ constructor(objectA: Box2dObject, objectB: Box2dObject, groundAnchorA: Vector2, groundAnchorB: Vector2, anchorA: Vector2, anchorB: Vector2, ratio?: number, collide?: boolean);
3564
+ /** Get the first ground anchor
3565
+ * @return {Vector2} */
3566
+ getGroundAnchorA(): Vector2;
3567
+ /** Get the second ground anchor
3568
+ * @return {Vector2} */
3569
+ getGroundAnchorB(): Vector2;
3570
+ /** Get the current length of the segment attached to objectA
3571
+ * @return {number} */
3572
+ getLengthA(): number;
3573
+ /** Get the current length of the segment attached to objectB
3574
+ * @return {number} */
3575
+ getLengthB(): number;
3576
+ /** Get the pulley ratio
3577
+ * @return {number} */
3578
+ getRatio(): number;
3579
+ /** Get the current length of the segment attached to objectA
3580
+ * @return {number} */
3581
+ getCurrentLengthA(): number;
3582
+ /** Get the current length of the segment attached to objectB
3583
+ * @return {number} */
3584
+ getCurrentLengthB(): number;
3585
+ }
3586
+ /**
3587
+ * Box2D Motor Joint
3588
+ * - Controls the relative motion between two objects
3589
+ * - Typical usage is to control the movement of a object with respect to the ground
3590
+ * @extends Box2dJoint
3591
+ */
3592
+ export class Box2dMotorJoint extends Box2dJoint {
3593
+ /** Create a motor joint
3594
+ * @param {Box2dObject} objectA
3595
+ * @param {Box2dObject} objectB */
3596
+ constructor(objectA: Box2dObject, objectB: Box2dObject);
3597
+ /** Set the target linear offset, in frame A, in meters.
3598
+ * @param {Vector2} offset */
3599
+ setLinearOffset(offset: Vector2): void;
3600
+ /** Get the target linear offset, in frame A, in meters.
3601
+ * @return {Vector2} */
3602
+ getLinearOffset(): Vector2;
3603
+ /** Set the target angular offset
3604
+ * @param {number} offset */
3605
+ setAngularOffset(offset: number): void;
3606
+ /** Get the target angular offset
3607
+ * @return {number} */
3608
+ getAngularOffset(): number;
3609
+ /** Set the maximum friction force
3610
+ * @param {number} force */
3611
+ setMaxForce(force: number): void;
3612
+ /** Get the maximum friction force
3613
+ * @return {number} */
3614
+ getMaxForce(): number;
3615
+ /** Set the maximum torque
3616
+ * @param {number} torque */
3617
+ setMaxTorque(torque: number): void;
3618
+ /** Get the maximum torque
3619
+ * @return {number} */
3620
+ getMaxTorque(): number;
3621
+ /** Set the position correction factor in the range [0,1]
3622
+ * @param {number} factor */
3623
+ setCorrectionFactor(factor: number): void;
3624
+ /** Get the position correction factor in the range [0,1]
3625
+ * @return {number} */
3626
+ getCorrectionFactor(): number;
3627
+ }
2319
3628
  }