littlejsengine 1.18.7 → 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
  /**
@@ -1473,13 +1487,15 @@ declare module "littlejsengine" {
1473
1487
  * @memberof Math */
1474
1488
  export function isNumber(n: any): boolean;
1475
1489
  /**
1476
- * Check if object can be converted to a string (has a toString method)
1490
+ * Check if a value is stringifiable i.e. it has a toString that returns
1491
+ * a string. Use this for ASSERTs and inputs that will be coerced to text;
1492
+ * use `typeof x === 'string'` inline if you need strict-string semantics.
1477
1493
  * - Returns true for strings, numbers, and most objects
1478
1494
  * - Returns false for null and undefined
1479
1495
  * @param {any} s
1480
1496
  * @return {boolean}
1481
1497
  * @memberof Math */
1482
- export function isString(s: any): boolean;
1498
+ export function isStringLike(s: any): boolean;
1483
1499
  /**
1484
1500
  * Check if object is an array
1485
1501
  * @param {any} a
@@ -1695,6 +1711,11 @@ declare module "littlejsengine" {
1695
1711
  * @type {number}
1696
1712
  * @memberof Draw */
1697
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;
1698
1719
  /** Convert from screen to world space coordinates
1699
1720
  * @param {Vector2} screenPos
1700
1721
  * @return {Vector2}
@@ -1749,7 +1770,7 @@ declare module "littlejsengine" {
1749
1770
  * @param {Vector2} pos
1750
1771
  * @param {Vector2} [size=vec2(1)]
1751
1772
  * @param {Color} [colorTop=WHITE]
1752
- * @param {Color} [colorBottom=BLACK]
1773
+ * @param {Color} [colorBottom=CLEAR_WHITE]
1753
1774
  * @param {number} [angle]
1754
1775
  * @param {boolean} [useWebGL=glEnable]
1755
1776
  * @param {boolean} [screenSpace]
@@ -1843,6 +1864,7 @@ declare module "littlejsengine" {
1843
1864
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
1844
1865
  * @memberof Draw */
1845
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;
1846
1868
  /**
1847
1869
  * @callback Canvas2DDrawFunction - A function that draws to a 2D canvas context
1848
1870
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
@@ -2064,6 +2086,18 @@ declare module "littlejsengine" {
2064
2086
  * @param {number} [rgbaAdditive=0] - black is 0
2065
2087
  * @memberof WebGL */
2066
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;
2067
2101
  /** Transform and add a polygon to the gl draw list
2068
2102
  * @param {Array<Vector2>} points - Array of Vector2 points
2069
2103
  * @param {number} rgba - Color of the polygon as a 32-bit integer
@@ -2301,9 +2335,7 @@ declare module "littlejsengine" {
2301
2335
  * - Web Audio API integration with master gain control
2302
2336
  * @namespace Audio
2303
2337
  */
2304
- /** Audio context used by the engine. Created lazily in audioInit() to avoid
2305
- * browser autoplay warnings about constructing an AudioContext before any
2306
- * user gesture.
2338
+ /** Audio context used by the engine
2307
2339
  * @type {AudioContext}
2308
2340
  * @memberof Audio */
2309
2341
  export let audioContext: AudioContext;
@@ -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 */
@@ -3738,6 +3778,10 @@ declare module "littlejsengine" {
3738
3778
  navigationIndex: any;
3739
3779
  /** @property {boolean} - Should this be auto selected by navigation? Must also have valid navigation index. */
3740
3780
  navigationAutoSelect: boolean;
3781
+ /** @property {Vector2} - Where on parent (or canvas if no parent) this object is anchored.
3782
+ * Components in [-1, 1]: (0,0)=center, (-1,-1)=top-left, (1,1)=bottom-right.
3783
+ * Also acts as self-pivot — e.g. (1,-1) puts your top-right corner at the anchor point. */
3784
+ anchor: Vector2;
3741
3785
  /** Add a child UIObject to this object, returns child for chaining
3742
3786
  * @param {UIObject} child
3743
3787
  * @return {UIObject} The child object added */
@@ -5070,13 +5114,21 @@ declare module "littlejsengine" {
5070
5114
  useRealTime?: boolean;
5071
5115
  paused?: boolean;
5072
5116
  });
5117
+ /** @property {function(number|Vector2|Color):void} - Called with the interpolated value each frame */
5073
5118
  callback: (arg0: number | Vector2 | Color) => void;
5119
+ /** @property {number|Vector2|Color} - Starting value */
5074
5120
  start: number | Vector2 | Color;
5121
+ /** @property {number|Vector2|Color} - Ending value */
5075
5122
  end: number | Vector2 | Color;
5123
+ /** @property {number} - Total duration in seconds */
5076
5124
  duration: number;
5125
+ /** @property {number} - Remaining time in seconds (counts down from duration to 0) */
5077
5126
  life: number;
5127
+ /** @property {function(number):number} - Easing curve mapping [0,1] -> [0,1] */
5078
5128
  ease: (arg0: number) => number;
5129
+ /** @property {boolean} - If true, advance even when the game is paused */
5079
5130
  useRealTime: boolean;
5131
+ /** @property {boolean} - If true, stop advancing until cleared */
5080
5132
  paused: boolean;
5081
5133
  /** @private completion callback set by then(), loop(), pingPong(). */
5082
5134
  private thenCallback;
@@ -5218,13 +5270,21 @@ declare module "littlejsengine" {
5218
5270
  * (size and walkability auto-derived) or a Vector2 grid size (user
5219
5271
  * overrides isWalkable). */
5220
5272
  constructor(source: TileCollisionLayer | Vector2);
5273
+ /** @property {Vector2} - Grid dimensions in tiles */
5221
5274
  size: any;
5275
+ /** @property {TileCollisionLayer|undefined} - Tile layer driving walkability, if any */
5222
5276
  tileLayer: Vector2 | TileCollisionLayer;
5277
+ /** @property {number} - A* heuristic multiplier (1 = admissible, higher = greedier) */
5223
5278
  heuristicWeight: number;
5279
+ /** @property {number} - Maximum A* expansions before giving up */
5224
5280
  maxLoop: number;
5281
+ /** @property {boolean} - If true, post-process paths with two-pass smoothing */
5225
5282
  smoothPath: boolean;
5283
+ /** @property {boolean} - If true, draw debug visualization during findPath */
5226
5284
  debug: boolean;
5285
+ /** @property {number} - Debug primitive lifetime in seconds (0 disables drawing) */
5227
5286
  debugTime: number;
5287
+ /** @property {Array<PathFinderNode>} - Flat row-major array of size.x*size.y nodes */
5228
5288
  nodes: any[];
5229
5289
  collisionScratch: Vector2;
5230
5290
  /** Default walkability: if a tile layer was provided, returns true when the
@@ -5304,6 +5364,14 @@ declare module "littlejsengine" {
5304
5364
  * @param {PathFinderNode[]} path
5305
5365
  * @private */
5306
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;
5307
5375
  /** Lookup helper: true when the node at tile coords (x, y) is in-bounds
5308
5376
  * and clear (walkable, zero-cost). Used by isLineClear's hot path.
5309
5377
  * @param {number} x