littlejsengine 1.17.1 → 1.17.5

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.
@@ -123,11 +123,11 @@ declare module "littlejsengine" {
123
123
  * @example
124
124
  * // Basic engine startup
125
125
  * engineInit(
126
- * () => { LOG('Game initialized!'); }, // gameInit
127
- * () => { updateGameLogic(); }, // gameUpdate
128
- * () => { updateUI(); }, // gameUpdatePost
129
- * () => { drawBackground(); }, // gameRender
130
- * () => { drawHUD(); }, // gameRenderPost
126
+ * ()=> { LOG('Game initialized!'); }, // gameInit
127
+ * ()=> { updateGameLogic(); }, // gameUpdate
128
+ * ()=> { updateUI(); }, // gameUpdatePost
129
+ * ()=> { drawBackground(); }, // gameRender
130
+ * ()=> { drawHUD(); }, // gameRenderPost
131
131
  * ['tiles.png', 'tilesLevel.png'] // images to load
132
132
  * );
133
133
  * @memberof Engine */
@@ -203,13 +203,13 @@ declare module "littlejsengine" {
203
203
  /** Asserts if the expression is false, does nothing in release builds
204
204
  * Halts execution if the assert fails and throws an error
205
205
  * @param {boolean} assert
206
- * @param {...Object} [output] - error message output
206
+ * @param {...Object} output - error message output
207
207
  * @memberof Debug */
208
- export function ASSERT(assert: boolean, ...output?: any[]): void;
208
+ export function ASSERT(assert: boolean, ...output: any[]): void;
209
209
  /** Log to console if debug is enabled, does nothing in release builds
210
- * @param {...Object} [output] - message output
210
+ * @param {...Object} output - message output
211
211
  * @memberof Debug */
212
- export function LOG(...output?: any[]): void;
212
+ export function LOG(...output: any[]): void;
213
213
  /** Draw a debug rectangle in world space
214
214
  * @param {Vector2} pos
215
215
  * @param {Vector2} [size=vec2(0)]
@@ -734,22 +734,22 @@ declare module "littlejsengine" {
734
734
  * @memberof Math */
735
735
  export const PI: number;
736
736
  /** Returns absolute value of value passed in
737
- * @param {number} value
737
+ * @param {number} x
738
738
  * @return {number}
739
739
  * @memberof Math */
740
740
  export const abs: (x: number) => number;
741
741
  /** Returns floored value of value passed in
742
- * @param {number} value
742
+ * @param {number} x
743
743
  * @return {number}
744
744
  * @memberof Math */
745
745
  export const floor: (x: number) => number;
746
746
  /** Returns ceiled value of value passed in
747
- * @param {number} value
747
+ * @param {number} x
748
748
  * @return {number}
749
749
  * @memberof Math */
750
750
  export const ceil: (x: number) => number;
751
751
  /** Returns rounded value passed in
752
- * @param {number} value
752
+ * @param {number} x
753
753
  * @return {number}
754
754
  * @memberof Math */
755
755
  export const round: (x: number) => number;
@@ -764,7 +764,7 @@ declare module "littlejsengine" {
764
764
  * @memberof Math */
765
765
  export const max: (...values: number[]) => number;
766
766
  /** Returns the sign of value passed in
767
- * @param {number} value
767
+ * @param {number} x
768
768
  * @return {number}
769
769
  * @memberof Math */
770
770
  export const sign: (x: number) => number;
@@ -774,22 +774,22 @@ declare module "littlejsengine" {
774
774
  * @memberof Math */
775
775
  export const hypot: (...values: number[]) => number;
776
776
  /** Returns log2 of value passed in
777
- * @param {number} value
777
+ * @param {number} x
778
778
  * @return {number}
779
779
  * @memberof Math */
780
780
  export const log2: (x: number) => number;
781
781
  /** Returns sin of value passed in
782
- * @param {number} value
782
+ * @param {number} x
783
783
  * @return {number}
784
784
  * @memberof Math */
785
785
  export const sin: (x: number) => number;
786
786
  /** Returns cos of value passed in
787
- * @param {number} value
787
+ * @param {number} x
788
788
  * @return {number}
789
789
  * @memberof Math */
790
790
  export const cos: (x: number) => number;
791
791
  /** Returns tan of value passed in
792
- * @param {number} value
792
+ * @param {number} x
793
793
  * @return {number}
794
794
  * @memberof Math */
795
795
  export const tan: (x: number) => number;
@@ -2132,24 +2132,38 @@ declare module "littlejsengine" {
2132
2132
  * @memberof Audio */
2133
2133
  export const audioDefaultSampleRate: 44100;
2134
2134
  /**
2135
- * Sound Object - Stores a sound for later use and can be played positionally
2135
+ * Sound Object - Stores a sound for later
2136
+ * - this can be used to load and play wave, mp3, and ogg files
2137
+ * - it can also create sounds using the ZzFX sound generator
2138
+ * - can attenuate and apply stereo panning to sounds
2139
+ * - sound instance control with pause/resume capability
2136
2140
  *
2137
2141
  * <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
2138
2142
  * @memberof Audio
2139
2143
  * @example
2140
- * // create a sound
2144
+ * // load an audio asset file
2145
+ * const sound_example = new Sound('sound.mp3');
2146
+ *
2147
+ * // create a zzfx sound
2141
2148
  * const sound_example = new Sound([.5,.5]);
2142
2149
  *
2143
- * // play the sound
2150
+ * // play a sound
2144
2151
  * sound_example.play();
2145
2152
  */
2146
2153
  export class Sound {
2147
- /** Create a sound object and cache the zzfx samples for later use
2148
- * @param {Array} zzfxSound - Array of zzfx parameters, ex. [.5,.5]
2154
+ /**
2155
+ * @callback SoundLoadCallback - Function called when sound is loaded
2156
+ * @param {Sound} sound
2157
+ * @memberof Audio
2158
+ */
2159
+ /** Create a sound object and cache the audio for later use
2160
+ * @param {string|Array} [asset] - Filename of audio file or zzfx array
2161
+ * @param {number} [randomness] - How much to randomize frequency each time sound plays, for zzfx sounds the zzfx default is used if undefined
2149
2162
  * @param {number} [range=soundDefaultRange] - World space max range of sound
2150
2163
  * @param {number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
2164
+ * @param {SoundLoadCallback} [onloadCallback] - callback function to call when sound is loaded
2151
2165
  */
2152
- constructor(zzfxSound: any[], range?: number, taper?: number);
2166
+ constructor(asset?: string | any[], randomness?: number, range?: number, taper?: number, onloadCallback?: (sound: Sound) => Sound);
2153
2167
  /** @property {number} - World space max range of sound */
2154
2168
  range: number;
2155
2169
  /** @property {number} - At what percentage of range should it start tapering */
@@ -2160,6 +2174,8 @@ declare module "littlejsengine" {
2160
2174
  sampleRate: number;
2161
2175
  /** @property {number} - Percentage of this sound currently loaded */
2162
2176
  loadedPercent: number;
2177
+ /** @property {SoundLoadCallback} - function to call when sound is loaded */
2178
+ onloadCallback: (sound: Sound) => Sound;
2163
2179
  sampleChannels: any[][];
2164
2180
  /** Play the sound
2165
2181
  * Sounds may not play until a user interaction occurs
@@ -2176,7 +2192,7 @@ declare module "littlejsengine" {
2176
2192
  * @param {number} [volume] - Volume to play the music at
2177
2193
  * @param {boolean} [loop] - Should the music loop?
2178
2194
  * @param {boolean} [paused] - Should the music start paused
2179
- * @return {SoundInstance} - The audio source node
2195
+ * @return {SoundInstance} - The sound instance
2180
2196
  */
2181
2197
  playMusic(volume?: number, loop?: boolean, paused?: boolean): SoundInstance;
2182
2198
  /** Play the sound as a musical note with a semitone offset
@@ -2184,7 +2200,7 @@ declare module "littlejsengine" {
2184
2200
  * @param {number} [semitoneOffset=0] - How many semitones to offset pitch
2185
2201
  * @param {Vector2} [pos] - World space position to play the sound if any
2186
2202
  * @param {number} [volume=1] - How much to scale volume by
2187
- * @return {SoundInstance} - The audio source node
2203
+ * @return {SoundInstance} - The sound instance
2188
2204
  */
2189
2205
  playNote(semitoneOffset?: number, pos?: Vector2, volume?: number): SoundInstance;
2190
2206
  /** Get how long this sound is in seconds
@@ -2195,36 +2211,7 @@ declare module "littlejsengine" {
2195
2211
  * @return {boolean} - True if sound is loaded and ready to play
2196
2212
  */
2197
2213
  isLoaded(): boolean;
2198
- }
2199
- /**
2200
- * Sound Wave Object - Loads and stores an audio file for later use
2201
- * - this can be used to load and play wave, mp3, and ogg files
2202
- * @extends Sound
2203
- * @memberof Audio
2204
- * @example
2205
- * // load an audio asset file
2206
- * const sound_example = new SoundWave('sound.mp3');
2207
- *
2208
- * // play the sound
2209
- * sound_example.play();
2210
- */
2211
- export class SoundWave extends Sound {
2212
- /**
2213
- * @callback SoundLoadCallback - Function called when sound is loaded
2214
- * @param {SoundWave} sound
2215
- * @memberof Audio
2216
- */
2217
- /** Create a sound object and cache the wave file for later use
2218
- * @param {string} filename - Filename of audio file to load
2219
- * @param {number} [randomness] - How much to randomize frequency each time sound plays
2220
- * @param {number} [range=soundDefaultRange] - World space max range of sound
2221
- * @param {number} [taper=soundDefaultTaper] - At what percentage of range should it start tapering
2222
- * @param {SoundLoadCallback} [onloadCallback] - callback function to call when sound is loaded
2223
- */
2224
- constructor(filename: string, randomness?: number, range?: number, taper?: number, onloadCallback?: (sound: SoundWave) => SoundWave);
2225
- /** @property {SoundLoadCallback} - callback function to call when sound is loaded */
2226
- onloadCallback: (sound: SoundWave) => SoundWave;
2227
- /** Loads a sound from a URL and decodes it into sample data. Must be used with await!
2214
+ /** Loads a sound from a URL and decodes it into sample data.
2228
2215
  * @param {string} filename
2229
2216
  * @return {Promise<void>} */
2230
2217
  loadSound(filename: string): Promise<void>;
@@ -2644,14 +2631,14 @@ declare module "littlejsengine" {
2644
2631
  */
2645
2632
  export class CanvasLayer extends EngineObject {
2646
2633
  /** Create a canvas layer object
2647
- * @param {Vector2} [position] - World space position of the layer
2634
+ * @param {Vector2} [pos] - World space position of the layer
2648
2635
  * @param {Vector2} [size] - World space size of the layer
2649
2636
  * @param {number} [angle] - Angle the layer is rotated by
2650
2637
  * @param {number} [renderOrder] - Objects sorted by renderOrder
2651
2638
  * @param {Vector2} [canvasSize] - Default size of canvas, can be changed later
2652
2639
  * @param {boolean} [useWebGL] - Should this layer use WebGL for rendering
2653
2640
  */
2654
- constructor(position?: Vector2, size?: Vector2, angle?: number, renderOrder?: number, canvasSize?: Vector2, useWebGL?: boolean);
2641
+ constructor(pos?: Vector2, size?: Vector2, angle?: number, renderOrder?: number, canvasSize?: Vector2, useWebGL?: boolean);
2655
2642
  /** @property {HTMLCanvasElement} - The canvas used by this layer */
2656
2643
  canvas: OffscreenCanvas;
2657
2644
  /** @property {OffscreenCanvasRenderingContext2D} - The 2D canvas context used by this layer */
@@ -2703,12 +2690,13 @@ declare module "littlejsengine" {
2703
2690
  */
2704
2691
  export class TileLayer extends CanvasLayer {
2705
2692
  /** Create a tile layer object
2706
- * @param {Vector2} position - World space position
2693
+ * @param {Vector2} pos - World space position
2707
2694
  * @param {Vector2} size - World space size
2708
2695
  * @param {TileInfo} [tileInfo] - Default tile info for layer (used for size and texture)
2709
2696
  * @param {number} [renderOrder] - Objects are sorted by renderOrder
2697
+ * @param {boolean} [useWebGL] - Should this layer use WebGL for rendering
2710
2698
  */
2711
- constructor(position: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number);
2699
+ constructor(pos: Vector2, size: Vector2, tileInfo?: TileInfo, renderOrder?: number, useWebGL?: boolean);
2712
2700
  /** @property {Array<TileLayerData>} - Default tile info for layer */
2713
2701
  data: TileLayerData[];
2714
2702
  /** @property {boolean} - Is this layer using a webgl texture? */
@@ -2722,14 +2710,14 @@ declare module "littlejsengine" {
2722
2710
  redrawStart(clear?: boolean): void;
2723
2711
  /** Call to end the redraw process */
2724
2712
  redrawEnd(): void;
2725
- /** Draw the tile at a given position in the tile grid
2713
+ /** Draw the tile at a given position in the tile layer
2726
2714
  * This can be used to clear out tiles when they are destroyed
2727
2715
  * Tiles can also be redrawn if inside a redrawStart/End block
2728
2716
  * @param {Vector2} layerPos
2729
2717
  * @param {boolean} [clear] - should the old tile be cleared out
2730
2718
  */
2731
2719
  drawTileData(layerPos: Vector2, clear?: boolean): void;
2732
- /** Draw the tile at a given position in the tile grid
2720
+ /** Draw the tile at a given position in the tile layer
2733
2721
  * This can be used to clear tiles when they are destroyed
2734
2722
  * For better performance use drawTileData inside a redrawStart/End block
2735
2723
  * @param {Vector2} layerPos
@@ -2762,6 +2750,10 @@ declare module "littlejsengine" {
2762
2750
  * @param {TileLayerData} data - Data to set
2763
2751
  * @param {boolean} [redraw] - Force the tile to redraw if true */
2764
2752
  setData(layerPos: Vector2, data: TileLayerData, redraw?: boolean): void;
2753
+ /** Clear data at a given position in the array
2754
+ * @param {Vector2} layerPos - Local position in array
2755
+ * @param {boolean} [redraw] - Force the tile to redraw if true */
2756
+ clearData(layerPos: Vector2, redraw?: boolean): void;
2765
2757
  /** Get data at a given position in the array
2766
2758
  * @param {Vector2} layerPos - Local position in array
2767
2759
  * @return {TileLayerData} */
@@ -2784,14 +2776,17 @@ declare module "littlejsengine" {
2784
2776
  /** Clear and initialize tile collision to new size
2785
2777
  * @param {Vector2} size - width and height of tile collision 2d grid */
2786
2778
  initCollision(size: Vector2): void;
2787
- /** Set tile collision data for a given cell in the grid
2788
- * @param {Vector2} gridPos
2779
+ /** Set tile collision data for a given cell in the layer
2780
+ * @param {Vector2} layerPos
2789
2781
  * @param {number} [data] */
2790
- setCollisionData(gridPos: Vector2, data?: number): void;
2791
- /** Get tile collision data for a given cell in the grid
2792
- * @param {Vector2} gridPos
2782
+ setCollisionData(layerPos: Vector2, data?: number): void;
2783
+ /** Clear tile collision data for a given cell in the layer
2784
+ * @param {Vector2} layerPos */
2785
+ clearCollisionData(layerPos: Vector2): void;
2786
+ /** Get tile collision data for a given cell in the layer
2787
+ * @param {Vector2} layerPos
2793
2788
  * @return {number} */
2794
- getCollisionData(gridPos: Vector2): number;
2789
+ getCollisionData(layerPos: Vector2): number;
2795
2790
  /** Check if collision with another object should occur
2796
2791
  * @param {Vector2} pos
2797
2792
  * @param {Vector2} [size=vec2()]
@@ -3176,9 +3171,9 @@ declare module "littlejsengine" {
3176
3171
  /** Play the music that loops by default
3177
3172
  * @param {number} [volume] - Volume to play the music at
3178
3173
  * @param {boolean} [loop] - Should the music loop?
3179
- * @return {AudioBufferSourceNode} - The audio source node
3174
+ * @return {SoundInstance} - The sound instance
3180
3175
  */
3181
- playMusic(volume?: number, loop?: boolean): AudioBufferSourceNode;
3176
+ playMusic(volume?: number, loop?: boolean): SoundInstance;
3182
3177
  }
3183
3178
  /**
3184
3179
  * LittleJS User Interface Plugin
@@ -3205,9 +3200,9 @@ declare module "littlejsengine" {
3205
3200
  export let uiDebug: number;
3206
3201
  /** Enable UI system debug drawing
3207
3202
  * 0=off, 1=normal, 2=show invisible
3208
- * @param {number|boolean} enable
3203
+ * @param {number|boolean} debugMode
3209
3204
  * @memberof UISystem */
3210
- export function uiSetDebug(debugMode: any): void;
3205
+ export function uiSetDebug(debugMode: number | boolean): void;
3211
3206
  /**
3212
3207
  * UI System Global Object
3213
3208
  * @memberof UISystem
@@ -3609,14 +3604,14 @@ declare module "littlejsengine" {
3609
3604
  */
3610
3605
  export class UIVideo extends UIObject {
3611
3606
  /** Create a video player UI object
3612
- * @param {Vector2} [pos]
3613
- * @param {Vector2} [size]
3607
+ * @param {Vector2} pos
3608
+ * @param {Vector2} size
3614
3609
  * @param {string} src - Video file path or URL
3615
3610
  * @param {boolean} [autoplay=false] - Start playing immediately?
3616
3611
  * @param {boolean} [loop=false] - Loop the video?
3617
3612
  * @param {number} [volume=1] - Volume percent scaled by global volume (0-1)
3618
3613
  */
3619
- constructor(pos?: Vector2, size?: Vector2, src: string, autoplay?: boolean, loop?: boolean, volume?: number);
3614
+ constructor(pos: Vector2, size: Vector2, src: string, autoplay?: boolean, loop?: boolean, volume?: number);
3620
3615
  /** @property {number} - The video volume */
3621
3616
  volume: number;
3622
3617
  /** @property {HTMLVideoElement} - The video player */
@@ -3670,6 +3665,7 @@ declare module "littlejsengine" {
3670
3665
  * - Contact begin and end callbacks
3671
3666
  * - Wraps b2Vec2 type to/from Vector2
3672
3667
  * - Raycasting and querying
3668
+ * - Box2dTileLayer for grid based collision
3673
3669
  * - Every type of joint
3674
3670
  * - Debug physics drawing
3675
3671
  * @namespace Box2D
@@ -3702,8 +3698,11 @@ declare module "littlejsengine" {
3702
3698
  /** Create the global UI system object
3703
3699
  * @param {Object} instance */
3704
3700
  constructor(instance: any);
3701
+ /** @property {Object} - The Box2d instance */
3705
3702
  instance: any;
3703
+ /** @property {Object} - The Box2d world */
3706
3704
  world: any;
3705
+ /** @property {Array<Box2dObject>} - List of all Box2d objects */
3707
3706
  objects: any[];
3708
3707
  /** @property {number} - Velocity iterations per update*/
3709
3708
  velocityIterations: number;
@@ -3753,13 +3752,14 @@ declare module "littlejsengine" {
3753
3752
  * @param {Color} [color]
3754
3753
  * @param {Color} [lineColor]
3755
3754
  * @param {number} [lineWidth]
3755
+ * @param {boolean} [useWebGL=glEnable]
3756
3756
  * @param {CanvasRenderingContext2D} [context] */
3757
- drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3757
+ drawFixture(fixture: any, pos: Vector2, angle: number, color?: Color, lineColor?: Color, lineWidth?: number, useWebgl: any, context?: CanvasRenderingContext2D): void;
3758
3758
  /** converts a box2d vec2 to a Vector2
3759
3759
  * @param {Object} v */
3760
3760
  vec2From(v: any): Vector2;
3761
3761
  /** converts a box2d vec2 pointer to a Vector2
3762
- * @param {Object} v */
3762
+ * @param {Object} vp */
3763
3763
  vec2FromPointer(vp: any): Vector2;
3764
3764
  /** converts a Vector2 to a box2 vec2
3765
3765
  * @param {Vector2} v */
@@ -3789,16 +3789,21 @@ declare module "littlejsengine" {
3789
3789
  * @param {number} [bodyType]
3790
3790
  * @param {number} [renderOrder] */
3791
3791
  constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, bodyType?: number, renderOrder?: number);
3792
+ /** @property {Object} - The Box2d body */
3792
3793
  body: any;
3794
+ /** @property {Color} - Line color used for default box2d drawing */
3793
3795
  lineColor: Color;
3796
+ /** @property {Array<Object>} - List of all edges for default box2d drawing */
3794
3797
  edgeLists: any[];
3798
+ /** @property {Array<Object>} - List of all edge loops for default box2d drawing */
3795
3799
  edgeLoops: any[];
3796
3800
  /** Draws all this object's fixtures
3797
- * @param {Color} [color]
3798
- * @param {Color} [lineColor]
3799
- * @param {number} [lineWidth]
3801
+ * @param {Color} [color]
3802
+ * @param {Color} [lineColor]
3803
+ * @param {number} [lineWidth]
3804
+ * @param {boolean} [useWebGL=glEnable]
3800
3805
  * @param {CanvasRenderingContext2D} [context] */
3801
- drawFixtures(color?: Color, lineColor?: Color, lineWidth?: number, context?: CanvasRenderingContext2D): void;
3806
+ drawFixtures(color?: Color, lineColor?: Color, lineWidth?: number, useWebGL?: boolean, context?: CanvasRenderingContext2D): void;
3802
3807
  /** Called when a contact begins
3803
3808
  * @param {Box2dObject} otherObject */
3804
3809
  beginContact(otherObject: Box2dObject): void;
@@ -3873,6 +3878,11 @@ declare module "littlejsengine" {
3873
3878
  * @param {number} [restitution]
3874
3879
  * @param {boolean} [isSensor] */
3875
3880
  addEdgeLoop(points: Array<Vector2>, density?: number, friction?: number, restitution?: number, isSensor?: boolean): any[];
3881
+ /** Destroy a fixture from the body
3882
+ * @param {Object} [fixture] */
3883
+ destroyFixture(fixture?: any): void;
3884
+ /** Destroy all fixture from the body */
3885
+ destroyAllFixtures(): void;
3876
3886
  /** Gets the center of mass
3877
3887
  * @return {Vector2} */
3878
3888
  getCenterOfMass(): Vector2;
@@ -4045,6 +4055,7 @@ declare module "littlejsengine" {
4045
4055
  /** Create a box2d joint, the base class is not intended to be used directly
4046
4056
  * @param {Object} jointDef */
4047
4057
  constructor(jointDef: any);
4058
+ /** @property {Object} - The Box2d joint */
4048
4059
  box2dJoint: any;
4049
4060
  /** Destroy this joint */
4050
4061
  destroy(): void;
@@ -4275,8 +4286,8 @@ declare module "littlejsengine" {
4275
4286
  * @param {Box2dObject} objectB
4276
4287
  * @param {Box2dJoint} joint1
4277
4288
  * @param {Box2dJoint} joint2
4278
- * @param {ratio} [ratio] */
4279
- constructor(objectA: Box2dObject, objectB: Box2dObject, joint1: Box2dJoint, joint2: Box2dJoint, ratio?: ratio);
4289
+ * @param {number} [ratio] */
4290
+ constructor(objectA: Box2dObject, objectB: Box2dObject, joint1: Box2dJoint, joint2: Box2dJoint, ratio?: number);
4280
4291
  joint1: Box2dJoint;
4281
4292
  joint2: Box2dJoint;
4282
4293
  /** Get the first joint