littlejsengine 1.18.23 → 1.18.24

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.
@@ -5841,15 +5841,15 @@ declare module "littlejsengine" {
5841
5841
  * @param {Vector2} imageSize - Size of the source image in pixels
5842
5842
  * @param {Vector2} [frameSize] - Size of each frame, or the whole image if not passed
5843
5843
  * @param {number} [padding] - How many pixels padding around each frame
5844
- * @param {number} [sourcePadding] - How many pixels padding around each frame in the source image
5844
+ * @param {number|Vector2} [sourcePadding] - How many pixels padding around each frame in the source image
5845
5845
  * @return {TileInfo} Tile for the packed image, or undefined if the sheet is full */
5846
- tryAdd(imageSize: Vector2, frameSize?: Vector2, padding?: number, sourcePadding?: number): TileInfo;
5846
+ tryAdd(imageSize: Vector2, frameSize?: Vector2, padding?: number, sourcePadding?: number | Vector2): TileInfo;
5847
5847
  /** Draw an image into this sheet at a tile returned by tryAdd
5848
5848
  * @param {HTMLImageElement} image - Source image to copy from
5849
5849
  * @param {TileInfo} tileInfo - Where to put it, from tryAdd
5850
5850
  * @param {boolean} [update] - Upload to webgl now, pass false when batching
5851
- * @param {number} [sourcePadding] - How many pixels padding around each frame in the source image */
5852
- drawImage(image: HTMLImageElement, tileInfo: TileInfo, update?: boolean, sourcePadding?: number): void;
5851
+ * @param {number|Vector2} [sourcePadding] - How many pixels padding around each frame in the source image */
5852
+ drawImage(image: HTMLImageElement, tileInfo: TileInfo, update?: boolean, sourcePadding?: number | Vector2): void;
5853
5853
  /** Upload the canvas to webgl if it has changed since the last upload
5854
5854
  * Only needed after batching, drawImage uploads automatically by default */
5855
5855
  updateTexture(): void;
@@ -5863,13 +5863,13 @@ declare module "littlejsengine" {
5863
5863
  * @param {string} src - Image source path
5864
5864
  * @param {Vector2|number} [frameSize] - Size of each animation frame in pixels
5865
5865
  * @param {number} [padding] - How many pixels padding around each frame
5866
- * @param {number} [sourcePadding] - How many pixels padding around each frame in the source image
5866
+ * @param {number|Vector2} [sourcePadding] - How many pixels padding around each frame in the source image
5867
5867
  * @return {TileInfo}
5868
5868
  * @example
5869
5869
  * const playerTile = loadSprite('player.png'); // a single sprite
5870
5870
  * const runTile = loadSprite('run.png', vec2(16)); // a 16x16 frame animation
5871
5871
  * @memberof TextureSheets */
5872
- export function loadSprite(src: string, frameSize?: Vector2 | number, padding?: number, sourcePadding?: number): TileInfo;
5872
+ export function loadSprite(src: string, frameSize?: Vector2 | number, padding?: number, sourcePadding?: number | Vector2): TileInfo;
5873
5873
  /** Load a pre-packed texture atlas and repack it onto texture sheets
5874
5874
  * - Supports TexturePacker json (hash and array) and Aseprite json
5875
5875
  * - Returns an empty object which is filled with TileInfos when loaded
@@ -35,7 +35,7 @@ const engineName = 'LittleJS';
35
35
  * @type {string}
36
36
  * @default
37
37
  * @memberof Engine */
38
- const engineVersion = '1.18.23';
38
+ const engineVersion = '1.18.24';
39
39
 
40
40
  /** Frames per second to update
41
41
  * @type {number}
@@ -14998,17 +14998,21 @@ class TextureSheet
14998
14998
  * @param {Vector2} imageSize - Size of the source image in pixels
14999
14999
  * @param {Vector2} [frameSize] - Size of each frame, or the whole image if not passed
15000
15000
  * @param {number} [padding] - How many pixels padding around each frame
15001
- * @param {number} [sourcePadding] - How many pixels padding around each frame in the source image
15001
+ * @param {number|Vector2} [sourcePadding] - How many pixels padding around each frame in the source image
15002
15002
  * @return {TileInfo} Tile for the packed image, or undefined if the sheet is full */
15003
15003
  tryAdd(imageSize, frameSize=imageSize, padding=textureSheetPadding, sourcePadding=0)
15004
15004
  {
15005
15005
  ASSERT(isVector2(imageSize) && isVector2(frameSize), 'sizes must be vec2');
15006
15006
  ASSERT(frameSize.x > 0 && frameSize.y > 0, 'frame size must be positive');
15007
- ASSERT(isNumber(sourcePadding) && sourcePadding >= 0, 'sourcePadding must be a number >= 0');
15007
+
15008
+ if (isNumber(sourcePadding))
15009
+ sourcePadding = vec2(sourcePadding);
15010
+ ASSERT(isVector2(sourcePadding) && sourcePadding.x >= 0 && sourcePadding.y >= 0,
15011
+ 'sourcePadding must be a number or vec2 >= 0');
15008
15012
 
15009
15013
  // the source may have its own padding baked in around each frame
15010
- const sourceCellWidth = frameSize.x + sourcePadding*2;
15011
- const sourceCellHeight = frameSize.y + sourcePadding*2;
15014
+ const sourceCellWidth = frameSize.x + sourcePadding.x*2;
15015
+ const sourceCellHeight = frameSize.y + sourcePadding.y*2;
15012
15016
  ASSERT(imageSize.x % sourceCellWidth === 0 && imageSize.y % sourceCellHeight === 0,
15013
15017
  'image size must be a multiple of the padded frame size');
15014
15018
 
@@ -15050,16 +15054,19 @@ class TextureSheet
15050
15054
  * @param {HTMLImageElement} image - Source image to copy from
15051
15055
  * @param {TileInfo} tileInfo - Where to put it, from tryAdd
15052
15056
  * @param {boolean} [update] - Upload to webgl now, pass false when batching
15053
- * @param {number} [sourcePadding] - How many pixels padding around each frame in the source image */
15057
+ * @param {number|Vector2} [sourcePadding] - How many pixels padding around each frame in the source image */
15054
15058
  drawImage(image, tileInfo, update=true, sourcePadding=0)
15055
15059
  {
15056
15060
  ASSERT(!!this.context, 'texture sheet has no canvas');
15057
15061
 
15062
+ if (isNumber(sourcePadding))
15063
+ sourcePadding = vec2(sourcePadding);
15064
+
15058
15065
  // copy frames in order, reading the source left to right, top to bottom
15059
15066
  // the destination wraps at tileInfo.columns which may be narrower than the source
15060
15067
  const frameSize = tileInfo.size;
15061
- const sourceCellWidth = frameSize.x + sourcePadding*2;
15062
- const sourceCellHeight = frameSize.y + sourcePadding*2;
15068
+ const sourceCellWidth = frameSize.x + sourcePadding.x*2;
15069
+ const sourceCellHeight = frameSize.y + sourcePadding.y*2;
15063
15070
  const sourceColumns = image.width / sourceCellWidth;
15064
15071
  const frameCount = sourceColumns * (image.height / sourceCellHeight);
15065
15072
  const columns = tileInfo.columns || frameCount;
@@ -15067,8 +15074,8 @@ class TextureSheet
15067
15074
  const cellHeight = frameSize.y + tileInfo.padding*2;
15068
15075
  for (let i = frameCount; i--;)
15069
15076
  {
15070
- const sourceX = (i % sourceColumns) * sourceCellWidth + sourcePadding;
15071
- const sourceY = (i / sourceColumns | 0) * sourceCellHeight + sourcePadding;
15077
+ const sourceX = (i % sourceColumns) * sourceCellWidth + sourcePadding.x;
15078
+ const sourceY = (i / sourceColumns | 0) * sourceCellHeight + sourcePadding.y;
15072
15079
  this.context.drawImage(image,
15073
15080
  sourceX, sourceY, frameSize.x, frameSize.y,
15074
15081
  tileInfo.pos.x + (i % columns) * cellWidth,
@@ -15102,7 +15109,7 @@ class TextureSheet
15102
15109
  * @param {string} src - Image source path
15103
15110
  * @param {Vector2|number} [frameSize] - Size of each animation frame in pixels
15104
15111
  * @param {number} [padding] - How many pixels padding around each frame
15105
- * @param {number} [sourcePadding] - How many pixels padding around each frame in the source image
15112
+ * @param {number|Vector2} [sourcePadding] - How many pixels padding around each frame in the source image
15106
15113
  * @return {TileInfo}
15107
15114
  * @example
15108
15115
  * const playerTile = loadSprite('player.png'); // a single sprite
@@ -15113,6 +15120,7 @@ function loadSprite(src, frameSize, padding=textureSheetPadding, sourcePadding=0
15113
15120
  ASSERT(isStringLike(src), 'image src must be a string');
15114
15121
  ASSERT(!frameSize || isVector2(frameSize) || isNumber(frameSize), 'frameSize must be a vec2 or number');
15115
15122
  ASSERT(isNumber(padding), 'padding must be a number');
15123
+ ASSERT(isNumber(sourcePadding) || isVector2(sourcePadding), 'sourcePadding must be a number or vec2');
15116
15124
 
15117
15125
  if (isNumber(frameSize))
15118
15126
  frameSize = vec2(frameSize);