littlejsengine 1.9.5 → 1.9.7

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.
@@ -214,6 +214,11 @@ declare module "littlejsengine" {
214
214
  * @default
215
215
  * @memberof Settings */
216
216
  export let showSplashScreen: boolean;
217
+ /** Disables all rendering, audio, and input for servers
218
+ * @type {Boolean}
219
+ * @default
220
+ * @memberof Settings */
221
+ export let headlessMode: boolean;
217
222
  /** Default size of tiles in pixels
218
223
  * @type {Vector2}
219
224
  * @default Vector2(16,16)
@@ -389,6 +394,10 @@ declare module "littlejsengine" {
389
394
  * @param {Boolean} show
390
395
  * @memberof Settings */
391
396
  export function setShowSplashScreen(show: boolean): void;
397
+ /** Set to disalbe rendering, audio, and input for servers
398
+ * @param {Boolean} headless
399
+ * @memberof Settings */
400
+ export function setHeadlessMode(headless: boolean): void;
392
401
  /** Set if webgl rendering is enabled
393
402
  * @param {Boolean} enable
394
403
  * @memberof Settings */
@@ -1103,9 +1112,9 @@ declare module "littlejsengine" {
1103
1112
  * @param {Color} [additiveColor=(0,0,0,0)] - Additive color to be applied
1104
1113
  * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1105
1114
  * @param {Boolean} [screenSpace=false] - If true the pos and size are in screen space
1106
- * @param {CanvasRenderingContext2D} [context] - Canvas 2D context to draw to
1115
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
1107
1116
  * @memberof Draw */
1108
- export function drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1117
+ 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;
1109
1118
  /** Draw colored rect centered on pos
1110
1119
  * @param {Vector2} pos
1111
1120
  * @param {Vector2} [size=(1,1)]
@@ -1113,9 +1122,9 @@ declare module "littlejsengine" {
1113
1122
  * @param {Number} [angle]
1114
1123
  * @param {Boolean} [useWebGL=glEnable]
1115
1124
  * @param {Boolean} [screenSpace=false]
1116
- * @param {CanvasRenderingContext2D} [context]
1125
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1117
1126
  * @memberof Draw */
1118
- export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1127
+ export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1119
1128
  /** Draw colored line between two points
1120
1129
  * @param {Vector2} posA
1121
1130
  * @param {Vector2} posB
@@ -1123,9 +1132,9 @@ declare module "littlejsengine" {
1123
1132
  * @param {Color} [color=(1,1,1,1)]
1124
1133
  * @param {Boolean} [useWebGL=glEnable]
1125
1134
  * @param {Boolean} [screenSpace=false]
1126
- * @param {CanvasRenderingContext2D} [context]
1135
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1127
1136
  * @memberof Draw */
1128
- export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1137
+ export function drawLine(posA: Vector2, posB: Vector2, thickness?: number, color?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1129
1138
  /** Draw directly to a 2d canvas context in world space
1130
1139
  * @param {Vector2} pos
1131
1140
  * @param {Vector2} size
@@ -1133,15 +1142,15 @@ declare module "littlejsengine" {
1133
1142
  * @param {Boolean} mirror
1134
1143
  * @param {Function} drawFunction
1135
1144
  * @param {Boolean} [screenSpace=false]
1136
- * @param {CanvasRenderingContext2D} [context=mainContext]
1145
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
1137
1146
  * @memberof Draw */
1138
- export function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function, screenSpace?: boolean, context?: CanvasRenderingContext2D): void;
1147
+ export function drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1139
1148
  /** Enable normal or additive blend mode
1140
1149
  * @param {Boolean} [additive]
1141
1150
  * @param {Boolean} [useWebGL=glEnable]
1142
- * @param {CanvasRenderingContext2D} [context=mainContext]
1151
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=mainContext]
1143
1152
  * @memberof Draw */
1144
- export function setBlendMode(additive?: boolean, useWebGL?: boolean, context?: CanvasRenderingContext2D): void;
1153
+ export function setBlendMode(additive?: boolean, useWebGL?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1145
1154
  /** Draw text on overlay canvas in screen space
1146
1155
  * Automatically splits new lines into rows
1147
1156
  * @param {String} text
@@ -1152,9 +1161,9 @@ declare module "littlejsengine" {
1152
1161
  * @param {Color} [lineColor=(0,0,0,1)]
1153
1162
  * @param {CanvasTextAlign} [textAlign]
1154
1163
  * @param {String} [font=fontDefault]
1155
- * @param {CanvasRenderingContext2D} [context=overlayContext]
1164
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
1156
1165
  * @memberof Draw */
1157
- export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D): void;
1166
+ export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1158
1167
  /** Draw text on overlay canvas in world space
1159
1168
  * Automatically splits new lines into rows
1160
1169
  * @param {String} text
@@ -1165,9 +1174,9 @@ declare module "littlejsengine" {
1165
1174
  * @param {Color} [lineColor=(0,0,0,1)]
1166
1175
  * @param {CanvasTextAlign} [textAlign='center']
1167
1176
  * @param {String} [font=fontDefault]
1168
- * @param {CanvasRenderingContext2D} [context=overlayContext]
1177
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
1169
1178
  * @memberof Draw */
1170
- export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D): void;
1179
+ export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1171
1180
  export let engineFontImage: any;
1172
1181
  /**
1173
1182
  * Font Image Object - Draw text on a 2D canvas by using characters in an image
@@ -1186,13 +1195,13 @@ declare module "littlejsengine" {
1186
1195
  * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1187
1196
  * @param {Vector2} [tileSize=(8,8)] - Size of the font source tiles
1188
1197
  * @param {Vector2} [paddingSize=(0,1)] - How much extra space to add between characters
1189
- * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
1198
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext] - context to draw to
1190
1199
  */
1191
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
1200
+ constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D);
1192
1201
  image: any;
1193
1202
  tileSize: Vector2;
1194
1203
  paddingSize: Vector2;
1195
- context: CanvasRenderingContext2D;
1204
+ context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
1196
1205
  /** Draw text in world space using the image font
1197
1206
  * @param {String} text
1198
1207
  * @param {Vector2} pos
@@ -1215,6 +1224,10 @@ declare module "littlejsengine" {
1215
1224
  /** Toggle fullsceen mode
1216
1225
  * @memberof Draw */
1217
1226
  export function toggleFullscreen(): void;
1227
+ /** Get the camera's visible area in world space
1228
+ * @return {Vector2}
1229
+ * @memberof Draw */
1230
+ export function getCameraSize(): Vector2;
1218
1231
  /**
1219
1232
  * LittleJS WebGL Interface
1220
1233
  * - All webgl used by the engine is wrapped up here
@@ -1372,16 +1385,6 @@ declare module "littlejsengine" {
1372
1385
  /** True if a touch device has been detected
1373
1386
  * @memberof Input */
1374
1387
  export const isTouchDevice: boolean;
1375
- /**
1376
- * LittleJS Audio System
1377
- * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1378
- * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1379
- * - Caches sounds and music for fast playback
1380
- * - Can attenuate and apply stereo panning to sounds
1381
- * - Ability to play mp3, ogg, and wave files
1382
- * - Speech synthesis functions
1383
- * @namespace Audio
1384
- */
1385
1388
  /**
1386
1389
  * Sound Object - Stores a sound for later use and can be played positionally
1387
1390
  *
@@ -1456,9 +1459,9 @@ declare module "littlejsengine" {
1456
1459
  * @param {Number} [randomness] - How much to randomize frequency each time sound plays
1457
1460
  * @param {Number} [range=soundDefaultRange] - World space max range of sound, will not play if camera is farther away
1458
1461
  * @param {Number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering off
1462
+ * @param {Function} [onloadCallback] - callback function to call when sound is loaded
1459
1463
  */
1460
- constructor(filename: string, randomness?: number, range?: number, taper?: number);
1461
- randomness: number;
1464
+ constructor(filename: string, randomness?: number, range?: number, taper?: number, onloadCallback?: Function);
1462
1465
  }
1463
1466
  /**
1464
1467
  * Music Object - Stores a zzfx music track for later use
@@ -1507,9 +1510,9 @@ declare module "littlejsengine" {
1507
1510
  * @param {String} filename - Location of sound file to play
1508
1511
  * @param {Number} [volume] - How much to scale volume by
1509
1512
  * @param {Boolean} [loop] - True if the music should loop
1510
- * @return {HTMLAudioElement} - The audio element for this sound
1513
+ * @return {SoundWave} - The sound object for this file
1511
1514
  * @memberof Audio */
1512
- export function playAudioFile(filename: string, volume?: number, loop?: boolean): HTMLAudioElement;
1515
+ export function playAudioFile(filename: string, volume?: number, loop?: boolean): SoundWave;
1513
1516
  /** Speak text with passed in settings
1514
1517
  * @param {String} text - The text to speak
1515
1518
  * @param {String} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
@@ -1528,6 +1531,16 @@ declare module "littlejsengine" {
1528
1531
  * @return {Number} - The frequency of the note
1529
1532
  * @memberof Audio */
1530
1533
  export function getNoteFrequency(semitoneOffset: number, rootFrequency?: number): number;
1534
+ /**
1535
+ * LittleJS Audio System
1536
+ * - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
1537
+ * - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
1538
+ * - Caches sounds and music for fast playback
1539
+ * - Can attenuate and apply stereo panning to sounds
1540
+ * - Ability to play mp3, ogg, and wave files
1541
+ * - Speech synthesis functions
1542
+ * @namespace Audio
1543
+ */
1531
1544
  /** Audio context used by the engine
1532
1545
  * @type {AudioContext}
1533
1546
  * @memberof Audio */
@@ -1625,6 +1638,8 @@ declare module "littlejsengine" {
1625
1638
  spawnTime: number;
1626
1639
  /** @property {Array} - List of children of this object */
1627
1640
  children: any[];
1641
+ /** @property {Boolean} - Limit object speed using linear or circular math */
1642
+ clampSpeedLinear: boolean;
1628
1643
  /** @property {EngineObject} - Parent of object if in local space */
1629
1644
  parent: any;
1630
1645
  /** @property {Vector2} - Local position if child */
@@ -1639,7 +1654,9 @@ declare module "littlejsengine" {
1639
1654
  isSolid: boolean;
1640
1655
  /** @property {Boolean} - Object collides with raycasts */
1641
1656
  collideRaycast: boolean;
1642
- /** Update the object transform and physics, called automatically by engine once each frame */
1657
+ /** Update the object transform, called automatically by engine even when paused */
1658
+ updateTransforms(): void;
1659
+ /** Update the object physics, called automatically by engine once each frame */
1643
1660
  update(): void;
1644
1661
  groundObject: any;
1645
1662
  /** Render the object, draws a tile by default, automatically called each frame, sorted by renderOrder */
@@ -1785,22 +1802,13 @@ declare module "littlejsengine" {
1785
1802
  constructor(position?: Vector2, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
1786
1803
  /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1787
1804
  canvas: HTMLCanvasElement;
1788
- /** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
1805
+ /** @property {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
1789
1806
  context: CanvasRenderingContext2D;
1790
1807
  /** @property {Vector2} - How much to scale this layer when rendered */
1791
1808
  scale: Vector2;
1792
1809
  /** @property {Boolean} - If true this layer will render to overlay canvas and appear above all objects */
1793
1810
  isOverlay: boolean;
1794
1811
  data: TileLayerData[];
1795
- /** Set data at a given position in the array
1796
- * @param {Vector2} layerPos - Local position in array
1797
- * @param {TileLayerData} data - Data to set
1798
- * @param {Boolean} [redraw] - Force the tile to redraw if true */
1799
- setData(layerPos: Vector2, data: TileLayerData, redraw?: boolean): void;
1800
- /** Get data at a given position in the array
1801
- * @param {Vector2} layerPos - Local position in array
1802
- * @return {TileLayerData} */
1803
- getData(layerPos: Vector2): TileLayerData;
1804
1812
  /** Draw all the tile data to an offscreen canvas
1805
1813
  * - This may be slow in some browsers but only needs to be done once */
1806
1814
  redraw(): void;
@@ -1808,8 +1816,6 @@ declare module "littlejsengine" {
1808
1816
  * - This can be used to manually update small parts of the level
1809
1817
  * @param {Boolean} [clear] - Should it clear the canvas before drawing */
1810
1818
  redrawStart(clear?: boolean): void;
1811
- /** @type {[HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number]} */
1812
- savedRenderSettings: [HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number];
1813
1819
  /** Call to end the redraw process */
1814
1820
  redrawEnd(): void;
1815
1821
  /** Draw the tile at a given position in the tile grid
@@ -1826,6 +1832,17 @@ declare module "littlejsengine" {
1826
1832
  * @param {Boolean} mirror
1827
1833
  * @param {Function} drawFunction */
1828
1834
  drawCanvas2D(pos: Vector2, size: Vector2, angle: number, mirror: boolean, drawFunction: Function): void;
1835
+ /** Set data at a given position in the array
1836
+ * @param {Vector2} layerPos - Local position in array
1837
+ * @param {TileLayerData} data - Data to set
1838
+ * @param {Boolean} [redraw] - Force the tile to redraw if true */
1839
+ setData(layerPos: Vector2, data: TileLayerData, redraw?: boolean): void;
1840
+ /** Get data at a given position in the array
1841
+ * @param {Vector2} layerPos - Local position in array
1842
+ * @return {TileLayerData} */
1843
+ getData(layerPos: Vector2): TileLayerData;
1844
+ /** @type {[HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number]} */
1845
+ savedRenderSettings: [HTMLCanvasElement, CanvasRenderingContext2D, Vector2, Vector2, number];
1829
1846
  /** Draw a tile directly onto the layer canvas in world space
1830
1847
  * @param {Vector2} pos
1831
1848
  * @param {Vector2} [size=(1,1)]
@@ -1948,22 +1965,23 @@ declare module "littlejsengine" {
1948
1965
  */
1949
1966
  export class Particle extends EngineObject {
1950
1967
  /**
1951
- * Create a particle with the given shis.colorStart = undefined;ettings
1952
- * @param {Vector2} position - World space position of the particle
1953
- * @param {TileInfo} [tileInfo] - Tile info to render particles
1954
- * @param {Number} [angle] - Angle to rotate the particle
1955
- * @param {Color} [colorStart] - Color at start of life
1956
- * @param {Color} [colorEnd] - Color at end of life
1957
- * @param {Number} [lifeTime] - How long to live for
1958
- * @param {Number} [sizeStart] - Angle to rotate the particle
1959
- * @param {Number} [sizeEnd] - Angle to rotate the particle
1960
- * @param {Number} [fadeRate] - Angle to rotate the particle
1961
- * @param {Boolean} [additive] - Angle to rotate the particle
1962
- * @param {Number} [trailScale] - If a trail, how long to make it
1968
+ * Create a particle with the passed in settings
1969
+ * Typically this is created automatically by a ParticleEmitter
1970
+ * @param {Vector2} position - World space position of the particle
1971
+ * @param {TileInfo} tileInfo - Tile info to render particles
1972
+ * @param {Number} angle - Angle to rotate the particle
1973
+ * @param {Color} colorStart - Color at start of life
1974
+ * @param {Color} colorEnd - Color at end of life
1975
+ * @param {Number} lifeTime - How long to live for
1976
+ * @param {Number} sizeStart - Size at start of life
1977
+ * @param {Number} sizeEnd - Size at end of life
1978
+ * @param {Number} fadeRate - How quick to fade in/out
1979
+ * @param {Boolean} additive - Does it use additive blend mode
1980
+ * @param {Number} trailScale - If a trail, how long to make it
1963
1981
  * @param {ParticleEmitter} [localSpaceEmitter] - Parent emitter if local space
1964
- * @param {Function} [destroyCallback] - Called when particle dies
1982
+ * @param {Function} [destroyCallback] - Callback when particle dies
1965
1983
  */
1966
- constructor(position: Vector2, tileInfo?: TileInfo, angle?: number, colorStart?: Color, colorEnd?: Color, lifeTime?: number, sizeStart?: number, sizeEnd?: number, fadeRate?: number, additive?: boolean, trailScale?: number, localSpaceEmitter?: ParticleEmitter, destroyCallback?: Function);
1984
+ constructor(position: Vector2, tileInfo: TileInfo, angle: number, colorStart: Color, colorEnd: Color, lifeTime: number, sizeStart: number, sizeEnd: number, fadeRate: number, additive: boolean, trailScale: number, localSpaceEmitter?: ParticleEmitter, destroyCallback?: Function);
1967
1985
  /** @property {Color} - Color at start of life */
1968
1986
  colorStart: Color;
1969
1987
  /** @property {Color} - Calculated change in color */