littlejsengine 1.18.12 → 1.18.15

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.
@@ -291,7 +291,7 @@ declare module "littlejsengine" {
291
291
  * @param {boolean} [screenSpace]
292
292
  * @memberof Debug */
293
293
  export function debugOverlap(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB: Vector2, color?: Color | string, time?: number, screenSpace?: boolean): void;
294
- /** Draw a debug axis aligned bounding box in world space
294
+ /** Draw debug text in world space
295
295
  * @param {string|number} text
296
296
  * @param {Vector2} pos
297
297
  * @param {number} [size]
@@ -358,7 +358,7 @@ declare module "littlejsengine" {
358
358
  export let canvasColorTiles: boolean;
359
359
  /** Color to clear the canvas to before render, does not clear if alpha is 0
360
360
  * @type {Color}
361
- * @memberof Draw */
361
+ * @memberof Settings */
362
362
  export let canvasClearColor: Color;
363
363
  /** The max size of the canvas, centered if window is larger
364
364
  * @type {Vector2}
@@ -516,7 +516,8 @@ declare module "littlejsengine" {
516
516
  * @memberof Settings */
517
517
  export let touchGamepadEnable: boolean;
518
518
  /** True if touch gamepad should have start button in the center
519
- * - Prevents activating if overlappng with virtual stick or buttons if they are enabled
519
+ * - Prevents activating within 2*touchGamepadSize of the virtual stick or face buttons
520
+ * (one radius for the visible control + one radius of buffer beyond its edge)
520
521
  * - When the game is paused, any touch will press the button
521
522
  * - Set size to enable the center button
522
523
  * @type {number}
@@ -739,6 +740,10 @@ declare module "littlejsengine" {
739
740
  * @param {number} alpha
740
741
  * @memberof Settings */
741
742
  export function setTouchGamepadAlpha(alpha: number): void;
743
+ /** Set how long to display the touch gamepad on screen in seconds, set to 0 to always display
744
+ * @param {number} time
745
+ * @memberof Settings */
746
+ export function setTouchGamepadDisplayTime(time: number): void;
742
747
  /** Set to allow vibration hardware if it exists
743
748
  * @param {boolean} enable
744
749
  * @memberof Settings */
@@ -821,17 +826,17 @@ declare module "littlejsengine" {
821
826
  * @param {number} x
822
827
  * @return {number}
823
828
  * @memberof Math */
824
- export const sign: any;
829
+ export function sign(x: number): number;
825
830
  /** Returns hypotenuse of values passed in
826
831
  * @param {...number} values
827
832
  * @return {number}
828
833
  * @memberof Math */
829
- export const hypot: any;
834
+ export function hypot(...values: number[]): number;
830
835
  /** Returns log2 of value passed in
831
836
  * @param {number} x
832
837
  * @return {number}
833
838
  * @memberof Math */
834
- export const log2: any;
839
+ export function log2(x: number): number;
835
840
  /** Returns sin of value passed in
836
841
  * @param {number} x
837
842
  * @return {number}
@@ -1422,7 +1427,8 @@ declare module "littlejsengine" {
1422
1427
  /** Get how long since elapsed, returns 0 if not set (returns negative if currently active)
1423
1428
  * @return {number} */
1424
1429
  get(): number;
1425
- /** Get percentage elapsed based on time it was set to, returns 0 if not set
1430
+ /** Get percentage elapsed based on time it was set to, returns 0 if not set.
1431
+ * Zero-duration timers report 1 (already elapsed).
1426
1432
  * @return {number} */
1427
1433
  getPercent(): number;
1428
1434
  /** Get the time this timer was set to, returns 0 if not set
@@ -1499,9 +1505,9 @@ declare module "littlejsengine" {
1499
1505
  /**
1500
1506
  * Check if object is an array
1501
1507
  * @param {any} a
1502
- * @return {boolean}
1508
+ * @return {a is Array<any>}
1503
1509
  * @memberof Math */
1504
- export function isArray(a: any): boolean;
1510
+ export function isArray(a: any): a is any[];
1505
1511
  /** Color - White #ffffff
1506
1512
  * @type {Color}
1507
1513
  * @memberof Math */
@@ -1580,8 +1586,8 @@ declare module "littlejsengine" {
1580
1586
  * @param {Vector2} [pos=vec2()] - Top left corner of tile in pixels
1581
1587
  * @param {Vector2} [size] - Size of tile in pixels
1582
1588
  * @param {TextureInfo} [textureInfo] - Texture info to use
1583
- * @param {number} [padding] - How many pixels padding around tiles
1584
- * @param {number} [bleed] - How many pixels smaller to draw tiles
1589
+ * @param {number} [padding] - How many pixels padding around all sides of each tile (increases grid size, does not affect tile size)
1590
+ * @param {number} [bleed] - How many pixels smaller to shrink UVS of tiles (does not affect grid size, only UVs)
1585
1591
  */
1586
1592
  constructor(pos?: Vector2, size?: Vector2, textureInfo?: TextureInfo, padding?: number, bleed?: number);
1587
1593
  /** @property {Vector2} - Top left corner of tile in pixels */
@@ -1656,7 +1662,7 @@ declare module "littlejsengine" {
1656
1662
  * - Optimized tile sheet sprite rendering using WebGL batching
1657
1663
  * - Primitive drawing for polygons, ellipses, and lines
1658
1664
  * - Tile-based rendering with TileInfo and TextureInfo classes
1659
- * - Text rendering with custom fonts and FontImage support
1665
+ * - Text rendering with custom fonts and ImageFont support
1660
1666
  * - Color and additive color blending for effects
1661
1667
  * - Rotation, mirroring, and scaling transformations
1662
1668
  * - Camera system with position, scale, and rotation
@@ -1833,9 +1839,9 @@ declare module "littlejsengine" {
1833
1839
  * @param {Vector2} [size=vec2(1)]
1834
1840
  * @param {number} [sides]
1835
1841
  * @param {Color} [color=WHITE]
1836
- * @param {number} [angle]
1837
1842
  * @param {number} [lineWidth]
1838
1843
  * @param {Color} [lineColor=BLACK]
1844
+ * @param {number} [angle]
1839
1845
  * @param {boolean} [useWebGL=glEnable]
1840
1846
  * @param {boolean} [screenSpace]
1841
1847
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
@@ -1864,7 +1870,20 @@ declare module "littlejsengine" {
1864
1870
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1865
1871
  * @memberof Draw */
1866
1872
  export function drawCircle(pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1867
- export function drawCircleGradient(pos: any, size: number, colorInner: Color, colorOuter: Color, useWebGL: boolean, screenSpace: boolean, context: any): void;
1873
+ export function drawEllipseGradient(pos: any, size: Vector2, colorInner: Color, colorOuter: Color, angle: number, useWebGL: boolean, screenSpace: boolean, context: any): void;
1874
+ /** Draw a circle filled with a radial gradient from the center to the rim
1875
+ * - Best when batched with other untextured polys
1876
+ * - If drawing mostly textured sprites, bake the gradient into a texture and use drawTile instead
1877
+ * - Stacking gradients at the exact same position may show a faint vertical artifact
1878
+ * @param {Vector2} pos
1879
+ * @param {number} [size=1] - Diameter
1880
+ * @param {Color} [colorInner=WHITE]
1881
+ * @param {Color} [colorOuter=CLEAR_WHITE]
1882
+ * @param {boolean} [useWebGL=glEnable]
1883
+ * @param {boolean} [screenSpace]
1884
+ * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1885
+ * @memberof Draw */
1886
+ export function drawCircleGradient(pos: Vector2, size?: number, colorInner?: Color, colorOuter?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
1868
1887
  /**
1869
1888
  * @callback Canvas2DDrawFunction - A function that draws to a 2D canvas context
1870
1889
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
@@ -1922,11 +1941,11 @@ declare module "littlejsengine" {
1922
1941
  * @memberof Draw */
1923
1942
  export function combineCanvases(): void;
1924
1943
  /** Engine font image, 8x8 font provided by the engine
1925
- * @type {FontImage}
1944
+ * @type {ImageFont}
1926
1945
  * @memberof Draw */
1927
- export let engineFontImage: FontImage;
1946
+ export let engineImageFont: ImageFont;
1928
1947
  /**
1929
- * Font Image Object - Draw text by using tiles in an image
1948
+ * Image Font Object - Draw text by using tiles in an image
1930
1949
  * - 96 characters (from space to tilde) are stored in an image
1931
1950
  * - A 8x8 default engine font is supplied for general use
1932
1951
  * - This system is WebGL enabled for fast text rendering
@@ -1935,12 +1954,12 @@ declare module "littlejsengine" {
1935
1954
  * @memberof Draw
1936
1955
  * @example
1937
1956
  * // use built in font
1938
- * const font = engineFontImage;
1957
+ * const font = engineImageFont;
1939
1958
  *
1940
1959
  * // draw text
1941
1960
  * font.drawTextScreen('LittleJS\nHello World!', vec2(200, 50));
1942
1961
  */
1943
- export class FontImage {
1962
+ export class ImageFont {
1944
1963
  /** Create an image font
1945
1964
  * @param {TileInfo} tileInfo - Tile info of first character in font
1946
1965
  */
@@ -2087,9 +2106,9 @@ declare module "littlejsengine" {
2087
2106
  * @memberof WebGL */
2088
2107
  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;
2089
2108
  /** Add an untextured rect to the gl draw list
2090
- * Picks the optimal path: if already in poly mode, emits a tristrip rect
2091
- * so it batches with surrounding polys; otherwise uses the instanced path
2092
- * with uvs and rgba zeroed so the color falls through the additive slot.
2109
+ * Zeroes the uvs and rgba so the texture contribution multiplies to 0,
2110
+ * then carries the real color in the additive slot. Works regardless of
2111
+ * which texture is currently bound.
2093
2112
  * @param {number} x
2094
2113
  * @param {number} y
2095
2114
  * @param {number} sizeX
@@ -2424,7 +2443,7 @@ declare module "littlejsengine" {
2424
2443
  */
2425
2444
  playNote(semitoneOffset?: number, pos?: Vector2, volume?: number): SoundInstance;
2426
2445
  /** Get how long this sound is in seconds
2427
- * @return {number} - How long the sound is in seconds (undefined if loading)
2446
+ * @return {number} - How long the sound is in seconds (0 if loading)
2428
2447
  */
2429
2448
  getDuration(): number;
2430
2449
  /** Check if sound is loaded, for sounds fetched from a url
@@ -2505,7 +2524,7 @@ declare module "littlejsengine" {
2505
2524
  */
2506
2525
  getCurrentTime(): number;
2507
2526
  /** Get the total duration of this sound
2508
- * @return {number} - Total duration in seconds
2527
+ * @return {number} - Total duration in seconds (0 if loading)
2509
2528
  */
2510
2529
  getDuration(): number;
2511
2530
  /** Get source of this sound instance
@@ -2641,7 +2660,7 @@ declare module "littlejsengine" {
2641
2660
  color: Color;
2642
2661
  /** @property {Color} - Additive color to apply when rendered */
2643
2662
  additiveColor: any;
2644
- /** @property {boolean} - Should it flip along y axis when rendered */
2663
+ /** @property {boolean} - Should the rendered tile flip along the y axis. Affects rendering and the local→world transform of attached children (a mirrored parent flips its children's localPos.x and localAngle). Does not affect this object's own physics, collision, or localToWorld/worldToLocal. */
2645
2664
  mirror: boolean;
2646
2665
  /** @property {boolean} - Has object been destroyed? */
2647
2666
  destroyed: boolean;
@@ -2898,20 +2917,6 @@ declare module "littlejsengine" {
2898
2917
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] - Canvas 2D context to draw to
2899
2918
  * @memberof Draw */
2900
2919
  draw(pos: Vector2, size?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2901
- /** Draw a tile onto the layer canvas in world space
2902
- * @param {Vector2} pos
2903
- * @param {Vector2} [size=vec2(1)]
2904
- * @param {TileInfo} [tileInfo]
2905
- * @param {Color} [color=WHITE]
2906
- * @param {number} [angle]
2907
- * @param {boolean} [mirror] */
2908
- drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
2909
- /** Draw a rectangle onto the layer canvas in world space
2910
- * @param {Vector2} pos
2911
- * @param {Vector2} [size=vec2(1)]
2912
- * @param {Color} [color=WHITE]
2913
- * @param {number} [angle] */
2914
- drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2915
2920
  /** Create WebGL texture if necessary and copy layer canvas to it */
2916
2921
  updateWebGL(): void;
2917
2922
  /** Check if this layer is using WebGL
@@ -2982,6 +2987,20 @@ declare module "littlejsengine" {
2982
2987
  * @param {number} [angle] - Angle to rotate by
2983
2988
  */
2984
2989
  drawLayerRect(pos: Vector2, size: Vector2, color?: Color, angle?: number): void;
2990
+ /** Draw a tile onto the layer canvas in world space
2991
+ * @param {Vector2} pos
2992
+ * @param {Vector2} [size=vec2(1)]
2993
+ * @param {TileInfo} [tileInfo]
2994
+ * @param {Color} [color=WHITE]
2995
+ * @param {number} [angle]
2996
+ * @param {boolean} [mirror] */
2997
+ drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
2998
+ /** Draw a rectangle onto the layer canvas in world space
2999
+ * @param {Vector2} pos
3000
+ * @param {Vector2} [size=vec2(1)]
3001
+ * @param {Color} [color=WHITE]
3002
+ * @param {number} [angle] */
3003
+ drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
2985
3004
  /** Clear a rectangle in layer space
2986
3005
  * @param {Vector2} pos - position in pixel coordinates
2987
3006
  * @param {Vector2} size
@@ -2998,8 +3017,8 @@ declare module "littlejsengine" {
2998
3017
  clearData(layerPos: Vector2, redraw?: boolean): void;
2999
3018
  /** Get data at a given position in the array
3000
3019
  * @param {Vector2} layerPos - Local position in array
3001
- * @return {TileLayerData} */
3002
- getData(layerPos: Vector2): TileLayerData;
3020
+ * @return {TileLayerData|undefined} */
3021
+ getData(layerPos: Vector2): TileLayerData | undefined;
3003
3022
  /** Called after this layer is redrawn, does nothing by default */
3004
3023
  onRedraw(): void;
3005
3024
  /** @type {[CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D, Vector2, Vector2, number, Color]} */
@@ -3108,7 +3127,7 @@ declare module "littlejsengine" {
3108
3127
  * @param {number} [angleDamping] - How much to dampen particle angular speed
3109
3128
  * @param {number} [gravityScale] - How much gravity effect particles
3110
3129
  * @param {number} [particleConeAngle] - Cone for start particle angle
3111
- * @param {number} [fadeRate] - How quick to fade particles at start/end in percent of life
3130
+ * @param {number} [fadeRate] - Fraction of life spent fading: half at fade-in (start), half at fade-out (end). e.g. .2 = 10% fade-in, 80% full opacity, 10% fade-out
3112
3131
  * @param {number} [randomness] - Apply extra randomness percent
3113
3132
  * @param {boolean} [collideTiles] - Do particles collide against tiles
3114
3133
  * @param {boolean} [additive] - Should particles use additive blend
@@ -3149,7 +3168,7 @@ declare module "littlejsengine" {
3149
3168
  angleSpeed: number;
3150
3169
  /** @property {number} - Cone for start particle angle */
3151
3170
  particleConeAngle: number;
3152
- /** @property {number} - How quick to fade in particles at start/end in percent of life */
3171
+ /** @property {number} - Fraction of life spent fading, split half at start and half at end (e.g. .2 = 10% fade-in + 10% fade-out) */
3153
3172
  fadeRate: number;
3154
3173
  /** @property {number} - Apply extra randomness percent */
3155
3174
  randomness: number;
@@ -3249,6 +3268,21 @@ declare module "littlejsengine" {
3249
3268
  * @default
3250
3269
  * @memberof Settings */
3251
3270
  export let medalsPreventUnlock: boolean;
3271
+ /** How long to show medals for in seconds
3272
+ * @type {number}
3273
+ * @default
3274
+ * @memberof Settings */
3275
+ export let medalDisplayTime: number;
3276
+ /** How quickly to slide on/off medals in seconds
3277
+ * @type {number}
3278
+ * @default
3279
+ * @memberof Settings */
3280
+ export let medalDisplaySlideTime: number;
3281
+ /** Size of medal display
3282
+ * @type {Vector2}
3283
+ * @default Vector2(640,80)
3284
+ * @memberof Settings */
3285
+ export let medalDisplaySize: Vector2;
3252
3286
  /** Initialize medals with a save name used for storage
3253
3287
  * - Call this after creating all medals
3254
3288
  * - Checks if medals are unlocked
@@ -3264,6 +3298,22 @@ declare module "littlejsengine" {
3264
3298
  * @param {MedalCallbackFunction} callback
3265
3299
  * @memberof Medals */
3266
3300
  export function medalsForEach(callback: MedalCallbackFunction): void;
3301
+ /** Set how long to show medals for in seconds
3302
+ * @param {number} time
3303
+ * @memberof Settings */
3304
+ export function setMedalDisplayTime(time: number): void;
3305
+ /** Set how quickly to slide on/off medals in seconds
3306
+ * @param {number} time
3307
+ * @memberof Settings */
3308
+ export function setMedalDisplaySlideTime(time: number): void;
3309
+ /** Set size of medal display
3310
+ * @param {Vector2} size
3311
+ * @memberof Settings */
3312
+ export function setMedalDisplaySize(size: Vector2): void;
3313
+ /** Set to stop medals from being unlockable
3314
+ * @param {boolean} preventUnlock
3315
+ * @memberof Settings */
3316
+ export function setMedalsPreventUnlock(preventUnlock: boolean): void;
3267
3317
  /**
3268
3318
  * Medal - Tracks an unlockable medal
3269
3319
  * @memberof Medals
@@ -3311,37 +3361,6 @@ declare module "littlejsengine" {
3311
3361
  renderIcon(pos: Vector2, size: number): void;
3312
3362
  storageKey(): string;
3313
3363
  }
3314
- /** How long to show medals for in seconds
3315
- * @type {number}
3316
- * @default
3317
- * @memberof Settings */
3318
- export let medalDisplayTime: number;
3319
- /** How quickly to slide on/off medals in seconds
3320
- * @type {number}
3321
- * @default
3322
- * @memberof Settings */
3323
- export let medalDisplaySlideTime: number;
3324
- /** Size of medal display
3325
- * @type {Vector2}
3326
- * @default Vector2(640,80)
3327
- * @memberof Settings */
3328
- export let medalDisplaySize: Vector2;
3329
- /** Set how long to show medals for in seconds
3330
- * @param {number} time
3331
- * @memberof Settings */
3332
- export function setMedalDisplayTime(time: number): void;
3333
- /** Set how quickly to slide on/off medals in seconds
3334
- * @param {number} time
3335
- * @memberof Settings */
3336
- export function setMedalDisplaySlideTime(time: number): void;
3337
- /** Set size of medal display
3338
- * @param {Vector2} size
3339
- * @memberof Settings */
3340
- export function setMedalDisplaySize(size: Vector2): void;
3341
- /** Set to stop medals from being unlockable
3342
- * @param {boolean} preventUnlock
3343
- * @memberof Settings */
3344
- export function setMedalsPreventUnlock(preventUnlock: boolean): void;
3345
3364
  /**
3346
3365
  * LittleJS Newgrounds Plugin
3347
3366
  * - NewgroundsMedal extends Medal with Newgrounds API functionality
@@ -3380,9 +3399,7 @@ declare module "littlejsengine" {
3380
3399
  host: string;
3381
3400
  /** @property {string|null} - Newgrounds session id from the URL (null when not logged in) */
3382
3401
  session_id: string;
3383
- /** @property {Array} - Medals fetched from Newgrounds (empty until session is active) */
3384
3402
  medals: any;
3385
- /** @property {Array} - Scoreboards fetched from Newgrounds */
3386
3403
  scoreboards: any;
3387
3404
  /** Send message to unlock a medal by id
3388
3405
  * @param {number} id - The medal id */
@@ -3498,6 +3515,14 @@ declare module "littlejsengine" {
3498
3515
  */
3499
3516
  playMusic(volume?: number, loop?: boolean): SoundInstance;
3500
3517
  }
3518
+ /** Generate samples for a ZzFM song with given parameters
3519
+ * @param {Array} instruments - Array of ZzFX sound parameters
3520
+ * @param {Array} patterns - Array of pattern data
3521
+ * @param {Array} sequence - Array of pattern indexes
3522
+ * @param {number} [BPM] - Playback speed of the song in BPM
3523
+ * @return {Array} - Left and right channel sample data
3524
+ * @memberof ZzFXM */
3525
+ export function zzfxM(instruments: any[], patterns: any[], sequence: any[], BPM?: number): any[];
3501
3526
  /**
3502
3527
  * LittleJS User Interface Plugin
3503
3528
  * - call new UISystemPlugin() to setup the UI system
@@ -3659,6 +3684,7 @@ declare module "littlejsengine" {
3659
3684
  * @param {DragAndDropCallback} [onDragLeave] - when a file is dragged off the window
3660
3685
  * @param {DragAndDropCallback} [onDragOver] - continuously when dragging over */
3661
3686
  setupDragAndDrop(onDrop?: (event: DragEvent) => any, onDragEnter?: (event: DragEvent) => any, onDragLeave?: (event: DragEvent) => any, onDragOver?: (event: DragEvent) => any): void;
3687
+ _dragListeners: any[];
3662
3688
  /** Convert a screen space position to native UI position
3663
3689
  * @param {Vector2} pos
3664
3690
  * @return {Vector2} */
@@ -4225,7 +4251,9 @@ declare module "littlejsengine" {
4225
4251
  /** Add a box shape to the body
4226
4252
  * @param {Vector2} [size]
4227
4253
  * @param {Vector2} [offset]
4228
- * @param {number} [angle]
4254
+ * @param {number} [angle] - LittleJS convention (clockwise positive).
4255
+ * Negated internally to match Box2D's CCW-positive convention so the
4256
+ * fixture aligns with the same angle passed to drawRect/drawTile.
4229
4257
  * @param {number} [density]
4230
4258
  * @param {number} [friction]
4231
4259
  * @param {number} [restitution]