littlejsengine 1.18.21 → 1.18.23
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 +6 -0
- package/dist/littlejs.d.ts +135 -1
- package/dist/littlejs.esm.js +489 -9
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +475 -8
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +475 -8
- package/package.json +1 -1
- package/plugins/pluginExport.js +13 -1
- package/plugins/textureSheet.js +450 -0
- package/src/engine.js +1 -1
- package/src/engineBuild.mjs +1 -0
- package/src/engineDraw.js +25 -7
package/README.md
CHANGED
|
@@ -80,6 +80,12 @@ The code is very clean and well documented with many examples to get you started
|
|
|
80
80
|
- [LittleJS AI Tools](https://github.com/KilledByAPixel/LittleJS-AI) - Templates, examples, and prompts tuned for AI + LittleJS workflows
|
|
81
81
|
- [LittleJS GPT](https://chatgpt.com/g/g-67c7c080b5bc81919736bc8815836be6-littlejs-game-maker) - Build LittleJS games right inside ChatGPT
|
|
82
82
|
|
|
83
|
+
### 🧊 3D with Three.js
|
|
84
|
+
|
|
85
|
+
- Optional [Three.js](https://threejs.org) plugin renders a 3D scene behind the LittleJS canvas
|
|
86
|
+
- 2D camera and 3D camera stay aligned so sprites and meshes share the same world space
|
|
87
|
+
- LittleJS physics drive Three.js meshes with `ThreeJSObject`
|
|
88
|
+
|
|
83
89
|
## How To Use LittleJS
|
|
84
90
|
|
|
85
91
|
To get started download the latest LittleJS package from GitHub or install via npm:
|
package/dist/littlejs.d.ts
CHANGED
|
@@ -1669,8 +1669,9 @@ declare module "littlejsengine" {
|
|
|
1669
1669
|
* @param {TextureInfo} [textureInfo] - Texture info to use
|
|
1670
1670
|
* @param {number} [padding] - How many pixels padding around all sides of each tile (increases grid size, does not affect tile size)
|
|
1671
1671
|
* @param {number} [bleed] - How many pixels smaller to shrink UVS of tiles (does not affect grid size, only UVs)
|
|
1672
|
+
* @param {number} [columns] - How many frames per row for frame(), 0 to keep frames on a single row
|
|
1672
1673
|
*/
|
|
1673
|
-
constructor(pos?: Vector2, size?: Vector2, textureInfo?: TextureInfo, padding?: number, bleed?: number);
|
|
1674
|
+
constructor(pos?: Vector2, size?: Vector2, textureInfo?: TextureInfo, padding?: number, bleed?: number, columns?: number);
|
|
1674
1675
|
/** @property {Vector2} - Top left corner of tile in pixels */
|
|
1675
1676
|
pos: Vector2;
|
|
1676
1677
|
/** @property {Vector2} - Size of tile in pixels */
|
|
@@ -1681,16 +1682,24 @@ declare module "littlejsengine" {
|
|
|
1681
1682
|
textureInfo: TextureInfo;
|
|
1682
1683
|
/** @property {number} - Shrinks tile by this many pixels to prevent neighbors bleeding */
|
|
1683
1684
|
bleed: number;
|
|
1685
|
+
/** @property {number} - How many frames per row for frame(), 0 to keep frames on a single row */
|
|
1686
|
+
columns: number;
|
|
1684
1687
|
/** Returns a copy of this tile offset by a vector
|
|
1685
1688
|
* @param {Vector2} offset - Offset to apply in pixels
|
|
1686
1689
|
* @return {TileInfo}
|
|
1687
1690
|
*/
|
|
1688
1691
|
offset(offset: Vector2): TileInfo;
|
|
1689
1692
|
/** Returns a copy of this tile offset by a number of animation frames
|
|
1693
|
+
* Frames wrap down to the next row if columns is set
|
|
1690
1694
|
* @param {number} frame - Offset to apply in animation frames
|
|
1691
1695
|
* @return {TileInfo}
|
|
1692
1696
|
*/
|
|
1693
1697
|
frame(frame: number): TileInfo;
|
|
1698
|
+
/** Set how many frames per row this tile uses, so frame() can wrap
|
|
1699
|
+
* @param {number} [columns] - Frames per row, 0 to keep frames on a single row
|
|
1700
|
+
* @return {TileInfo}
|
|
1701
|
+
*/
|
|
1702
|
+
setColumns(columns?: number): TileInfo;
|
|
1694
1703
|
/**
|
|
1695
1704
|
* Returns a tile info for an index using this tile as reference
|
|
1696
1705
|
* @param {Vector2|number} [index=0]
|
|
@@ -5772,4 +5781,129 @@ declare module "littlejsengine" {
|
|
|
5772
5781
|
/** Copy this object's transform to the mesh */
|
|
5773
5782
|
syncMesh(): void;
|
|
5774
5783
|
}
|
|
5784
|
+
/**
|
|
5785
|
+
* LittleJS Texture Sheet Plugin
|
|
5786
|
+
* - Packs images into texture sheets as they are loaded
|
|
5787
|
+
* - Sprites are placed automatically, callers get a TileInfo
|
|
5788
|
+
* - Sheets are created and filled as needed
|
|
5789
|
+
* - Sheets fill in call order, images decode in parallel
|
|
5790
|
+
* - Animation frames keep layout and wrap across rows as needed
|
|
5791
|
+
* - WebGL textures upload once per batch of loads
|
|
5792
|
+
* - loadAtlas imports pre-packed atlases (TexturePacker and Aseprite json)
|
|
5793
|
+
* @namespace TextureSheets
|
|
5794
|
+
*/
|
|
5795
|
+
/** Width and height in pixels of texture sheets created by loadSprite
|
|
5796
|
+
* @type {number}
|
|
5797
|
+
* @default
|
|
5798
|
+
* @memberof Settings */
|
|
5799
|
+
export let textureSheetSize: number;
|
|
5800
|
+
/** Default padding pixels around each frame packed by loadSprite
|
|
5801
|
+
* @type {number}
|
|
5802
|
+
* @default
|
|
5803
|
+
* @memberof Settings */
|
|
5804
|
+
export let textureSheetPadding: number;
|
|
5805
|
+
/** Set width and height in pixels of texture sheets created by loadSprite
|
|
5806
|
+
* @param {number} size
|
|
5807
|
+
* @memberof Settings */
|
|
5808
|
+
export function setTextureSheetSize(size: number): void;
|
|
5809
|
+
/** Set default padding pixels around each frame packed by loadSprite
|
|
5810
|
+
* @param {number} padding
|
|
5811
|
+
* @memberof Settings */
|
|
5812
|
+
export function setTextureSheetPadding(padding: number): void;
|
|
5813
|
+
/** Array of texture sheets created by loadSprite
|
|
5814
|
+
* @type {Array<TextureSheet>}
|
|
5815
|
+
* @memberof TextureSheets */
|
|
5816
|
+
export let textureSheets: Array<TextureSheet>;
|
|
5817
|
+
/**
|
|
5818
|
+
* Texture Sheet - A texture that images are packed into as they load
|
|
5819
|
+
* Uses shelf packing, images are placed left to right then wrap to a new row
|
|
5820
|
+
* @memberof TextureSheets
|
|
5821
|
+
*/
|
|
5822
|
+
export class TextureSheet {
|
|
5823
|
+
/** Create a texture sheet, called automatically by loadSprite
|
|
5824
|
+
* @param {number} [size] - Width and height of the sheet in pixels */
|
|
5825
|
+
constructor(size?: number);
|
|
5826
|
+
/** @property {number} - Width and height of the sheet in pixels */
|
|
5827
|
+
size: number;
|
|
5828
|
+
/** @property {OffscreenCanvas} - Canvas holding the packed images */
|
|
5829
|
+
canvas: OffscreenCanvas;
|
|
5830
|
+
/** @property {OffscreenCanvasRenderingContext2D} - 2d context for the canvas */
|
|
5831
|
+
context: OffscreenCanvasRenderingContext2D;
|
|
5832
|
+
/** @property {TextureInfo} - The texture info for this sheet */
|
|
5833
|
+
textureInfo: TextureInfo;
|
|
5834
|
+
/** @property {Vector2} - Where the next image will be packed */
|
|
5835
|
+
cursor: Vector2;
|
|
5836
|
+
/** @property {number} - Height of the row being packed */
|
|
5837
|
+
rowHeight: number;
|
|
5838
|
+
/** @property {boolean} - Has the canvas changed since the last webgl upload? */
|
|
5839
|
+
glDirty: boolean;
|
|
5840
|
+
/** Find a spot for an image on this sheet without drawing it
|
|
5841
|
+
* @param {Vector2} imageSize - Size of the source image in pixels
|
|
5842
|
+
* @param {Vector2} [frameSize] - Size of each frame, or the whole image if not passed
|
|
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
|
|
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;
|
|
5847
|
+
/** Draw an image into this sheet at a tile returned by tryAdd
|
|
5848
|
+
* @param {HTMLImageElement} image - Source image to copy from
|
|
5849
|
+
* @param {TileInfo} tileInfo - Where to put it, from tryAdd
|
|
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;
|
|
5853
|
+
/** Upload the canvas to webgl if it has changed since the last upload
|
|
5854
|
+
* Only needed after batching, drawImage uploads automatically by default */
|
|
5855
|
+
updateTexture(): void;
|
|
5856
|
+
}
|
|
5857
|
+
/** Load an image and pack it into a texture sheet
|
|
5858
|
+
* - Returns a TileInfo immediately which is filled in when the image loads
|
|
5859
|
+
* - Nothing is visible until it loads, use spritesReady to wait for it
|
|
5860
|
+
* - Pass frameSize for animations, then step through them with TileInfo.frame
|
|
5861
|
+
* - Grid images keep their layout and frames wrap down to the next row
|
|
5862
|
+
* - Pass sourcePadding if the source image has padding baked in around frames
|
|
5863
|
+
* @param {string} src - Image source path
|
|
5864
|
+
* @param {Vector2|number} [frameSize] - Size of each animation frame in pixels
|
|
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
|
|
5867
|
+
* @return {TileInfo}
|
|
5868
|
+
* @example
|
|
5869
|
+
* const playerTile = loadSprite('player.png'); // a single sprite
|
|
5870
|
+
* const runTile = loadSprite('run.png', vec2(16)); // a 16x16 frame animation
|
|
5871
|
+
* @memberof TextureSheets */
|
|
5872
|
+
export function loadSprite(src: string, frameSize?: Vector2 | number, padding?: number, sourcePadding?: number): TileInfo;
|
|
5873
|
+
/** Load a pre-packed texture atlas and repack it onto texture sheets
|
|
5874
|
+
* - Supports TexturePacker json (hash and array) and Aseprite json
|
|
5875
|
+
* - Returns an empty object which is filled with TileInfos when loaded
|
|
5876
|
+
* - Frames are named by the json, animations are grouped automatically
|
|
5877
|
+
* - Aseprite frame tags become animations, so do names like run_0, run_1
|
|
5878
|
+
* - Trimmed frames are restored to their full source size when packed
|
|
5879
|
+
* - Rotated frames are rotated back upright when packed
|
|
5880
|
+
* @param {string} imageSrc - Atlas image path
|
|
5881
|
+
* @param {string|Object} jsonSrc - Atlas json path, or already parsed json data
|
|
5882
|
+
* @param {number} [padding] - How many pixels padding around each frame
|
|
5883
|
+
* @return {Object} Object mapping frame and animation names to TileInfos
|
|
5884
|
+
* @example
|
|
5885
|
+
* const atlas = loadAtlas('sprites.png', 'sprites.json');
|
|
5886
|
+
* await spritesReady();
|
|
5887
|
+
* drawTile(pos, size, atlas.player); // a single frame
|
|
5888
|
+
* drawTile(pos, size, atlas.run.frame(2)); // frame 2 of the run animation
|
|
5889
|
+
* @memberof TextureSheets */
|
|
5890
|
+
export function loadAtlas(imageSrc: string, jsonSrc: string | any, padding?: number): any;
|
|
5891
|
+
/** Parse atlas json into a list of named frame groups, used by loadAtlas
|
|
5892
|
+
* - Accepts TexturePacker json (hash and array) and Aseprite json
|
|
5893
|
+
* - Frames tagged in Aseprite or named like run_0, run_1 group into animations
|
|
5894
|
+
* @param {Object} data - Parsed atlas json data
|
|
5895
|
+
* @return {Array<Object>} List of {name, frames} groups in atlas order
|
|
5896
|
+
* @memberof TextureSheets */
|
|
5897
|
+
export function parseAtlas(data: any): Array<any>;
|
|
5898
|
+
/** Wait for everything started by loadSprite and loadAtlas to finish packing
|
|
5899
|
+
* @return {Promise}
|
|
5900
|
+
* @example
|
|
5901
|
+
* async function gameInit()
|
|
5902
|
+
* {
|
|
5903
|
+
* playerTile = loadSprite('player.png');
|
|
5904
|
+
* runTile = loadSprite('run.png', vec2(16));
|
|
5905
|
+
* await spritesReady();
|
|
5906
|
+
* }
|
|
5907
|
+
* @memberof TextureSheets */
|
|
5908
|
+
export function spritesReady(): Promise<any>;
|
|
5775
5909
|
}
|