littlejsengine 1.24.0 → 1.24.2
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/CHANGELOG.md +86 -1
- package/EDITOR.md +2 -0
- package/FAQ.md +13 -2
- package/README.md +2 -2
- package/REFERENCE.md +27 -10
- package/dist/littlejs.d.ts +104 -29
- package/dist/littlejs.esm.js +2499 -1979
- package/dist/littlejs.esm.min.js +3 -3
- package/dist/littlejs.js +2496 -1979
- package/dist/littlejs.min.js +2 -2
- package/dist/littlejs.release.js +2438 -1983
- package/package.json +1 -1
- package/plugins/box2d.js +1 -1
- package/plugins/gltf.js +62 -9
- package/plugins/lightSystem.js +1 -1
- package/plugins/math3d.js +1014 -1013
- package/plugins/medalSystem.js +7 -11
- package/plugins/particleEffects.js +2 -2
- package/plugins/pathFinder.js +2 -2
- package/plugins/pluginExport.js +1 -0
- package/plugins/render3d.js +134 -57
- package/plugins/render3dEditor.js +28 -12
- package/plugins/render3dExtras.js +32 -17
- package/plugins/render3dLevel.js +21 -12
- package/plugins/render3dVoxels.js +15 -8
- package/plugins/textureSheet.js +97 -3
- package/plugins/tweakables.js +1 -1
- package/plugins/tweenSystem.js +2 -2
- package/plugins/uiSystem.js +6 -2
- package/src/engine.js +34 -11
- package/src/engineAudio.js +13 -3
- package/src/engineDebug.js +4 -1
- package/src/engineDraw.js +29 -16
- package/src/engineEditor.js +99 -56
- package/src/engineExport.js +2 -0
- package/src/engineInput.js +17 -3
- package/src/engineMath.js +6 -2
- package/src/engineObject.js +675 -675
- package/src/engineParticles.js +1 -1
- package/src/engineSettings.js +21 -1
- package/src/engineTileLayer.js +142 -43
- package/src/engineUtilities.js +20 -8
- package/src/engineWebGL.js +12 -8
package/dist/littlejs.d.ts
CHANGED
|
@@ -1345,6 +1345,12 @@ declare module "littlejsengine" {
|
|
|
1345
1345
|
* @default
|
|
1346
1346
|
* @memberof Settings */
|
|
1347
1347
|
export let soundEnable: boolean;
|
|
1348
|
+
/** Play sound with an iPhone's silent switch on, as media does; off by default, so the switch mutes the game as it
|
|
1349
|
+
* does a ringtone, and the player's own music keeps playing beside it; Safari 16.4 and up, elsewhere it does nothing
|
|
1350
|
+
* @type {boolean}
|
|
1351
|
+
* @default
|
|
1352
|
+
* @memberof Settings */
|
|
1353
|
+
export let soundIgnoreSilentSwitch: boolean;
|
|
1348
1354
|
/** Volume scale to apply to all sound, music and speech
|
|
1349
1355
|
* Use setSoundVolume to also update the audio master gain immediately
|
|
1350
1356
|
* @type {number}
|
|
@@ -1614,6 +1620,10 @@ declare module "littlejsengine" {
|
|
|
1614
1620
|
* @param {boolean} enable
|
|
1615
1621
|
* @memberof Settings */
|
|
1616
1622
|
export function setSoundEnable(enable: boolean): void;
|
|
1623
|
+
/** Set if sound plays with an iPhone's silent switch on, as media does, which also pauses the player's own music
|
|
1624
|
+
* @param {boolean} ignore
|
|
1625
|
+
* @memberof Settings */
|
|
1626
|
+
export function setSoundIgnoreSilentSwitch(ignore: boolean): void;
|
|
1617
1627
|
/** Set volume scale to apply to all sound, music and speech
|
|
1618
1628
|
* @param {number} volume
|
|
1619
1629
|
* @memberof Settings */
|
|
@@ -1806,7 +1816,7 @@ declare module "littlejsengine" {
|
|
|
1806
1816
|
* @return {number}
|
|
1807
1817
|
* @memberof Math */
|
|
1808
1818
|
export function smoothStep(percent: number): number;
|
|
1809
|
-
/** Returns the nearest power of two not less than the value
|
|
1819
|
+
/** Returns the nearest whole power of two not less than the value, 1 for a value of 1 or less
|
|
1810
1820
|
* @param {number} value
|
|
1811
1821
|
* @return {number}
|
|
1812
1822
|
* @memberof Math */
|
|
@@ -1899,6 +1909,7 @@ declare module "littlejsengine" {
|
|
|
1899
1909
|
export function saveText(text: string, filename?: string, type?: string): void;
|
|
1900
1910
|
/** Create an offscreen canvas to draw into, and return its 2D context
|
|
1901
1911
|
* - The canvas is context.canvas, which is what TextureInfo and the like take
|
|
1912
|
+
* - A browser with no OffscreenCanvas, Safari before 16.4, gets a canvas element that is not on the page
|
|
1902
1913
|
* @param {number} width - In pixels
|
|
1903
1914
|
* @param {number} [height] - In pixels, defaults to the width for a square
|
|
1904
1915
|
* @param {boolean} [willReadFrequently] - Keep it in software, faster when getImageData is called on it often
|
|
@@ -1933,11 +1944,12 @@ declare module "littlejsengine" {
|
|
|
1933
1944
|
export function readSaveData<T extends {
|
|
1934
1945
|
[x: string]: any;
|
|
1935
1946
|
} = any>(saveName: string, defaultSaveData?: T): T;
|
|
1936
|
-
/** Write save data to local storage
|
|
1947
|
+
/** Write save data to local storage, an object as readSaveData gives it back
|
|
1937
1948
|
* @param {string} saveName - unique name for the game/save
|
|
1938
1949
|
* @param {object} saveData - object containing data to be saved
|
|
1950
|
+
* @return {boolean} - Whether it was written, false when storage is unavailable or full
|
|
1939
1951
|
* @memberof Utilities */
|
|
1940
|
-
export function writeSaveData(saveName: string, saveData: object):
|
|
1952
|
+
export function writeSaveData(saveName: string, saveData: object): boolean;
|
|
1941
1953
|
/** 1D value noise — returns a smooth value in [0, 1] for any real x.
|
|
1942
1954
|
* Integer inputs land on deterministic lattice values; non-integer inputs
|
|
1943
1955
|
* are interpolated with smoothStep for C1 continuity.
|
|
@@ -2535,6 +2547,10 @@ declare module "littlejsengine" {
|
|
|
2535
2547
|
padding: number;
|
|
2536
2548
|
/** @property {TextureInfo} - The texture info for this tile */
|
|
2537
2549
|
textureInfo: TextureInfo;
|
|
2550
|
+
/** @property {Array<TileInfo>|undefined} - A tile set's tiles, each wherever it was packed, as loadTiles makes
|
|
2551
|
+
* them: a tile layer given this tile info draws its tile n from tiles[n] and not from a grid on one sheet
|
|
2552
|
+
* @type {Array<TileInfo>|undefined} */
|
|
2553
|
+
tiles: Array<TileInfo> | undefined;
|
|
2538
2554
|
/** @property {number} - Shrinks tile by this many pixels to prevent neighbors bleeding */
|
|
2539
2555
|
bleed: number;
|
|
2540
2556
|
/** @property {number} - How many frames per row for frame(), 0 to keep frames on a single row */
|
|
@@ -3660,13 +3676,13 @@ declare module "littlejsengine" {
|
|
|
3660
3676
|
* @memberof Audio
|
|
3661
3677
|
* @example
|
|
3662
3678
|
* // load an audio asset file
|
|
3663
|
-
* const
|
|
3679
|
+
* const music = new Sound('sound.mp3');
|
|
3664
3680
|
*
|
|
3665
3681
|
* // create a zzfx sound
|
|
3666
|
-
* const
|
|
3682
|
+
* const blip = new Sound([.5,.5]);
|
|
3667
3683
|
*
|
|
3668
3684
|
* // play a sound
|
|
3669
|
-
*
|
|
3685
|
+
* blip.play();
|
|
3670
3686
|
*/
|
|
3671
3687
|
export class Sound {
|
|
3672
3688
|
/** Create a sound object and cache the audio for later use
|
|
@@ -4282,30 +4298,36 @@ declare module "littlejsengine" {
|
|
|
4282
4298
|
* @param {Object} tileMapData - Level data from exported data
|
|
4283
4299
|
* @param {TileInfo} [tileInfo] - Default tile info (used for size and texture), tile() by default, none when no image is loaded
|
|
4284
4300
|
* @param {number} [renderOrder] - Render order of the top layer
|
|
4285
|
-
* @param {number}
|
|
4301
|
+
* @param {number|string} [collisionLayer] - Layer to use for collision if any, by its index or its name
|
|
4286
4302
|
* @param {boolean} [draw] - Should the layer be drawn automatically
|
|
4287
|
-
* @return {Array<TileCollisionLayer>}
|
|
4303
|
+
* @return {Array<TileCollisionLayer>} - It throws for a map that is not whole cells, or a layer whose tiles do not
|
|
4304
|
+
* fill it, before it makes any layer
|
|
4288
4305
|
* @memberof TileLayers */
|
|
4289
|
-
export function tileLayersLoad(tileMapData: any, tileInfo?: TileInfo, renderOrder?: number, collisionLayer?: number, draw?: boolean): Array<TileCollisionLayer>;
|
|
4306
|
+
export function tileLayersLoad(tileMapData: any, tileInfo?: TileInfo, renderOrder?: number, collisionLayer?: number | string, draw?: boolean): Array<TileCollisionLayer>;
|
|
4290
4307
|
/**
|
|
4291
4308
|
* Make a Tiled map of a level of an LDtk project, to load with tileLayersLoad and objectLayersLoad
|
|
4292
|
-
* - Each Tiles, AutoLayer and IntGrid layer is a tile layer, the bottom one first as in Tiled
|
|
4293
|
-
*
|
|
4294
|
-
*
|
|
4295
|
-
*
|
|
4296
|
-
* - An IntGrid layer
|
|
4309
|
+
* - Each Tiles, AutoLayer and IntGrid layer is a tile layer, the bottom one first as in Tiled; where LDtk stacks
|
|
4310
|
+
* tiles in a cell, an edge over a fill, each tile over another goes in a layer of its own just above, named with
|
|
4311
|
+
* (2), (3) and so on, and a tile LDtk draws see-through goes in one of its own with that opacity, times the
|
|
4312
|
+
* layer's, named with it, like Ground .25
|
|
4313
|
+
* - An IntGrid layer is a hidden layer of its values under its own name, for collision, whatever tiles its rules
|
|
4314
|
+
* make, which are layers over it named with tiles, like Collisions tiles; pass the name as collisionLayer, since
|
|
4315
|
+
* the stacked and see-through layers change the indices from level to level:
|
|
4316
|
+
* tileLayersLoad(map, tile(0, 16), 0, 'Collisions')
|
|
4297
4317
|
* - An Entities layer is an object layer: an entity's name is its type for objectLayersAddType, it is placed at
|
|
4298
4318
|
* its middle, and its Int, Float, Bool, String, Color and FilePath fields are its properties (an enum is a string)
|
|
4299
4319
|
* - The tileset is the first tile layer's, with its padding and spacing; give tileLayersLoad a tile info of its image
|
|
4300
4320
|
* - The level is in the project file (not saved as separate level files), its layers of one grid size; a layer of
|
|
4301
|
-
* another grid size or another tileset is left out, with a warning in debug builds
|
|
4321
|
+
* another grid size or another tileset is left out, with a warning in debug builds, and a project with no tileset
|
|
4322
|
+
* keeps its tiles for the tile info the game gives; a project of several worlds has its levels counted in order
|
|
4323
|
+
* - Layer offsets are not read
|
|
4302
4324
|
* - The level editor edits the map this returns, and saves it as a Tiled map
|
|
4303
4325
|
* @param {Object} ldtk - The LDtk project, its JSON
|
|
4304
4326
|
* @param {number|string} [level] - Which level, by its index or its identifier
|
|
4305
4327
|
* @return {Object} - A Tiled map: width, height, tilewidth, tileheight, tilesets and layers
|
|
4306
4328
|
* @example
|
|
4307
4329
|
* const map = tileLayersFromLDtk(await fetchJSON('world.ldtk'), 'Level_0');
|
|
4308
|
-
* const layers = tileLayersLoad(map, tile(0, 16), 0,
|
|
4330
|
+
* const layers = tileLayersLoad(map, tile(0, 16), 0, 'Collisions'); // its IntGrid layer is solid
|
|
4309
4331
|
* objectLayersLoad(map);
|
|
4310
4332
|
* @memberof TileLayers */
|
|
4311
4333
|
export function tileLayersFromLDtk(ldtk: any, level?: number | string): any;
|
|
@@ -4600,7 +4622,7 @@ declare module "littlejsengine" {
|
|
|
4600
4622
|
* rgb(1,1,1,0), rgb(0,0,0,0), // colorEndA, colorEndB
|
|
4601
4623
|
* 1, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
|
|
4602
4624
|
* .99, 1, 1, PI, .05, // damping, angleDamping, gravityScale, particleCone, fadeRate
|
|
4603
|
-
* .5,
|
|
4625
|
+
* .5, true // randomness, collide
|
|
4604
4626
|
* );
|
|
4605
4627
|
*/
|
|
4606
4628
|
export class ParticleEmitter extends EngineObject {
|
|
@@ -7676,8 +7698,8 @@ declare module "littlejsengine" {
|
|
|
7676
7698
|
* const path = pf.findPath(player.pos, mousePos);
|
|
7677
7699
|
*
|
|
7678
7700
|
* // Bare grid with custom walkability:
|
|
7679
|
-
* const
|
|
7680
|
-
*
|
|
7701
|
+
* const gridFinder = new PathFinder(vec2(50, 50));
|
|
7702
|
+
* gridFinder.isWalkable = (x, y) => myGrid[y*50 + x] === 0;
|
|
7681
7703
|
*/
|
|
7682
7704
|
export class PathFinder {
|
|
7683
7705
|
/** @param {TileCollisionLayer|Vector2} source - Either a TileCollisionLayer
|
|
@@ -8498,6 +8520,7 @@ declare module "littlejsengine" {
|
|
|
8498
8520
|
viewProjection: Matrix4;
|
|
8499
8521
|
/** @property {Matrix4} - This frame's light view projection for the shadow map */
|
|
8500
8522
|
shadowMatrix: Matrix4;
|
|
8523
|
+
gelAxes: number[];
|
|
8501
8524
|
/** @property {Vector3} - Camera right axis this frame */
|
|
8502
8525
|
cameraRight: Vector3;
|
|
8503
8526
|
/** @property {Vector3} - Camera up axis this frame */
|
|
@@ -9721,11 +9744,12 @@ declare module "littlejsengine" {
|
|
|
9721
9744
|
/** @type {Array<Vector3>} */
|
|
9722
9745
|
chunkCenters: Array<Vector3>;
|
|
9723
9746
|
chunksChanged: Set<any>;
|
|
9724
|
-
/** @type {Array<{faces: Array<number>, seeThrough: boolean, transparent: boolean}|undefined>} */
|
|
9747
|
+
/** @type {Array<{faces: Array<number>, seeThrough: boolean, transparent: boolean, doubleSided: boolean}|undefined>} */
|
|
9725
9748
|
blockTypes: Array<{
|
|
9726
9749
|
faces: Array<number>;
|
|
9727
9750
|
seeThrough: boolean;
|
|
9728
9751
|
transparent: boolean;
|
|
9752
|
+
doubleSided: boolean;
|
|
9729
9753
|
} | undefined>;
|
|
9730
9754
|
tiles: Map<any, any>;
|
|
9731
9755
|
/** The block type at a cell, 0 for empty or outside the map
|
|
@@ -9753,25 +9777,28 @@ declare module "littlejsengine" {
|
|
|
9753
9777
|
* @param {number} type - 1 to 255
|
|
9754
9778
|
* @param {number|Array<number>|{top?: number, side: number, bottom?: number}} faces - A tile index for every face,
|
|
9755
9779
|
* six in the order +x, -x, +y, -y, +z, -z, or the side's with the top and bottom's, which default to the side's
|
|
9756
|
-
* @param {{seeThrough?: boolean, transparent?: boolean}} [options] - seeThrough for holes
|
|
9757
|
-
* leaves, so the blocks beside it keep their faces; transparent to blend, like glass or
|
|
9758
|
-
* transparent stage, and see-through too
|
|
9780
|
+
* @param {{seeThrough?: boolean, transparent?: boolean, doubleSided?: boolean}} [options] - seeThrough for holes
|
|
9781
|
+
* in its texture, like leaves, so the blocks beside it keep their faces; transparent to blend, like glass or
|
|
9782
|
+
* water, drawn in the transparent stage, and see-through too; doubleSided for faces seen from inside the
|
|
9783
|
+
* block as well, like water, whose surface then shows from under it */
|
|
9759
9784
|
setBlockType(type: number, faces: number | Array<number> | {
|
|
9760
9785
|
top?: number;
|
|
9761
9786
|
side: number;
|
|
9762
9787
|
bottom?: number;
|
|
9763
|
-
}, { seeThrough, transparent }?: {
|
|
9788
|
+
}, { seeThrough, transparent, doubleSided }?: {
|
|
9764
9789
|
seeThrough?: boolean;
|
|
9765
9790
|
transparent?: boolean;
|
|
9791
|
+
doubleSided?: boolean;
|
|
9766
9792
|
}): void;
|
|
9767
9793
|
/** A block type's faces and how it is seen through
|
|
9768
9794
|
* @param {number} type
|
|
9769
|
-
* @return {{faces: Array<number>, seeThrough: boolean, transparent: boolean}}
|
|
9795
|
+
* @return {{faces: Array<number>, seeThrough: boolean, transparent: boolean, doubleSided: boolean}}
|
|
9770
9796
|
* @ignore */
|
|
9771
9797
|
blockType(type: number): {
|
|
9772
9798
|
faces: Array<number>;
|
|
9773
9799
|
seeThrough: boolean;
|
|
9774
9800
|
transparent: boolean;
|
|
9801
|
+
doubleSided: boolean;
|
|
9775
9802
|
};
|
|
9776
9803
|
/** Build every chunk again, after changing data directly or ambientOcclusion */
|
|
9777
9804
|
rebuild(): void;
|
|
@@ -9876,6 +9903,13 @@ declare module "littlejsengine" {
|
|
|
9876
9903
|
/** @property {number} - How fast the glow fades from its middle: 1 by default, .5 a wide haze, 2 a tight
|
|
9877
9904
|
* bright core */
|
|
9878
9905
|
glowFalloff: number;
|
|
9906
|
+
/** @property {TextureInfo|TileInfo|undefined} - A gel: a picture the light shines through, like a stained glass
|
|
9907
|
+
* window or the leaves of a tree, cast along its cone in its colors, upright as the light looks out, the whole
|
|
9908
|
+
* texture of a TileInfo; only the spotlight that casts the shadows has one, with render3D.shadows on and it
|
|
9909
|
+
* as render3D.shadowLight, and only on what takes its shadows: an object with receiveShadow off is lit
|
|
9910
|
+
* without the gel; its alpha is not read, see through panes are dark
|
|
9911
|
+
* @type {TextureInfo|TileInfo|undefined} */
|
|
9912
|
+
gel: TextureInfo | TileInfo | undefined;
|
|
9879
9913
|
/** @type {LensFlare3D|undefined} */
|
|
9880
9914
|
flareObject: LensFlare3D | undefined;
|
|
9881
9915
|
/** Give the light a lens flare, made with the arguments of LensFlare3D, in place of the one it had
|
|
@@ -9883,8 +9917,9 @@ declare module "littlejsengine" {
|
|
|
9883
9917
|
* @param {number} [count] - How many ghosts there are, besides the glow at the light
|
|
9884
9918
|
* @param {number} [intensity] - How bright it is
|
|
9885
9919
|
* @param {number} [saturation] - How colorful the ghosts are
|
|
9920
|
+
* @param {Color} [color] - Tints the flare, with the light's own color
|
|
9886
9921
|
* @return {LensFlare3D} - The flare, to change: light.addFlare().shapes = ['hex'] */
|
|
9887
|
-
addFlare(size?: number, count?: number, intensity?: number, saturation?: number): LensFlare3D;
|
|
9922
|
+
addFlare(size?: number, count?: number, intensity?: number, saturation?: number, color?: Color): LensFlare3D;
|
|
9888
9923
|
set flare(arg: LensFlare3D);
|
|
9889
9924
|
/** The light's lens flare, undefined for none: addFlare makes it, or set a LensFlare3D of your own, and
|
|
9890
9925
|
* destroying the flare takes it away
|
|
@@ -10209,7 +10244,8 @@ declare module "littlejsengine" {
|
|
|
10209
10244
|
* with the sun's own color; shapes says what its ghosts are, glowSize and ghostSize how big its parts are; or
|
|
10210
10245
|
* give it elements of your own, which may be tiles of the game's
|
|
10211
10246
|
* - visible is how much of the sun shows, 0 to 1, eased over fadeTime, there for a game to read; it is 0 while the
|
|
10212
|
-
* sun is off the screen, where nothing
|
|
10247
|
+
* sun is too far off the screen for the flare to show, about a seventh of the screen past its edge, where nothing
|
|
10248
|
+
* is tested
|
|
10213
10249
|
* - What hides the sun is found with a ray from the camera, against the level and every object that is not see
|
|
10214
10250
|
* through, each on the triangles of its mesh, see render3D.pick; turn it off with occlusion
|
|
10215
10251
|
* - It needs WebGL, and it draws nothing in the shadow of renderAfter2D
|
|
@@ -10252,7 +10288,8 @@ declare module "littlejsengine" {
|
|
|
10252
10288
|
elements: Array<LensFlareElement> | undefined;
|
|
10253
10289
|
/** @property {Light3D|undefined} - A light the flare is of in place of the sun, a lamp or a spotlight: the
|
|
10254
10290
|
* flare is at the light and in its color, smaller from farther than the light reaches, hidden by what is
|
|
10255
|
-
* in front of the light,
|
|
10291
|
+
* in front of the light but its lamp, a mesh around it whose surface is near it, and a spotlight's
|
|
10292
|
+
* shows from inside its beam only; a DirectionalLight3D's is far
|
|
10256
10293
|
* away where it shines from, like the sun's; the flare is destroyed when its light is; light.addFlare
|
|
10257
10294
|
* sets this
|
|
10258
10295
|
* @type {Light3D|undefined} */
|
|
@@ -10555,11 +10592,24 @@ declare module "littlejsengine" {
|
|
|
10555
10592
|
duration: number;
|
|
10556
10593
|
}
|
|
10557
10594
|
/** Parse a model from GLB bytes or glTF JSON, fetching the buffers and images it refers to
|
|
10595
|
+
* - A .gltf names its .bin and image files, which are fetched from baseUrl, or found among files: what a game
|
|
10596
|
+
* has in hand, like the files dropped on the page, by their paths in the drop; with files, baseUrl is the
|
|
10597
|
+
* .gltf's own folder among them ('' or 'models/house/'), its names are read from there, and a name found nowhere
|
|
10598
|
+
* there is taken by its file name alone only when one file of the drop has it; only an http, https or blob uri
|
|
10599
|
+
* is fetched then
|
|
10600
|
+
* - A file the model needs that is not found is named in the error, and an image that can not be read is named in
|
|
10601
|
+
* a warning and left out
|
|
10558
10602
|
* @param {ArrayBuffer|Object|string} data - GLB bytes, or the glTF JSON as bytes, text or an object
|
|
10559
10603
|
* @param {string} [baseUrl] - Where the .bin and image files are, with its trailing slash; loadGLTF passes the file's folder
|
|
10604
|
+
* @param {Map<string, Blob>} [files] - The files it refers to, by their paths, in place of fetching them
|
|
10560
10605
|
* @return {Promise<GLTFModel>}
|
|
10606
|
+
* @example
|
|
10607
|
+
* // the files of a drop, a .gltf with its .bin and textures, by their names
|
|
10608
|
+
* const files = new Map([...dataTransfer.files].map((file)=> [file.name, file]));
|
|
10609
|
+
* const gltf = [...files.values()].find((file)=> file.name.endsWith('.gltf'));
|
|
10610
|
+
* const model = await parseGLTF(await gltf.text(), '', files);
|
|
10561
10611
|
* @memberof GLTF */
|
|
10562
|
-
export function parseGLTF(data: ArrayBuffer | any | string, baseUrl?: string): Promise<GLTFModel>;
|
|
10612
|
+
export function parseGLTF(data: ArrayBuffer | any | string, baseUrl?: string, files?: Map<string, Blob>): Promise<GLTFModel>;
|
|
10563
10613
|
/** Load a glTF or GLB model, the .bin and images of a .gltf from beside it
|
|
10564
10614
|
* - A texture only OPAQUE materials use loads with its alpha set to 1, so the 3D pass cuts no holes in it
|
|
10565
10615
|
* @param {string} url
|
|
@@ -10820,6 +10870,7 @@ declare module "littlejsengine" {
|
|
|
10820
10870
|
* - Animation frames keep layout and wrap across rows as needed
|
|
10821
10871
|
* - WebGL textures upload once per batch of loads
|
|
10822
10872
|
* - loadAtlas imports pre-packed atlases (TexturePacker and Aseprite json)
|
|
10873
|
+
* - loadTiles packs separate tile images, or several tile sheets, into one tile set for tile layers and maps
|
|
10823
10874
|
* @namespace TextureSheets
|
|
10824
10875
|
*/
|
|
10825
10876
|
/** Width and height in pixels of texture sheets created by loadSprite
|
|
@@ -10890,6 +10941,7 @@ declare module "littlejsengine" {
|
|
|
10890
10941
|
* - Pass frameSize for animations, then step through them with TileInfo.frame
|
|
10891
10942
|
* - Grid images keep their layout and frames wrap down to the next row
|
|
10892
10943
|
* - Pass sourcePadding if the source image has padding baked in around frames
|
|
10944
|
+
* - The same image loaded again with the same settings gives back what the first load did, packed once
|
|
10893
10945
|
* @param {string} src - Image source path
|
|
10894
10946
|
* @param {Vector2|number} [frameSize] - Size of each animation frame in pixels, or the whole image less its
|
|
10895
10947
|
* source padding if not passed
|
|
@@ -10901,6 +10953,28 @@ declare module "littlejsengine" {
|
|
|
10901
10953
|
* const runTile = loadSprite('run.png', vec2(16)); // a 16x16 frame animation
|
|
10902
10954
|
* @memberof TextureSheets */
|
|
10903
10955
|
export function loadSprite(src: string, frameSize?: Vector2 | number, padding?: number, sourcePadding?: number | Vector2): TileInfo;
|
|
10956
|
+
/** Load tile images and pack them into texture sheets as one tile set, for tile layers and maps
|
|
10957
|
+
* - Each image is cut into tiles of tileSize, left to right then down, so an image of one tile is one tile and a
|
|
10958
|
+
* sheet is all of its tiles; the tiles are numbered from 0 in the order the images are given
|
|
10959
|
+
* - Returns a tile set at once, a TileInfo whose tiles fill in as the images load; wait for them with spritesReady
|
|
10960
|
+
* - Give it to tileLayersLoad, a TileLayer or a TileCollisionLayer as its tile info: tile n draws tiles[n],
|
|
10961
|
+
* wherever it was packed, and the level editor's palette offers each of them; frame and index do not read the
|
|
10962
|
+
* list, use set.tiles[n] for one tile; make the layers after spritesReady, a layer made before draws nothing
|
|
10963
|
+
* - An image that is not a whole number of tiles gives the whole tiles in it; a sheet with gaps between its tiles
|
|
10964
|
+
* is not read, cut it into its tiles first
|
|
10965
|
+
* - An image that fails to load, or that no sheet can hold, adds no tiles and says so in the console, so the tiles
|
|
10966
|
+
* of the images after it move up
|
|
10967
|
+
* - The same images loaded again with the same settings give back what the first load did, packed once
|
|
10968
|
+
* @param {Array<string>} sources - Image source paths
|
|
10969
|
+
* @param {Vector2|number} [tileSize] - Size of a tile in pixels
|
|
10970
|
+
* @param {number} [padding] - How many pixels padding around each tile on the sheet
|
|
10971
|
+
* @return {TileInfo}
|
|
10972
|
+
* @example
|
|
10973
|
+
* const tiles = loadTiles(['grass.png', 'dirt.png', 'water.png', 'props.png'], 16);
|
|
10974
|
+
* await spritesReady();
|
|
10975
|
+
* tileLayersLoad(map, tiles); // tile 0 is grass, 1 dirt, 2 water, then the tiles of props.png
|
|
10976
|
+
* @memberof TextureSheets */
|
|
10977
|
+
export function loadTiles(sources: Array<string>, tileSize?: Vector2 | number, padding?: number): TileInfo;
|
|
10904
10978
|
/** Load a pre-packed texture atlas and repack it onto texture sheets
|
|
10905
10979
|
* - Supports TexturePacker json (hash and array) and Aseprite json
|
|
10906
10980
|
* - Returns an empty object which is filled with TileInfos when loaded
|
|
@@ -10908,6 +10982,7 @@ declare module "littlejsengine" {
|
|
|
10908
10982
|
* - Aseprite frame tags become animations, so do names like run_0, run_1
|
|
10909
10983
|
* - Trimmed frames are restored to their full source size when packed
|
|
10910
10984
|
* - Rotated frames are rotated back upright when packed
|
|
10985
|
+
* - The same atlas loaded again by its paths, with the same padding, gives back what the first load did, packed once
|
|
10911
10986
|
* @param {string} imageSrc - Atlas image path
|
|
10912
10987
|
* @param {string|Object} jsonSrc - Atlas json path, or already parsed json data
|
|
10913
10988
|
* @param {number} [padding] - How many pixels padding around each frame
|