littlejsengine 1.18.17 → 1.18.19

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.
@@ -390,6 +390,8 @@ declare module "littlejsengine" {
390
390
  * @memberof Settings */
391
391
  export let canvasPixelated: boolean;
392
392
  /** Disables texture filtering for crisper pixel art
393
+ * - Leave true for pixel art so sprites stay sharp when scaled (uses NEAREST filtering)
394
+ * - Set false for smooth/high-resolution art to enable bilinear filtering and mipmaps
393
395
  * @type {boolean}
394
396
  * @default
395
397
  * @memberof Settings */
@@ -666,6 +668,7 @@ declare module "littlejsengine" {
666
668
  * @memberof Settings */
667
669
  export function setCanvasPixelated(pixelated: boolean): void;
668
670
  /** Disables texture filtering for crisper pixel art
671
+ * - Leave true for pixel art; set false for smooth/high-resolution art
669
672
  * @param {boolean} pixelated
670
673
  * @memberof Settings */
671
674
  export function setTilesPixelated(pixelated: boolean): void;
@@ -1385,9 +1388,17 @@ declare module "littlejsengine" {
1385
1388
  * @param {Color} c - other color
1386
1389
  * @return {Color} */
1387
1390
  setFrom(c: Color): Color;
1391
+ /** Sets the alpha of this color and returns self
1392
+ * @param {number} [a] - alpha
1393
+ * @return {Color} */
1394
+ setAlpha(a?: number): Color;
1388
1395
  /** Returns a new color that is a copy of this
1389
1396
  * @return {Color} */
1390
1397
  copy(): Color;
1398
+ /** Returns a copy of this color with the alpha set
1399
+ * @param {number} [a] - alpha
1400
+ * @return {Color} */
1401
+ withAlpha(a?: number): Color;
1391
1402
  /** Returns a copy of this color plus the color passed in
1392
1403
  * @param {Color} c - other color
1393
1404
  * @return {Color} */
@@ -2003,11 +2014,10 @@ declare module "littlejsengine" {
2003
2014
  * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=drawContext]
2004
2015
  * @memberof Draw */
2005
2016
  export function drawTextScreen(text: string | number, pos: Vector2, size: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, fontStyle?: string, maxWidth?: number, angle?: number, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2006
- /** Enable normal or additive blend mode
2017
+ /** Enable additive blending
2007
2018
  * @param {boolean} [additive]
2008
- * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
2009
2019
  * @memberof Draw */
2010
- export function setBlendMode(additive?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
2020
+ export function setAdditiveBlendMode(additive?: boolean): void;
2011
2021
  /** Combines LittleJS canvases onto the main canvas
2012
2022
  * This is necessary for things like screenshots and video
2013
2023
  * @memberof Draw */
@@ -2074,6 +2084,19 @@ declare module "littlejsengine" {
2074
2084
  * @return {Vector2}
2075
2085
  * @memberof Draw */
2076
2086
  export function getCameraSize(): Vector2;
2087
+ /** Fit the camera to a rectangle in world space by setting cameraPos and cameraScale
2088
+ * - worldMargin pads the content rectangle in world units, so the gap scales with the content on resize
2089
+ * - screenInset reserves space in screen pixels on each viewport edge (for example a HUD band) and
2090
+ * re-centers the content away from that edge, so the reserved band stays a fixed pixel size on resize
2091
+ * - worldMargin and screenInset may each be a number for all sides, a Vector2 (x=left/right, y=top/bottom),
2092
+ * or an object with any of {top, right, bottom, left}
2093
+ * @param {Vector2} center - Center of the rectangle in world space
2094
+ * @param {Vector2} size - Size of the rectangle in world space
2095
+ * @param {number|Vector2|Object} [worldMargin] - World space padding added around the content rectangle
2096
+ * @param {number|Vector2|Object} [screenInset] - Screen space padding in pixels reserved on each viewport edge
2097
+ * @return {number} - The new camera scale
2098
+ * @memberof Draw */
2099
+ export function cameraFit(center: Vector2, size: Vector2, worldMargin?: number | Vector2 | any, screenInset?: number | Vector2 | any): number;
2077
2100
  /** Check if a box, point, or circle is on screen with a circle test
2078
2101
  * If size is a Vector2, uses the length as diameter
2079
2102
  * This can be used to cull offscreen objects from render or update
@@ -2325,10 +2348,27 @@ declare module "littlejsengine" {
2325
2348
  * @type {boolean}
2326
2349
  * @memberof Input */
2327
2350
  export let mouseInWindow: boolean;
2328
- /** Returns true if user is using gamepad (has more recently pressed a gamepad button)
2351
+ /** True if a gamepad is the most recently used input device.
2352
+ * Equivalent to usingGamepadInput(); derived from lastInputDevice each frame.
2329
2353
  * @type {boolean}
2330
2354
  * @memberof Input */
2331
2355
  export let isUsingGamepad: boolean;
2356
+ /** The most recently used input device: 'mouse' | 'keyboard' | 'gamepad'.
2357
+ * Sticky: it holds its value while every device is idle, so a mouse-follow
2358
+ * control (e.g. paddle = mousePos) won't snap back the instant the stick/keys
2359
+ * are released. With several devices in play at once (e.g. keyboard to move +
2360
+ * mouse to aim) it tracks whichever was touched last each frame, so it may
2361
+ * alternate — that's intended; use it to pick which control drives a shared
2362
+ * action. Updated every frame by inputUpdate().
2363
+ * @type {string}
2364
+ * @memberof Input */
2365
+ export let lastInputDevice: string;
2366
+ /** Screen-pixel mouse movement per frame that counts as "using the mouse"
2367
+ * (so sub-pixel hand jitter doesn't steal focus from the keyboard/gamepad).
2368
+ * @type {number}
2369
+ * @default
2370
+ * @memberof Input */
2371
+ export let inputMouseMoveThreshold: number;
2332
2372
  /** Prevents input continuing to the default browser handling (true by default)
2333
2373
  * @type {boolean}
2334
2374
  * @memberof Input */
@@ -2345,6 +2385,16 @@ declare module "littlejsengine" {
2345
2385
  * @param {boolean} preventDefault
2346
2386
  * @memberof Input */
2347
2387
  export function setInputPreventDefault(preventDefault?: boolean): void;
2388
+ /** Set the screen-pixel mouse movement per frame that counts as using the mouse
2389
+ * @param {number} threshold
2390
+ * @memberof Input */
2391
+ export function setInputMouseMoveThreshold(threshold: number): void;
2392
+ /** @return {boolean} - Is the mouse the most recently used input device? @memberof Input */
2393
+ export function usingMouseInput(): boolean;
2394
+ /** @return {boolean} - Is the keyboard the most recently used input device? @memberof Input */
2395
+ export function usingKeyboardInput(): boolean;
2396
+ /** @return {boolean} - Is a gamepad the most recently used input device? @memberof Input */
2397
+ export function usingGamepadInput(): boolean;
2348
2398
  /** Returns true if gamepad button is down
2349
2399
  * @param {number} button
2350
2400
  * @param {number} [gamepad]
@@ -3885,10 +3935,15 @@ declare module "littlejsengine" {
3885
3935
  * @param {Vector2} [size=vec2(1)]
3886
3936
  */
3887
3937
  constructor(pos?: Vector2, size?: Vector2);
3888
- /** @property {Vector2} - Local position of the object */
3938
+ /** @property {Vector2} - Position you set: an offset from this object's
3939
+ * anchor point (the parent box, or the canvas for roots). This is the
3940
+ * input that controls placement — set this, not nativePos. */
3889
3941
  localPos: Vector2;
3890
- /** @property {Vector2} - Screen space position of the object */
3891
- pos: Vector2;
3942
+ /** @property {Vector2} - Resolved position in native UI space, recomputed
3943
+ * every frame from localPos + anchor (and nativeHeight, if set). This is a
3944
+ * derived output used for drawing and hit-testing; assigning to it has no
3945
+ * effect since it is overwritten each frame. Set localPos instead. */
3946
+ nativePos: Vector2;
3892
3947
  /** @property {Vector2} - Screen space size of the object */
3893
3948
  size: Vector2;
3894
3949
  /** @property {Color} - Color of the object */
@@ -5215,11 +5270,16 @@ declare module "littlejsengine" {
5215
5270
  }
5216
5271
  /** Draw a scalable nine-slice UI element in world space
5217
5272
  * This function can apply color and additive color if WebGL is enabled
5273
+ * The nine-slice samples a 3x3 block of tiles from the tilesheet, it does not
5274
+ * subdivide a single tile. Pass the top-left tile of that block as startTile;
5275
+ * the other 8 tiles (edges, corners, and center) are taken automatically from
5276
+ * the 3x3 grid of tiles extending right and down from it. borderSize only sets
5277
+ * the rendered thickness of the edges and corners, not how the texture is cut.
5218
5278
  * @param {Vector2} pos - World space position
5219
5279
  * @param {Vector2} size - World space size
5220
- * @param {TileInfo} startTile - Starting tile for the nine-slice pattern
5280
+ * @param {TileInfo} startTile - Top-left tile of the 3x3 block to sample the nine-slice from
5221
5281
  * @param {Color} [color] - Color to modulate with
5222
- * @param {number} [borderSize] - Width of the border sections
5282
+ * @param {number} [borderSize] - Rendered thickness of the border sections
5223
5283
  * @param {Color} [additiveColor] - Additive color
5224
5284
  * @param {number} [extraSpace] - Extra spacing adjustment
5225
5285
  * @param {number} [angle] - Angle to rotate by
@@ -5238,19 +5298,23 @@ declare module "littlejsengine" {
5238
5298
  * This function can not apply color because it draws using the 2d context
5239
5299
  * @param {Vector2} pos - Screen space position
5240
5300
  * @param {Vector2} size - Screen space size
5241
- * @param {TileInfo} startTile - Starting tile for the nine-slice pattern
5242
- * @param {number} [borderSize] - Width of the border sections
5301
+ * @param {TileInfo} startTile - Top-left tile of the 3x3 block to sample (see drawNineSlice)
5302
+ * @param {number} [borderSize] - Rendered thickness of the border sections
5243
5303
  * @param {number} [extraSpace] - Extra spacing adjustment
5244
5304
  * @param {number} [angle] - Angle to rotate by
5245
5305
  * @memberof DrawUtilities */
5246
5306
  export function drawNineSliceScreen(pos: Vector2, size: Vector2, startTile: TileInfo, borderSize?: number, extraSpace?: number, angle?: number): void;
5247
5307
  /** Draw a scalable three-slice UI element in world space
5248
5308
  * This function can apply color and additive color if WebGL is enabled
5309
+ * The three-slice samples 3 consecutive tiles from the tilesheet, it does not
5310
+ * subdivide a single tile. Pass the first tile as startTile; the three tiles
5311
+ * are used in order as corner, side, and center, then rotated and mirrored to
5312
+ * build all four edges and corners. borderSize only sets the rendered thickness.
5249
5313
  * @param {Vector2} pos - World space position
5250
5314
  * @param {Vector2} size - World space size
5251
- * @param {TileInfo} startTile - Starting tile for the three-slice pattern
5315
+ * @param {TileInfo} startTile - First of 3 consecutive tiles (corner, side, center) for the three-slice
5252
5316
  * @param {Color} [color] - Color to modulate with
5253
- * @param {number} [borderSize] - Width of the border sections
5317
+ * @param {number} [borderSize] - Rendered thickness of the border sections
5254
5318
  * @param {Color} [additiveColor] - Additive color
5255
5319
  * @param {number} [extraSpace] - Extra spacing adjustment
5256
5320
  * @param {number} [angle] - Angle to rotate by
@@ -5263,8 +5327,8 @@ declare module "littlejsengine" {
5263
5327
  * This function can not apply color because it draws using the 2d context
5264
5328
  * @param {Vector2} pos - Screen space position
5265
5329
  * @param {Vector2} size - Screen space size
5266
- * @param {TileInfo} startTile - Starting tile for the three-slice pattern
5267
- * @param {number} [borderSize] - Width of the border sections
5330
+ * @param {TileInfo} startTile - First of 3 consecutive tiles: corner, side, center (see drawThreeSlice)
5331
+ * @param {number} [borderSize] - Rendered thickness of the border sections
5268
5332
  * @param {number} [extraSpace] - Extra spacing adjustment
5269
5333
  * @param {number} [angle] - Angle to rotate by
5270
5334
  * @memberof DrawUtilities */