littlejsengine 1.7.13 → 1.8.1
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 +27 -55
- package/build/littlejs.d.ts +253 -76
- package/build/littlejs.esm.js +644 -523
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +640 -332
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +640 -332
- package/examples/breakout/game.js +17 -14
- package/examples/breakout/gameObjects.js +29 -8
- package/examples/breakout/index.html +3 -3
- package/examples/breakoutTutorial/README.md +2 -2
- package/examples/breakoutTutorial/game.js +4 -4
- package/examples/breakoutTutorial/index.html +2 -2
- package/examples/electron/build.js +2 -0
- package/examples/electron/game.js +3 -2
- package/examples/electron/index.html +2 -2
- package/examples/empty/game.js +1 -1
- package/examples/favicon.png +0 -0
- package/examples/js13k/build.js +2 -0
- package/examples/js13k/game.js +20 -15
- package/examples/js13k/index.html +14 -14
- package/examples/module/game.js +4 -3
- package/examples/module/index.html +1 -1
- package/examples/particles/index.html +19 -22
- package/examples/platformer/game.js +3 -3
- package/examples/platformer/gameEffects.js +21 -19
- package/examples/platformer/gameLevel.js +6 -6
- package/examples/platformer/gameObjects.js +18 -18
- package/examples/platformer/gamePlayer.js +4 -3
- package/examples/platformer/index.html +6 -6
- package/examples/platformer/tiles.png +0 -0
- package/examples/platformer/tilesLevel.png +0 -0
- package/examples/puzzle/game.js +10 -8
- package/examples/puzzle/index.html +2 -2
- package/examples/screenshot.jpg +0 -0
- package/examples/starter/build.js +2 -0
- package/examples/starter/game.js +32 -21
- package/examples/starter/index.html +13 -13
- package/examples/starter/tiles.png +0 -0
- package/examples/stress/index.html +2 -2
- package/examples/typescript/build.js +2 -0
- package/examples/typescript/game.js +4 -3
- package/examples/typescript/game.ts +4 -3
- package/examples/typescript/index.html +1 -1
- package/package.json +1 -1
- package/src/engine.js +59 -49
- package/src/engineAudio.js +67 -41
- package/src/engineBuild.js +23 -7
- package/src/engineDraw.js +139 -40
- package/src/engineExport.js +4 -191
- package/src/engineInput.js +22 -10
- package/src/engineMedals.js +13 -45
- package/src/engineObject.js +12 -13
- package/src/engineParticles.js +17 -17
- package/src/engineSettings.js +195 -2
- package/src/engineTileLayer.js +23 -22
- package/src/engineUtilities.js +6 -6
- package/src/engineWebGL.js +73 -74
package/build/littlejs.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
declare module "littlejs.esm" {
|
|
2
|
-
/**
|
|
3
|
-
* LittleJS Module Export
|
|
4
|
-
* - Export engine as a module with functions where necessary
|
|
5
|
-
*/
|
|
6
2
|
/** Set position of camera in world space
|
|
7
3
|
* @param {Vector2} pos
|
|
8
4
|
* @memberof Settings */
|
|
@@ -181,7 +177,7 @@ declare module "littlejs.esm" {
|
|
|
181
177
|
* @default Vector2(16,16)
|
|
182
178
|
* @memberof Settings */
|
|
183
179
|
export let tileSizeDefault: Vector2;
|
|
184
|
-
/**
|
|
180
|
+
/** How many pixels smaller to draw tiles to prevent bleeding from neighbors
|
|
185
181
|
* @type {Number}
|
|
186
182
|
* @default
|
|
187
183
|
* @memberof Settings */
|
|
@@ -231,6 +227,11 @@ declare module "littlejs.esm" {
|
|
|
231
227
|
* @default
|
|
232
228
|
* @memberof Settings */
|
|
233
229
|
export let particleEmitRateScale: number;
|
|
230
|
+
/**
|
|
231
|
+
* LittleJS Engine Settings
|
|
232
|
+
* - All settings for the engine are here
|
|
233
|
+
* @namespace Settings
|
|
234
|
+
*/
|
|
234
235
|
/** Position of camera in world space
|
|
235
236
|
* @type {Vector2}
|
|
236
237
|
* @default Vector2()
|
|
@@ -333,6 +334,15 @@ declare module "littlejs.esm" {
|
|
|
333
334
|
* @default
|
|
334
335
|
* @memberof Settings */
|
|
335
336
|
export let medalDisplayIconSize: number;
|
|
337
|
+
/**
|
|
338
|
+
* LittleJS Debug System
|
|
339
|
+
* - Press Esc to show debug overlay with mouse pick
|
|
340
|
+
* - Number keys toggle debug functions
|
|
341
|
+
* - +/- apply time scale
|
|
342
|
+
* - Debug primitive rendering
|
|
343
|
+
* - Save a 2d canvas as a png image
|
|
344
|
+
* @namespace Debug
|
|
345
|
+
*/
|
|
336
346
|
/** True if debug is enabled
|
|
337
347
|
* @type {Boolean}
|
|
338
348
|
* @default
|
|
@@ -407,6 +417,15 @@ declare module "littlejs.esm" {
|
|
|
407
417
|
* @param {String} [type='image/png']
|
|
408
418
|
* @memberof Debug */
|
|
409
419
|
export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
|
|
420
|
+
/**
|
|
421
|
+
* LittleJS Utility Classes and Functions
|
|
422
|
+
* - General purpose math library
|
|
423
|
+
* - Vector2 - fast, simple, easy 2D vector class
|
|
424
|
+
* - Color - holds a rgba color with some math functions
|
|
425
|
+
* - Timer - tracks time automatically
|
|
426
|
+
* - RandomGenerator - seeded random number generator
|
|
427
|
+
* @namespace Utilities
|
|
428
|
+
*/
|
|
410
429
|
/** A shortcut to get Math.PI
|
|
411
430
|
* @type {Number}
|
|
412
431
|
* @default Math.PI
|
|
@@ -560,10 +579,10 @@ declare module "littlejs.esm" {
|
|
|
560
579
|
* - Can be used to create a deterministic random number sequence
|
|
561
580
|
* @example
|
|
562
581
|
* let r = new RandomGenerator(123); // random number generator with seed 123
|
|
563
|
-
* let a = r.
|
|
564
|
-
* let b = r.
|
|
582
|
+
* let a = r.float(); // random value between 0 and 1
|
|
583
|
+
* let b = r.int(10); // random integer between 0 and 9
|
|
565
584
|
* r.seed = 123; // reset the seed
|
|
566
|
-
* let c = r.
|
|
585
|
+
* let c = r.float(); // the same value as a
|
|
567
586
|
*/
|
|
568
587
|
export class RandomGenerator {
|
|
569
588
|
/** Create a random number generator with the seed passed in
|
|
@@ -821,7 +840,7 @@ declare module "littlejs.esm" {
|
|
|
821
840
|
}
|
|
822
841
|
/**
|
|
823
842
|
* Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
|
|
824
|
-
* @param {Number} [x=0]
|
|
843
|
+
* @param {(Number|Vector2)} [x=0]
|
|
825
844
|
* @param {Number} [y=0]
|
|
826
845
|
* @return {Vector2}
|
|
827
846
|
* @example
|
|
@@ -831,7 +850,7 @@ declare module "littlejs.esm" {
|
|
|
831
850
|
* b = vec2(); // set b to (0, 0)
|
|
832
851
|
* @memberof Utilities
|
|
833
852
|
*/
|
|
834
|
-
export function vec2(x?: number, y?: number): Vector2;
|
|
853
|
+
export function vec2(x?: (number | Vector2), y?: number): Vector2;
|
|
835
854
|
/**
|
|
836
855
|
* Create a color object with RGBA values
|
|
837
856
|
* @param {Number} [r=1] - red
|
|
@@ -852,6 +871,9 @@ declare module "littlejs.esm" {
|
|
|
852
871
|
* @memberof Utilities
|
|
853
872
|
*/
|
|
854
873
|
export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
|
|
874
|
+
/**
|
|
875
|
+
* LittleJS Object System
|
|
876
|
+
*/
|
|
855
877
|
/**
|
|
856
878
|
* LittleJS Object Base Object Class
|
|
857
879
|
* - Top level object class used by the engine
|
|
@@ -879,23 +901,20 @@ declare module "littlejs.esm" {
|
|
|
879
901
|
*/
|
|
880
902
|
export class EngineObject {
|
|
881
903
|
/** Create an engine object and adds it to the list of objects
|
|
882
|
-
* @param {Vector2} [
|
|
883
|
-
* @param {Vector2} [size=Vector2(1,1)]
|
|
884
|
-
* @param {
|
|
885
|
-
* @param {
|
|
886
|
-
* @param {
|
|
887
|
-
* @param {
|
|
888
|
-
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
904
|
+
* @param {Vector2} [pos=Vector2()] - World space position of the object
|
|
905
|
+
* @param {Vector2} [size=Vector2(1,1)] - World space size of the object
|
|
906
|
+
* @param {TileInfo} [tileInfo] - Tile info to render object (undefined is untextured)
|
|
907
|
+
* @param {Number} [angle=0] - Angle the object is rotated by
|
|
908
|
+
* @param {Color} [color=Color()] - Color to apply to tile when rendered
|
|
909
|
+
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
889
910
|
*/
|
|
890
|
-
constructor(pos?: Vector2, size?: Vector2,
|
|
911
|
+
constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, renderOrder?: number);
|
|
891
912
|
/** @property {Vector2} - World space position of the object */
|
|
892
913
|
pos: Vector2;
|
|
893
914
|
/** @property {Vector2} - World space width and height of the object */
|
|
894
915
|
size: Vector2;
|
|
895
|
-
/** @property {
|
|
896
|
-
|
|
897
|
-
/** @property {Vector2} - Size of tile in source pixels */
|
|
898
|
-
tileSize: Vector2;
|
|
916
|
+
/** @property {TileInfo} - Tile info to render object (undefined is untextured) */
|
|
917
|
+
tileInfo: TileInfo;
|
|
899
918
|
/** @property {Number} - Angle to rotate the object */
|
|
900
919
|
angle: number;
|
|
901
920
|
/** @property {Color} - Color to apply when rendered */
|
|
@@ -975,10 +994,85 @@ declare module "littlejs.esm" {
|
|
|
975
994
|
* @return {String} */
|
|
976
995
|
toString(): string;
|
|
977
996
|
}
|
|
978
|
-
/**
|
|
979
|
-
* @type {
|
|
997
|
+
/** Array containing texture info for batch rendering system
|
|
998
|
+
* @type {Array}
|
|
980
999
|
* @memberof Draw */
|
|
981
|
-
export
|
|
1000
|
+
export let textureInfos: any[];
|
|
1001
|
+
/**
|
|
1002
|
+
* Create a tile info object
|
|
1003
|
+
* - This can take vecs or floats for easier use and conversion
|
|
1004
|
+
* - If an index is passed in, the tile size and index will determine the position
|
|
1005
|
+
* @param {(Number|Vector2)} [pos=Vector2()] - Top left corner of tile in pixels or index
|
|
1006
|
+
* @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
|
|
1007
|
+
* @param {Number} [textureIndex=0] - Texture index to use
|
|
1008
|
+
* @return {TileInfo}
|
|
1009
|
+
* @example
|
|
1010
|
+
* tile(2) // a tile at index 2 using the default tile size of 16
|
|
1011
|
+
* tile(5, 8) // a tile at index 5 using a tile size of 8
|
|
1012
|
+
* tile(1, 16, 3) // a tile at index 1 of size 16 on texture 3
|
|
1013
|
+
* tile(vec2(4,8), vec2(30,10)) // a tile at pixel location (4,8) with a size of (30,10)
|
|
1014
|
+
* @memberof Draw
|
|
1015
|
+
*/
|
|
1016
|
+
export function tile(pos?: (number | Vector2), size?: (number | Vector2), textureIndex?: number): TileInfo;
|
|
1017
|
+
/**
|
|
1018
|
+
* Tile Info - Stores info about how to draw a tile
|
|
1019
|
+
*/
|
|
1020
|
+
export class TileInfo {
|
|
1021
|
+
/** Create a tile info object
|
|
1022
|
+
* @param {Vector2} [pos=Vector2()] - Top left corner of tile in pixels
|
|
1023
|
+
* @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
|
|
1024
|
+
* @param {Number} [textureIndex=0] - Texture index to use
|
|
1025
|
+
*/
|
|
1026
|
+
constructor(pos?: Vector2, size?: Vector2, textureIndex?: number);
|
|
1027
|
+
/** @property {Vector2} - Top left corner of tile in pixels */
|
|
1028
|
+
pos: Vector2;
|
|
1029
|
+
/** @property {Vector2} - Size of tile in pixels */
|
|
1030
|
+
size: Vector2;
|
|
1031
|
+
/** @property {Number} - Texture index to use */
|
|
1032
|
+
textureIndex: number;
|
|
1033
|
+
/** Returns an offset copy of this tile, useful for animation
|
|
1034
|
+
* @param {Vector2} offset - Offset to apply in pixels
|
|
1035
|
+
* @return {TileInfo}
|
|
1036
|
+
*/
|
|
1037
|
+
offset(offset: Vector2): TileInfo;
|
|
1038
|
+
/** Returns the texture info for this tile
|
|
1039
|
+
* @return {TextureInfo}
|
|
1040
|
+
*/
|
|
1041
|
+
getTextureInfo(): TextureInfo;
|
|
1042
|
+
}
|
|
1043
|
+
/** Texture Info - Stores info about each texture */
|
|
1044
|
+
export class TextureInfo {
|
|
1045
|
+
constructor(image: any);
|
|
1046
|
+
/** @property {CanvasImageSource} - image source */
|
|
1047
|
+
image: any;
|
|
1048
|
+
/** @property {Vector2} - size of the image */
|
|
1049
|
+
size: Vector2;
|
|
1050
|
+
/** @property {WebGLTexture} - webgl texture */
|
|
1051
|
+
glTexture: WebGLTexture;
|
|
1052
|
+
/** @property {Vector2} - size to adjust tile to fix bleeding */
|
|
1053
|
+
fixBleedSize: Vector2;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* LittleJS Drawing System
|
|
1057
|
+
* - Hybrid system with both Canvas2D and WebGL available
|
|
1058
|
+
* - Super fast tile sheet rendering with WebGL
|
|
1059
|
+
* - Can apply rotation, mirror, color and additive color
|
|
1060
|
+
* - Font rendering system with built in engine font
|
|
1061
|
+
* - Many useful utility functions
|
|
1062
|
+
*
|
|
1063
|
+
* LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.
|
|
1064
|
+
* There are 3 canvas/contexts available to draw to...
|
|
1065
|
+
* mainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.
|
|
1066
|
+
* glCanvas - Used by the accelerated WebGL batch rendering system.
|
|
1067
|
+
* overlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.
|
|
1068
|
+
*
|
|
1069
|
+
* The WebGL rendering system is very fast with some caveats...
|
|
1070
|
+
* - Switching blend modes (additive) or textures causes another draw call which is expensive in excess
|
|
1071
|
+
* - Group additive rendering together using renderOrder to mitigate this issue
|
|
1072
|
+
*
|
|
1073
|
+
* The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!
|
|
1074
|
+
* @namespace Draw
|
|
1075
|
+
*/
|
|
982
1076
|
/** The primary 2D canvas visible to the user
|
|
983
1077
|
* @type {HTMLCanvasElement}
|
|
984
1078
|
* @memberof Draw */
|
|
@@ -1012,7 +1106,7 @@ declare module "littlejs.esm" {
|
|
|
1012
1106
|
/** Draw textured tile centered in world space, with color applied if using WebGL
|
|
1013
1107
|
* @param {Vector2} pos - Center of the tile in world space
|
|
1014
1108
|
* @param {Vector2} [size=Vector2(1,1)] - Size of the tile in world space
|
|
1015
|
-
* @param {
|
|
1109
|
+
* @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
|
|
1016
1110
|
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
|
|
1017
1111
|
* @param {Color} [color=Color()] - Color to modulate with
|
|
1018
1112
|
* @param {Number} [angle=0] - Angle to rotate by
|
|
@@ -1021,7 +1115,7 @@ declare module "littlejs.esm" {
|
|
|
1021
1115
|
* @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
|
|
1022
1116
|
* @param {Boolean} [screenSpace=0] - If true the pos and size are in screen space
|
|
1023
1117
|
* @memberof Draw */
|
|
1024
|
-
export function drawTile(pos: Vector2, size?: Vector2,
|
|
1118
|
+
export function drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean): void;
|
|
1025
1119
|
/** Draw colored rect centered on pos
|
|
1026
1120
|
* @param {Vector2} pos
|
|
1027
1121
|
* @param {Vector2} [size=Vector2(1,1)]
|
|
@@ -1099,14 +1193,12 @@ declare module "littlejs.esm" {
|
|
|
1099
1193
|
* @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
|
|
1100
1194
|
* @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
|
|
1101
1195
|
* @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
|
|
1102
|
-
* @param {Number} [startTileIndex=0] - Tile index in image where font starts
|
|
1103
1196
|
* @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
|
|
1104
1197
|
*/
|
|
1105
|
-
constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2,
|
|
1198
|
+
constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
|
|
1106
1199
|
image: any;
|
|
1107
1200
|
tileSize: Vector2;
|
|
1108
1201
|
paddingSize: Vector2;
|
|
1109
|
-
startTileIndex: number;
|
|
1110
1202
|
context: CanvasRenderingContext2D;
|
|
1111
1203
|
/** Draw text in world space using the image font
|
|
1112
1204
|
* @param {String} text
|
|
@@ -1130,6 +1222,14 @@ declare module "littlejs.esm" {
|
|
|
1130
1222
|
/** Toggle fullsceen mode
|
|
1131
1223
|
* @memberof Draw */
|
|
1132
1224
|
export function toggleFullscreen(): void;
|
|
1225
|
+
/**
|
|
1226
|
+
* LittleJS Input System
|
|
1227
|
+
* - Tracks keyboard down, pressed, and released
|
|
1228
|
+
* - Tracks mouse buttons, position, and wheel
|
|
1229
|
+
* - Tracks multiple analog gamepads
|
|
1230
|
+
* - Virtual gamepad for touch devices
|
|
1231
|
+
* @namespace Input
|
|
1232
|
+
*/
|
|
1133
1233
|
/** Returns true if device key is down
|
|
1134
1234
|
* @param {Number} key
|
|
1135
1235
|
* @param {Number} [device=0]
|
|
@@ -1151,6 +1251,14 @@ declare module "littlejs.esm" {
|
|
|
1151
1251
|
/** Clears all input
|
|
1152
1252
|
* @memberof Input */
|
|
1153
1253
|
export function clearInput(): void;
|
|
1254
|
+
/**
|
|
1255
|
+
* LittleJS Input System
|
|
1256
|
+
* - Tracks keyboard down, pressed, and released
|
|
1257
|
+
* - Tracks mouse buttons, position, and wheel
|
|
1258
|
+
* - Tracks multiple analog gamepads
|
|
1259
|
+
* - Virtual gamepad for touch devices
|
|
1260
|
+
* @namespace Input
|
|
1261
|
+
*/
|
|
1154
1262
|
/** Returns true if device key is down
|
|
1155
1263
|
* @param {Number} key
|
|
1156
1264
|
* @param {Number} [device=0]
|
|
@@ -1225,6 +1333,16 @@ declare module "littlejs.esm" {
|
|
|
1225
1333
|
/** True if a touch device has been detected
|
|
1226
1334
|
* @memberof Input */
|
|
1227
1335
|
export const isTouchDevice: boolean;
|
|
1336
|
+
/**
|
|
1337
|
+
* LittleJS Audio System
|
|
1338
|
+
* - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
|
|
1339
|
+
* - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
|
|
1340
|
+
* - Caches sounds and music for fast playback
|
|
1341
|
+
* - Can attenuate and apply stereo panning to sounds
|
|
1342
|
+
* - Ability to play mp3, ogg, and wave files
|
|
1343
|
+
* - Speech synthesis functions
|
|
1344
|
+
* @namespace Audio
|
|
1345
|
+
*/
|
|
1228
1346
|
/**
|
|
1229
1347
|
* Sound Object - Stores a zzfx sound for later use and can be played positionally
|
|
1230
1348
|
*
|
|
@@ -1249,22 +1367,39 @@ declare module "littlejs.esm" {
|
|
|
1249
1367
|
taper: number;
|
|
1250
1368
|
/** @property {Number} - How much to randomize frequency each time sound plays */
|
|
1251
1369
|
randomness: any;
|
|
1252
|
-
|
|
1370
|
+
sampleChannels: any[][];
|
|
1371
|
+
sampleRate: number;
|
|
1253
1372
|
/** Play the sound
|
|
1254
1373
|
* @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
|
|
1255
1374
|
* @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
|
|
1256
1375
|
* @param {Number} [pitch=1] - How much to scale pitch by (also adjusted by this.randomness)
|
|
1257
1376
|
* @param {Number} [randomnessScale=1] - How much to scale randomness
|
|
1258
|
-
* @
|
|
1377
|
+
* @param {Boolean} [loop=0] - Should the sound loop
|
|
1378
|
+
* @return {AudioBufferSourceNode} - The audio source node
|
|
1259
1379
|
*/
|
|
1260
|
-
play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number): AudioBufferSourceNode;
|
|
1380
|
+
play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
|
|
1381
|
+
source: number | AudioBufferSourceNode;
|
|
1382
|
+
/** Stop the last instance of this sound that was played */
|
|
1383
|
+
stop(): void;
|
|
1261
1384
|
/** Play the sound as a note with a semitone offset
|
|
1262
1385
|
* @param {Number} semitoneOffset - How many semitones to offset pitch
|
|
1263
1386
|
* @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
|
|
1264
1387
|
* @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
|
|
1265
|
-
* @return {AudioBufferSourceNode} - The audio
|
|
1388
|
+
* @return {AudioBufferSourceNode} - The audio source node
|
|
1266
1389
|
*/
|
|
1267
1390
|
playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
|
|
1391
|
+
/** Get how long this sound is in seconds
|
|
1392
|
+
* @return {Number} - How long the sound is in seconds (undefined if loading)
|
|
1393
|
+
*/
|
|
1394
|
+
getDuration(): number;
|
|
1395
|
+
/** Check if the last instance of this sound is playing
|
|
1396
|
+
* @return {Boolean} - True if the sound is playing
|
|
1397
|
+
*/
|
|
1398
|
+
isPlaying(): boolean;
|
|
1399
|
+
/** Check if sound is loading, for sounds fetched from a url
|
|
1400
|
+
* @return {Boolean} - True if sound is loading and not ready to play
|
|
1401
|
+
*/
|
|
1402
|
+
isLoading(): boolean;
|
|
1268
1403
|
}
|
|
1269
1404
|
/**
|
|
1270
1405
|
* Music Object - Stores a zzfx music track for later use
|
|
@@ -1296,30 +1431,23 @@ declare module "littlejs.esm" {
|
|
|
1296
1431
|
* // play the music
|
|
1297
1432
|
* music_example.play();
|
|
1298
1433
|
*/
|
|
1299
|
-
export class Music {
|
|
1434
|
+
export class Music extends Sound {
|
|
1300
1435
|
/** Create a music object and cache the zzfx music samples for later use
|
|
1301
1436
|
* @param {Array} zzfxMusic - Array of zzfx music parameters
|
|
1302
1437
|
*/
|
|
1303
1438
|
constructor(zzfxMusic: any[]);
|
|
1304
|
-
|
|
1439
|
+
sampleChannels: any[];
|
|
1305
1440
|
/** Play the music
|
|
1306
1441
|
* @param {Number} [volume=1] - How much to scale volume by
|
|
1307
|
-
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1308
|
-
* @return {AudioBufferSourceNode} - The audio node
|
|
1442
|
+
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1443
|
+
* @return {AudioBufferSourceNode} - The audio source node
|
|
1309
1444
|
*/
|
|
1310
1445
|
play(volume?: number, loop?: boolean): AudioBufferSourceNode;
|
|
1311
|
-
source: number | AudioBufferSourceNode;
|
|
1312
|
-
/** Stop the music */
|
|
1313
|
-
stop(): void;
|
|
1314
|
-
/** Check if music is playing
|
|
1315
|
-
* @return {Boolean}
|
|
1316
|
-
*/
|
|
1317
|
-
isPlaying(): boolean;
|
|
1318
1446
|
}
|
|
1319
|
-
/** Play an mp3 or wav audio from a local file or url
|
|
1447
|
+
/** Play an mp3, ogg, or wav audio from a local file or url
|
|
1320
1448
|
* @param {String} url - Location of sound file to play
|
|
1321
1449
|
* @param {Number} [volume=1] - How much to scale volume by
|
|
1322
|
-
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1450
|
+
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1323
1451
|
* @return {HTMLAudioElement} - The audio element for this sound
|
|
1324
1452
|
* @memberof Audio */
|
|
1325
1453
|
export function playAudioFile(url: string, volume?: number, loop?: boolean): HTMLAudioElement;
|
|
@@ -1350,9 +1478,10 @@ declare module "littlejs.esm" {
|
|
|
1350
1478
|
* @param {Number} [rate=1] - The playback rate to use
|
|
1351
1479
|
* @param {Number} [pan=0] - How much to apply stereo panning
|
|
1352
1480
|
* @param {Boolean} [loop=0] - True if the sound should loop when it reaches the end
|
|
1481
|
+
* @param {Number} [sampleRate=44100] - Sample rate for the sound
|
|
1353
1482
|
* @return {AudioBufferSourceNode} - The audio node of the sound played
|
|
1354
1483
|
* @memberof Audio */
|
|
1355
|
-
export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean): AudioBufferSourceNode;
|
|
1484
|
+
export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number): AudioBufferSourceNode;
|
|
1356
1485
|
/** Generate and play a ZzFX sound
|
|
1357
1486
|
*
|
|
1358
1487
|
* <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
|
|
@@ -1360,6 +1489,17 @@ declare module "littlejs.esm" {
|
|
|
1360
1489
|
* @return {AudioBufferSourceNode} - The audio node of the sound played
|
|
1361
1490
|
* @memberof Audio */
|
|
1362
1491
|
export function zzfx(...zzfxSound: any[]): AudioBufferSourceNode;
|
|
1492
|
+
/**
|
|
1493
|
+
* LittleJS Tile Layer System
|
|
1494
|
+
* - Caches arrays of tiles to off screen canvas for fast rendering
|
|
1495
|
+
* - Unlimted numbers of layers, allocates canvases as needed
|
|
1496
|
+
* - Interfaces with EngineObject for collision
|
|
1497
|
+
* - Collision layer is separate from visible layers
|
|
1498
|
+
* - It is recommended to have a visible layer that matches the collision
|
|
1499
|
+
* - Tile layers can be drawn to using their context with canvas2d
|
|
1500
|
+
* - Drawn directly to the main canvas without using WebGL
|
|
1501
|
+
* @namespace TileCollision
|
|
1502
|
+
*/
|
|
1363
1503
|
/** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
|
|
1364
1504
|
* @type {Array}
|
|
1365
1505
|
* @memberof TileCollision */
|
|
@@ -1425,7 +1565,7 @@ declare module "littlejs.esm" {
|
|
|
1425
1565
|
clear(): void;
|
|
1426
1566
|
}
|
|
1427
1567
|
/**
|
|
1428
|
-
* Tile
|
|
1568
|
+
* Tile Layer - cached rendering system for tile layers
|
|
1429
1569
|
* - Each Tile layer is rendered to an off screen canvas
|
|
1430
1570
|
* - To allow dynamic modifications, layers are rendered using canvas 2d
|
|
1431
1571
|
* - Some devices like mobile phones are limited to 4k texture resolution
|
|
@@ -1440,11 +1580,11 @@ declare module "littlejs.esm" {
|
|
|
1440
1580
|
/** Create a tile layer object
|
|
1441
1581
|
* @param {Vector2} [position=Vector2()] - World space position
|
|
1442
1582
|
* @param {Vector2} [size=tileCollisionSize] - World space size
|
|
1443
|
-
* @param {
|
|
1583
|
+
* @param {TileInfo} [tileInfo] - Tile info for layer
|
|
1444
1584
|
* @param {Vector2} [scale=Vector2(1,1)] - How much to scale this layer when rendered
|
|
1445
1585
|
* @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
|
|
1446
1586
|
*/
|
|
1447
|
-
constructor(pos: any, size?: Vector2,
|
|
1587
|
+
constructor(pos: any, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
|
|
1448
1588
|
/** @property {HTMLCanvasElement} - The canvas used by this tile layer */
|
|
1449
1589
|
canvas: HTMLCanvasElement;
|
|
1450
1590
|
/** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
|
|
@@ -1486,12 +1626,11 @@ declare module "littlejs.esm" {
|
|
|
1486
1626
|
/** Draw a tile directly onto the layer canvas
|
|
1487
1627
|
* @param {Vector2} pos
|
|
1488
1628
|
* @param {Vector2} [size=Vector2(1,1)]
|
|
1489
|
-
* @param {
|
|
1490
|
-
* @param {Vector2} [tileSize=tileSizeDefault]
|
|
1629
|
+
* @param {TileInfo} [tileInfo]
|
|
1491
1630
|
* @param {Color} [color=Color()]
|
|
1492
1631
|
* @param {Number} [angle=0]
|
|
1493
1632
|
* @param {Boolean} [mirror=0] */
|
|
1494
|
-
drawTile(pos: Vector2, size?: Vector2,
|
|
1633
|
+
drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
|
|
1495
1634
|
/** Draw a rectangle directly onto the layer canvas
|
|
1496
1635
|
* @param {Vector2} pos
|
|
1497
1636
|
* @param {Vector2} [size=Vector2(1,1)]
|
|
@@ -1499,6 +1638,9 @@ declare module "littlejs.esm" {
|
|
|
1499
1638
|
* @param {Number} [angle=0] */
|
|
1500
1639
|
drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
|
|
1501
1640
|
}
|
|
1641
|
+
/**
|
|
1642
|
+
* LittleJS Particle System
|
|
1643
|
+
*/
|
|
1502
1644
|
/**
|
|
1503
1645
|
* Particle Emitter - Spawns particles with the given settings
|
|
1504
1646
|
* @extends EngineObject
|
|
@@ -1508,7 +1650,7 @@ declare module "littlejs.esm" {
|
|
|
1508
1650
|
* let particleEmiter = new ParticleEmitter
|
|
1509
1651
|
* (
|
|
1510
1652
|
* pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
|
|
1511
|
-
* 0,
|
|
1653
|
+
* tile(0, 16), // tileInfo
|
|
1512
1654
|
* new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
|
|
1513
1655
|
* new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
|
|
1514
1656
|
* 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
|
|
@@ -1524,8 +1666,7 @@ declare module "littlejs.esm" {
|
|
|
1524
1666
|
* @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
|
|
1525
1667
|
* @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
|
|
1526
1668
|
* @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
|
|
1527
|
-
* @param {
|
|
1528
|
-
* @param {Vector2} [tileSize=tileSizeDefault] - Tile size for particles
|
|
1669
|
+
* @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
|
|
1529
1670
|
* @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
|
|
1530
1671
|
* @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
|
|
1531
1672
|
* @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
|
|
@@ -1547,7 +1688,7 @@ declare module "littlejs.esm" {
|
|
|
1547
1688
|
* @param {Number} [renderOrder=0] - Render order for particles (additive is above other stuff by default)
|
|
1548
1689
|
* @param {Boolean} [localSpace=0] - Should it be in local space of emitter (world space is default)
|
|
1549
1690
|
*/
|
|
1550
|
-
constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number,
|
|
1691
|
+
constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileInfo?: TileInfo, colorStartA?: Color, colorStartB?: Color, colorEndA?: Color, colorEndB?: Color, particleTime?: number, sizeStart?: number, sizeEnd?: number, speed?: number, angleSpeed?: number, damping?: number, angleDamping?: number, gravityScale?: number, particleConeAngle?: number, fadeRate?: number, randomness?: number, collideTiles?: boolean, additive?: boolean, randomColorLinear?: boolean, renderOrder?: number, localSpace?: boolean);
|
|
1551
1692
|
/** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
|
|
1552
1693
|
emitSize: number;
|
|
1553
1694
|
/** @property {Number} - How long to stay alive (0 is forever) */
|
|
@@ -1603,12 +1744,18 @@ declare module "littlejs.esm" {
|
|
|
1603
1744
|
/**
|
|
1604
1745
|
* Create a particle with the given settings
|
|
1605
1746
|
* @param {Vector2} position - World space position of the particle
|
|
1606
|
-
* @param {
|
|
1607
|
-
* @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
|
|
1747
|
+
* @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
|
|
1608
1748
|
* @param {Number} [angle=0] - Angle to rotate the particle
|
|
1609
1749
|
*/
|
|
1610
|
-
constructor(pos: any,
|
|
1750
|
+
constructor(pos: any, tileInfo?: TileInfo, angle?: number);
|
|
1611
1751
|
}
|
|
1752
|
+
/**
|
|
1753
|
+
* LittleJS Medal System
|
|
1754
|
+
* - Tracks and displays medals
|
|
1755
|
+
* - Saves medals to local storage
|
|
1756
|
+
* - Newgrounds integration
|
|
1757
|
+
* @namespace Medals
|
|
1758
|
+
*/
|
|
1612
1759
|
/** List of all medals
|
|
1613
1760
|
* @type {Array}
|
|
1614
1761
|
* @memberof Medals */
|
|
@@ -1627,10 +1774,11 @@ declare module "littlejs.esm" {
|
|
|
1627
1774
|
/** This can used to enable Newgrounds functionality
|
|
1628
1775
|
* @param {Number} app_id - The newgrounds App ID
|
|
1629
1776
|
* @param {String} [cipher] - The encryption Key (AES-128/Base64)
|
|
1777
|
+
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
|
|
1630
1778
|
* @memberof Medals */
|
|
1631
|
-
export function newgroundsInit(app_id: number, cipher?: string): void;
|
|
1779
|
+
export function newgroundsInit(app_id: number, cipher?: string, cryptoJS?: any): void;
|
|
1632
1780
|
/**
|
|
1633
|
-
* Medal
|
|
1781
|
+
* Medal - Tracks an unlockable medal
|
|
1634
1782
|
* @example
|
|
1635
1783
|
* // create a medal
|
|
1636
1784
|
* const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
|
|
@@ -1642,7 +1790,7 @@ declare module "littlejs.esm" {
|
|
|
1642
1790
|
* medal_example.unlock();
|
|
1643
1791
|
*/
|
|
1644
1792
|
export class Medal {
|
|
1645
|
-
/** Create
|
|
1793
|
+
/** Create a medal object and adds it to the list of medals
|
|
1646
1794
|
* @param {Number} id - The unique identifier of the medal
|
|
1647
1795
|
* @param {String} name - Name of the medal
|
|
1648
1796
|
* @param {String} [description] - Description of the medal
|
|
@@ -1673,20 +1821,20 @@ declare module "littlejs.esm" {
|
|
|
1673
1821
|
/**
|
|
1674
1822
|
* Newgrounds API wrapper object
|
|
1675
1823
|
* @example
|
|
1676
|
-
* // create a newgrounds object, replace the app id
|
|
1824
|
+
* // create a newgrounds object, replace the app id with your own
|
|
1677
1825
|
* const app_id = '53123:1ZuSTQ9l';
|
|
1678
|
-
*
|
|
1679
|
-
* newgrounds = new Newgrounds(app_id, cipher);
|
|
1826
|
+
* newgrounds = new Newgrounds(app_id);
|
|
1680
1827
|
*/
|
|
1681
1828
|
export class Newgrounds {
|
|
1682
1829
|
/** Create a newgrounds object
|
|
1683
1830
|
* @param {Number} app_id - The newgrounds App ID
|
|
1684
|
-
* @param {String} [cipher] - The encryption Key (AES-128/Base64)
|
|
1685
|
-
|
|
1831
|
+
* @param {String} [cipher] - The encryption Key (AES-128/Base64)
|
|
1832
|
+
* @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher */
|
|
1833
|
+
constructor(app_id: number, cipher?: string, cryptoJS?: any);
|
|
1686
1834
|
app_id: number;
|
|
1687
1835
|
cipher: string;
|
|
1688
|
-
host: string;
|
|
1689
1836
|
cryptoJS: any;
|
|
1837
|
+
host: string;
|
|
1690
1838
|
session_id: string;
|
|
1691
1839
|
medals: any;
|
|
1692
1840
|
scoreboards: any;
|
|
@@ -1715,8 +1863,18 @@ declare module "littlejs.esm" {
|
|
|
1715
1863
|
* @return {Object} - The response JSON object
|
|
1716
1864
|
*/
|
|
1717
1865
|
call(component: string, parameters?: any, async?: boolean): any;
|
|
1718
|
-
CryptoJS(): any;
|
|
1719
1866
|
}
|
|
1867
|
+
/**
|
|
1868
|
+
* LittleJS WebGL Interface
|
|
1869
|
+
* - All webgl used by the engine is wrapped up here
|
|
1870
|
+
* - For normal stuff you won't need to see or call anything in this file
|
|
1871
|
+
* - For advanced stuff there are helper functions to create shaders, textures, etc
|
|
1872
|
+
* - Can be disabled with glEnable to revert to 2D canvas rendering
|
|
1873
|
+
* - Batches sprite rendering on GPU for incredibly fast performance
|
|
1874
|
+
* - Sprite transform math is done in the shader where possible
|
|
1875
|
+
* - Supports shadertoy style post processing shaders
|
|
1876
|
+
* @namespace WebGL
|
|
1877
|
+
*/
|
|
1720
1878
|
/** The WebGL canvas which appears above the main canvas and below the overlay canvas
|
|
1721
1879
|
* @type {HTMLCanvasElement}
|
|
1722
1880
|
* @memberof WebGL */
|
|
@@ -1729,11 +1887,11 @@ declare module "littlejs.esm" {
|
|
|
1729
1887
|
* @param {Boolean} [additive=0]
|
|
1730
1888
|
* @memberof WebGL */
|
|
1731
1889
|
export function glSetBlendMode(additive?: boolean): void;
|
|
1732
|
-
/** Set the WebGl texture,
|
|
1890
|
+
/** Set the WebGl texture, called automatically if using multiple textures
|
|
1733
1891
|
* - This may also flush the gl buffer resulting in more draw calls and worse performance
|
|
1734
|
-
* @param {WebGLTexture}
|
|
1892
|
+
* @param {WebGLTexture} texture
|
|
1735
1893
|
* @memberof WebGL */
|
|
1736
|
-
export function glSetTexture(texture
|
|
1894
|
+
export function glSetTexture(texture: WebGLTexture): void;
|
|
1737
1895
|
/** Compile WebGL shader of the given type, will throw errors if in debug mode
|
|
1738
1896
|
* @param {String} source
|
|
1739
1897
|
* @param type
|
|
@@ -1756,6 +1914,25 @@ declare module "littlejs.esm" {
|
|
|
1756
1914
|
* @param {Boolean} includeOverlay
|
|
1757
1915
|
* @memberof WebGL */
|
|
1758
1916
|
export function glInitPostProcess(shaderCode: string, includeOverlay: boolean): void;
|
|
1917
|
+
/**
|
|
1918
|
+
* LittleJS - The Tiny JavaScript Game Engine That Can!
|
|
1919
|
+
* MIT License - Copyright 2021 Frank Force
|
|
1920
|
+
*
|
|
1921
|
+
* Engine Features
|
|
1922
|
+
* - Object oriented system with base class engine object
|
|
1923
|
+
* - Base class object handles update, physics, collision, rendering, etc
|
|
1924
|
+
* - Engine helper classes and functions like Vector2, Color, and Timer
|
|
1925
|
+
* - Super fast rendering system for tile sheets
|
|
1926
|
+
* - Sound effects audio with zzfx and music with zzfxm
|
|
1927
|
+
* - Input processing system with gamepad and touchscreen support
|
|
1928
|
+
* - Tile layer rendering and collision system
|
|
1929
|
+
* - Particle effect system
|
|
1930
|
+
* - Medal system tracks and displays achievements
|
|
1931
|
+
* - Debug tools and debug rendering system
|
|
1932
|
+
* - Post processing effects
|
|
1933
|
+
* - Call engineInit() to start it up!
|
|
1934
|
+
* @namespace Engine
|
|
1935
|
+
*/
|
|
1759
1936
|
/** Name of engine
|
|
1760
1937
|
* @type {String}
|
|
1761
1938
|
* @default
|
|
@@ -1807,9 +1984,9 @@ declare module "littlejs.esm" {
|
|
|
1807
1984
|
* @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
|
|
1808
1985
|
* @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
|
|
1809
1986
|
* @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
|
|
1810
|
-
* @param {String} [
|
|
1987
|
+
* @param {String} [imageSources='tiles.png'] - Image to load
|
|
1811
1988
|
* @memberof Engine */
|
|
1812
|
-
export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function,
|
|
1989
|
+
export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: string): void;
|
|
1813
1990
|
/** Update each engine object, remove destroyed objects, and update time
|
|
1814
1991
|
* @memberof Engine */
|
|
1815
1992
|
export function engineObjectsUpdate(): void;
|