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.
- package/dist/littlejs.d.ts +6 -6
- package/dist/littlejs.esm.js +19 -11
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +19 -11
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +19 -11
- package/package.json +1 -1
- package/plugins/textureSheet.js +18 -10
- package/src/engine.js +1 -1
package/dist/littlejs.js
CHANGED
|
@@ -35,7 +35,7 @@ const engineName = 'LittleJS';
|
|
|
35
35
|
* @type {string}
|
|
36
36
|
* @default
|
|
37
37
|
* @memberof Engine */
|
|
38
|
-
const engineVersion = '1.18.
|
|
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
|
-
|
|
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);
|