littlejsengine 1.18.8 → 1.18.12

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.
package/README.md CHANGED
@@ -53,7 +53,7 @@ The code is very clean and well documented with many examples to get you started
53
53
 
54
54
  - Robust arcade physics system with collision handling
55
55
  - Fast tilemap collision and raycasting
56
- - Full Box2D integration for realistic physics
56
+ - Full Box2D integration for realistic physics using [Box2D v2.3.1 wasm](https://github.com/kripken/box2d.js)
57
57
  - Grid-based A* pathfinding plugin with optional path smoothing
58
58
 
59
59
  ### 🚀 Flexibility
@@ -74,7 +74,6 @@ The code is very clean and well documented with many examples to get you started
74
74
 
75
75
  ## How To Use LittleJS
76
76
 
77
-
78
77
  To get started download the latest LittleJS package from GitHub or install via npm:
79
78
 
80
79
  ```
@@ -98,8 +97,7 @@ npm run dev
98
97
  - [LittleJS Quick Reference Sheet](https://github.com/KilledByAPixel/LittleJS/blob/main/reference.md) - A reference sheet to help you get started.
99
98
  - [Little JS FAQ](https://github.com/KilledByAPixel/LittleJS/blob/main/FAQ.md) - Answers to common questions about LittleJS.
100
99
  - [JS13k Branch](https://github.com/KilledByAPixel/LittleJS/tree/js13k) - For size coding events like JS13k there is a special branch that builds to a 7KB zip.
101
- - [LittleJS GPT AI](https://chatgpt.com/g/g-67c7c080b5bc81919736bc8815836be6-make-games-with-littlejs) - Use AI to make games without writing any code!
102
- - [LittleJS AI Info](https://github.com/KilledByAPixel/LittleJS-AI) - Experiments, games, and templates to improve LittleJS + AI workflows.
100
+ - [LittleJS AI Tools](https://github.com/KilledByAPixel/LittleJS-AI) - Experiments, games, and templates to improve LittleJS + AI workflows.
103
101
 
104
102
  ## Examples
105
103
 
@@ -1018,6 +1018,19 @@ declare module "littlejsengine" {
1018
1018
  * @param {Object} saveData - object containing data to be saved
1019
1019
  * @memberof Utilities */
1020
1020
  export function writeSaveData(saveName: string, saveData: any): void;
1021
+ /** 1D gradient noise — returns a smooth value in [0, 1] for any real x.
1022
+ * Integer inputs land on deterministic lattice values; non-integer inputs
1023
+ * are interpolated with smoothStep for C1 continuity.
1024
+ * @param {number} x
1025
+ * @return {number}
1026
+ * @memberof Utilities */
1027
+ export function noise1D(x: number): number;
1028
+ /** 2D gradient noise — returns a smooth value in [0, 1] for any real (x, y).
1029
+ * @param {number} x
1030
+ * @param {number} y
1031
+ * @return {number}
1032
+ * @memberof Utilities */
1033
+ export function noise2D(x: number, y: number): number;
1021
1034
  /** Random global functions
1022
1035
  * @namespace Random */
1023
1036
  /** Returns a random value between the two values passed in
@@ -1368,6 +1381,7 @@ declare module "littlejsengine" {
1368
1381
  * - File saving (text, canvas, data URLs)
1369
1382
  * - Native share dialog support
1370
1383
  * - Local storage save data management
1384
+ * - Gradient noise (1D and 2D)
1371
1385
  * @namespace Utilities
1372
1386
  */
1373
1387
  /**
@@ -1697,6 +1711,11 @@ declare module "littlejsengine" {
1697
1711
  * @type {number}
1698
1712
  * @memberof Draw */
1699
1713
  export let drawCount: number;
1714
+ /** Keeps track of how many primitives were drawn each frame for debugging
1715
+ * A single draw call can render many primitives (e.g. a WebGL sprite batch).
1716
+ * @type {number}
1717
+ * @memberof Draw */
1718
+ export let primitiveCount: number;
1700
1719
  /** Convert from screen to world space coordinates
1701
1720
  * @param {Vector2} screenPos
1702
1721
  * @return {Vector2}
@@ -1751,7 +1770,7 @@ declare module "littlejsengine" {
1751
1770
  * @param {Vector2} pos
1752
1771
  * @param {Vector2} [size=vec2(1)]
1753
1772
  * @param {Color} [colorTop=WHITE]
1754
- * @param {Color} [colorBottom=BLACK]
1773
+ * @param {Color} [colorBottom=CLEAR_WHITE]
1755
1774
  * @param {number} [angle]
1756
1775
  * @param {boolean} [useWebGL=glEnable]
1757
1776
  * @param {boolean} [screenSpace]
@@ -1845,6 +1864,7 @@ declare module "littlejsengine" {
1845
1864
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1846
1865
  * @memberof Draw */
1847
1866
  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;
1848
1868
  /**
1849
1869
  * @callback Canvas2DDrawFunction - A function that draws to a 2D canvas context
1850
1870
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
@@ -2066,6 +2086,18 @@ declare module "littlejsengine" {
2066
2086
  * @param {number} [rgbaAdditive=0] - black is 0
2067
2087
  * @memberof WebGL */
2068
2088
  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
+ /** 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.
2093
+ * @param {number} x
2094
+ * @param {number} y
2095
+ * @param {number} sizeX
2096
+ * @param {number} sizeY
2097
+ * @param {number} angle
2098
+ * @param {number} rgba - color as 32-bit integer
2099
+ * @memberof WebGL */
2100
+ export function glDrawUntextured(x: number, y: number, sizeX: number, sizeY: number, angle: number, rgba: number): void;
2069
2101
  /** Transform and add a polygon to the gl draw list
2070
2102
  * @param {Array<Vector2>} points - Array of Vector2 points
2071
2103
  * @param {number} rgba - Color of the polygon as a 32-bit integer
@@ -2483,13 +2515,13 @@ declare module "littlejsengine" {
2483
2515
  }
2484
2516
  /** Speak text with passed in settings
2485
2517
  * @param {string} text - The text to speak
2486
- * @param {string} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
2487
2518
  * @param {number} [volume] - How much to scale volume by
2488
2519
  * @param {number} [rate] - How quickly to speak
2489
2520
  * @param {number} [pitch] - How much to change the pitch by
2521
+ * @param {string} [language] - The language/accent to use (examples: en, it, ru, ja, zh)
2490
2522
  * @return {SpeechSynthesisUtterance} - The utterance that was spoken
2491
2523
  * @memberof Audio */
2492
- export function speak(text: string, language?: string, volume?: number, rate?: number, pitch?: number): SpeechSynthesisUtterance;
2524
+ export function speak(text: string, volume?: number, rate?: number, pitch?: number, language?: string): SpeechSynthesisUtterance;
2493
2525
  /** Stop all queued speech
2494
2526
  * @memberof Audio */
2495
2527
  export function speakStop(): void;
@@ -3264,6 +3296,7 @@ declare module "littlejsengine" {
3264
3296
  icon: string;
3265
3297
  /** @property {boolean} - Is the medal unlocked? */
3266
3298
  unlocked: boolean;
3299
+ /** @property {HTMLImageElement|undefined} - Source image for the medal icon, if any */
3267
3300
  image: HTMLImageElement;
3268
3301
  /** Unlocks a medal if not already unlocked */
3269
3302
  unlock(): void;
@@ -3337,12 +3370,19 @@ declare module "littlejsengine" {
3337
3370
  * new NewgroundsPlugin(app_id);
3338
3371
  */
3339
3372
  constructor(app_id: string, cipher?: string, cryptoJS?: any);
3373
+ /** @property {string} - The newgrounds App ID */
3340
3374
  app_id: string;
3375
+ /** @property {string|undefined} - AES-128/Base64 encryption key, if any */
3341
3376
  cipher: string;
3377
+ /** @property {Object|undefined} - CryptoJS instance used when cipher is set */
3342
3378
  cryptoJS: any;
3379
+ /** @property {string} - Hostname used when logging views */
3343
3380
  host: string;
3381
+ /** @property {string|null} - Newgrounds session id from the URL (null when not logged in) */
3344
3382
  session_id: string;
3383
+ /** @property {Array} - Medals fetched from Newgrounds (empty until session is active) */
3345
3384
  medals: any;
3385
+ /** @property {Array} - Scoreboards fetched from Newgrounds */
3346
3386
  scoreboards: any;
3347
3387
  /** Send message to unlock a medal by id
3348
3388
  * @param {number} id - The medal id */
@@ -5074,13 +5114,21 @@ declare module "littlejsengine" {
5074
5114
  useRealTime?: boolean;
5075
5115
  paused?: boolean;
5076
5116
  });
5117
+ /** @property {function(number|Vector2|Color):void} - Called with the interpolated value each frame */
5077
5118
  callback: (arg0: number | Vector2 | Color) => void;
5119
+ /** @property {number|Vector2|Color} - Starting value */
5078
5120
  start: number | Vector2 | Color;
5121
+ /** @property {number|Vector2|Color} - Ending value */
5079
5122
  end: number | Vector2 | Color;
5123
+ /** @property {number} - Total duration in seconds */
5080
5124
  duration: number;
5125
+ /** @property {number} - Remaining time in seconds (counts down from duration to 0) */
5081
5126
  life: number;
5127
+ /** @property {function(number):number} - Easing curve mapping [0,1] -> [0,1] */
5082
5128
  ease: (arg0: number) => number;
5129
+ /** @property {boolean} - If true, advance even when the game is paused */
5083
5130
  useRealTime: boolean;
5131
+ /** @property {boolean} - If true, stop advancing until cleared */
5084
5132
  paused: boolean;
5085
5133
  /** @private completion callback set by then(), loop(), pingPong(). */
5086
5134
  private thenCallback;
@@ -5222,13 +5270,21 @@ declare module "littlejsengine" {
5222
5270
  * (size and walkability auto-derived) or a Vector2 grid size (user
5223
5271
  * overrides isWalkable). */
5224
5272
  constructor(source: TileCollisionLayer | Vector2);
5273
+ /** @property {Vector2} - Grid dimensions in tiles */
5225
5274
  size: any;
5275
+ /** @property {TileCollisionLayer|undefined} - Tile layer driving walkability, if any */
5226
5276
  tileLayer: Vector2 | TileCollisionLayer;
5277
+ /** @property {number} - A* heuristic multiplier (1 = admissible, higher = greedier) */
5227
5278
  heuristicWeight: number;
5279
+ /** @property {number} - Maximum A* expansions before giving up */
5228
5280
  maxLoop: number;
5281
+ /** @property {boolean} - If true, post-process paths with two-pass smoothing */
5229
5282
  smoothPath: boolean;
5283
+ /** @property {boolean} - If true, draw debug visualization during findPath */
5230
5284
  debug: boolean;
5285
+ /** @property {number} - Debug primitive lifetime in seconds (0 disables drawing) */
5231
5286
  debugTime: number;
5287
+ /** @property {Array<PathFinderNode>} - Flat row-major array of size.x*size.y nodes */
5232
5288
  nodes: any[];
5233
5289
  collisionScratch: Vector2;
5234
5290
  /** Default walkability: if a tile layer was provided, returns true when the
@@ -5308,6 +5364,14 @@ declare module "littlejsengine" {
5308
5364
  * @param {PathFinderNode[]} path
5309
5365
  * @private */
5310
5366
  private smoothPathStringPull;
5367
+ /** Drop any middle node that lies exactly on the line through its two
5368
+ * neighbors. Backstop for the smoothing passes — the corners pass
5369
+ * intentionally keeps truly-straight runs, and the string-pulling pass
5370
+ * checks collinearity against the original path, not the in-progress
5371
+ * result, so it can leave 3+ collinear nodes in some edge cases.
5372
+ * @param {PathFinderNode[]} path
5373
+ * @private */
5374
+ private dropCollinearNodes;
5311
5375
  /** Lookup helper: true when the node at tile coords (x, y) is in-bounds
5312
5376
  * and clear (walkable, zero-cost). Used by isLineClear's hot path.
5313
5377
  * @param {number} x