littlejsengine 1.7.13 → 1.7.21
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/build/littlejs.d.ts +152 -18
- package/build/littlejs.esm.js +158 -115
- package/build/littlejs.esm.min.js +1 -1
- package/build/littlejs.js +158 -115
- package/build/littlejs.min.js +1 -1
- package/build/littlejs.release.js +158 -115
- package/examples/electron/build.js +2 -0
- package/examples/js13k/build.js +2 -0
- package/examples/screenshot.jpg +0 -0
- package/examples/starter/build.js +2 -0
- package/examples/starter/game.js +1 -1
- package/examples/typescript/build.js +2 -0
- package/package.json +1 -1
- package/src/engine.js +10 -7
- package/src/engineAudio.js +67 -41
- package/src/engineBuild.js +23 -7
- package/src/engineDraw.js +2 -2
- package/src/engineInput.js +22 -10
- package/src/engineWebGL.js +43 -43
package/build/littlejs.d.ts
CHANGED
|
@@ -231,6 +231,11 @@ declare module "littlejs.esm" {
|
|
|
231
231
|
* @default
|
|
232
232
|
* @memberof Settings */
|
|
233
233
|
export let particleEmitRateScale: number;
|
|
234
|
+
/**
|
|
235
|
+
* LittleJS Engine Settings
|
|
236
|
+
* - All settings for the engine are here
|
|
237
|
+
* @namespace Settings
|
|
238
|
+
*/
|
|
234
239
|
/** Position of camera in world space
|
|
235
240
|
* @type {Vector2}
|
|
236
241
|
* @default Vector2()
|
|
@@ -333,6 +338,15 @@ declare module "littlejs.esm" {
|
|
|
333
338
|
* @default
|
|
334
339
|
* @memberof Settings */
|
|
335
340
|
export let medalDisplayIconSize: number;
|
|
341
|
+
/**
|
|
342
|
+
* LittleJS Debug System
|
|
343
|
+
* - Press Esc to show debug overlay with mouse pick
|
|
344
|
+
* - Number keys toggle debug functions
|
|
345
|
+
* - +/- apply time scale
|
|
346
|
+
* - Debug primitive rendering
|
|
347
|
+
* - Save a 2d canvas as a png image
|
|
348
|
+
* @namespace Debug
|
|
349
|
+
*/
|
|
336
350
|
/** True if debug is enabled
|
|
337
351
|
* @type {Boolean}
|
|
338
352
|
* @default
|
|
@@ -407,6 +421,15 @@ declare module "littlejs.esm" {
|
|
|
407
421
|
* @param {String} [type='image/png']
|
|
408
422
|
* @memberof Debug */
|
|
409
423
|
export function debugSaveCanvas(canvas: HTMLCanvasElement, filename?: string, type?: string): void;
|
|
424
|
+
/**
|
|
425
|
+
* LittleJS Utility Classes and Functions
|
|
426
|
+
* - General purpose math library
|
|
427
|
+
* - Vector2 - fast, simple, easy 2D vector class
|
|
428
|
+
* - Color - holds a rgba color with some math functions
|
|
429
|
+
* - Timer - tracks time automatically
|
|
430
|
+
* - RandomGenerator - seeded random number generator
|
|
431
|
+
* @namespace Utilities
|
|
432
|
+
*/
|
|
410
433
|
/** A shortcut to get Math.PI
|
|
411
434
|
* @type {Number}
|
|
412
435
|
* @default Math.PI
|
|
@@ -852,6 +875,9 @@ declare module "littlejs.esm" {
|
|
|
852
875
|
* @memberof Utilities
|
|
853
876
|
*/
|
|
854
877
|
export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
|
|
878
|
+
/**
|
|
879
|
+
* LittleJS Object System
|
|
880
|
+
*/
|
|
855
881
|
/**
|
|
856
882
|
* LittleJS Object Base Object Class
|
|
857
883
|
* - Top level object class used by the engine
|
|
@@ -979,6 +1005,27 @@ declare module "littlejs.esm" {
|
|
|
979
1005
|
* @type {CanvasImageSource}
|
|
980
1006
|
* @memberof Draw */
|
|
981
1007
|
export const tileImage: CanvasImageSource;
|
|
1008
|
+
/**
|
|
1009
|
+
* LittleJS Drawing System
|
|
1010
|
+
* - Hybrid system with both Canvas2D and WebGL available
|
|
1011
|
+
* - Super fast tile sheet rendering with WebGL
|
|
1012
|
+
* - Can apply rotation, mirror, color and additive color
|
|
1013
|
+
* - Font rendering system with built in engine font
|
|
1014
|
+
* - Many useful utility functions
|
|
1015
|
+
*
|
|
1016
|
+
* LittleJS uses a hybrid rendering solution with the best of both Canvas2D and WebGL.
|
|
1017
|
+
* There are 3 canvas/contexts available to draw to...
|
|
1018
|
+
* mainCanvas - 2D background canvas, non WebGL stuff like tile layers are drawn here.
|
|
1019
|
+
* glCanvas - Used by the accelerated WebGL batch rendering system.
|
|
1020
|
+
* overlayCanvas - Another 2D canvas that appears on top of the other 2 canvases.
|
|
1021
|
+
*
|
|
1022
|
+
* The WebGL rendering system is very fast with some caveats...
|
|
1023
|
+
* - Switching blend modes (additive) or textures causes another draw call which is expensive in excess
|
|
1024
|
+
* - Group additive rendering together using renderOrder to mitigate this issue
|
|
1025
|
+
*
|
|
1026
|
+
* The LittleJS rendering solution is intentionally simple, feel free to adjust it for your needs!
|
|
1027
|
+
* @namespace Draw
|
|
1028
|
+
*/
|
|
982
1029
|
/** The primary 2D canvas visible to the user
|
|
983
1030
|
* @type {HTMLCanvasElement}
|
|
984
1031
|
* @memberof Draw */
|
|
@@ -1130,6 +1177,14 @@ declare module "littlejs.esm" {
|
|
|
1130
1177
|
/** Toggle fullsceen mode
|
|
1131
1178
|
* @memberof Draw */
|
|
1132
1179
|
export function toggleFullscreen(): void;
|
|
1180
|
+
/**
|
|
1181
|
+
* LittleJS Input System
|
|
1182
|
+
* - Tracks keyboard down, pressed, and released
|
|
1183
|
+
* - Tracks mouse buttons, position, and wheel
|
|
1184
|
+
* - Tracks multiple analog gamepads
|
|
1185
|
+
* - Virtual gamepad for touch devices
|
|
1186
|
+
* @namespace Input
|
|
1187
|
+
*/
|
|
1133
1188
|
/** Returns true if device key is down
|
|
1134
1189
|
* @param {Number} key
|
|
1135
1190
|
* @param {Number} [device=0]
|
|
@@ -1151,6 +1206,14 @@ declare module "littlejs.esm" {
|
|
|
1151
1206
|
/** Clears all input
|
|
1152
1207
|
* @memberof Input */
|
|
1153
1208
|
export function clearInput(): void;
|
|
1209
|
+
/**
|
|
1210
|
+
* LittleJS Input System
|
|
1211
|
+
* - Tracks keyboard down, pressed, and released
|
|
1212
|
+
* - Tracks mouse buttons, position, and wheel
|
|
1213
|
+
* - Tracks multiple analog gamepads
|
|
1214
|
+
* - Virtual gamepad for touch devices
|
|
1215
|
+
* @namespace Input
|
|
1216
|
+
*/
|
|
1154
1217
|
/** Returns true if device key is down
|
|
1155
1218
|
* @param {Number} key
|
|
1156
1219
|
* @param {Number} [device=0]
|
|
@@ -1225,6 +1288,16 @@ declare module "littlejs.esm" {
|
|
|
1225
1288
|
/** True if a touch device has been detected
|
|
1226
1289
|
* @memberof Input */
|
|
1227
1290
|
export const isTouchDevice: boolean;
|
|
1291
|
+
/**
|
|
1292
|
+
* LittleJS Audio System
|
|
1293
|
+
* - <a href=https://killedbyapixel.github.io/ZzFX/>ZzFX Sound Effects</a> - ZzFX Sound Effect Generator
|
|
1294
|
+
* - <a href=https://keithclark.github.io/ZzFXM/>ZzFXM Music</a> - ZzFXM Music System
|
|
1295
|
+
* - Caches sounds and music for fast playback
|
|
1296
|
+
* - Can attenuate and apply stereo panning to sounds
|
|
1297
|
+
* - Ability to play mp3, ogg, and wave files
|
|
1298
|
+
* - Speech synthesis functions
|
|
1299
|
+
* @namespace Audio
|
|
1300
|
+
*/
|
|
1228
1301
|
/**
|
|
1229
1302
|
* Sound Object - Stores a zzfx sound for later use and can be played positionally
|
|
1230
1303
|
*
|
|
@@ -1249,22 +1322,39 @@ declare module "littlejs.esm" {
|
|
|
1249
1322
|
taper: number;
|
|
1250
1323
|
/** @property {Number} - How much to randomize frequency each time sound plays */
|
|
1251
1324
|
randomness: any;
|
|
1252
|
-
|
|
1325
|
+
sampleChannels: any[][];
|
|
1326
|
+
sampleRate: number;
|
|
1253
1327
|
/** Play the sound
|
|
1254
1328
|
* @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
|
|
1255
1329
|
* @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
|
|
1256
1330
|
* @param {Number} [pitch=1] - How much to scale pitch by (also adjusted by this.randomness)
|
|
1257
1331
|
* @param {Number} [randomnessScale=1] - How much to scale randomness
|
|
1258
|
-
* @
|
|
1332
|
+
* @param {Boolean} [loop=0] - Should the sound loop
|
|
1333
|
+
* @return {AudioBufferSourceNode} - The audio source node
|
|
1259
1334
|
*/
|
|
1260
|
-
play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number): AudioBufferSourceNode;
|
|
1335
|
+
play(pos?: Vector2, volume?: number, pitch?: number, randomnessScale?: number, loop?: boolean): AudioBufferSourceNode;
|
|
1336
|
+
source: number | AudioBufferSourceNode;
|
|
1337
|
+
/** Stop the last instance of this sound that was played */
|
|
1338
|
+
stop(): void;
|
|
1261
1339
|
/** Play the sound as a note with a semitone offset
|
|
1262
1340
|
* @param {Number} semitoneOffset - How many semitones to offset pitch
|
|
1263
1341
|
* @param {Vector2} [pos] - World space position to play the sound, sound is not attenuated if null
|
|
1264
1342
|
* @param {Number} [volume=1] - How much to scale volume by (in addition to range fade)
|
|
1265
|
-
* @return {AudioBufferSourceNode} - The audio
|
|
1343
|
+
* @return {AudioBufferSourceNode} - The audio source node
|
|
1266
1344
|
*/
|
|
1267
1345
|
playNote(semitoneOffset: number, pos?: Vector2, volume?: number): AudioBufferSourceNode;
|
|
1346
|
+
/** Get how long this sound is in seconds
|
|
1347
|
+
* @return {Number} - How long the sound is in seconds (undefined if loading)
|
|
1348
|
+
*/
|
|
1349
|
+
getDuration(): number;
|
|
1350
|
+
/** Check if the last instance of this sound is playing
|
|
1351
|
+
* @return {Boolean} - True if the sound is playing
|
|
1352
|
+
*/
|
|
1353
|
+
isPlaying(): boolean;
|
|
1354
|
+
/** Check if sound is loading, for sounds fetched from a url
|
|
1355
|
+
* @return {Boolean} - True if sound is loading and not ready to play
|
|
1356
|
+
*/
|
|
1357
|
+
isLoading(): boolean;
|
|
1268
1358
|
}
|
|
1269
1359
|
/**
|
|
1270
1360
|
* Music Object - Stores a zzfx music track for later use
|
|
@@ -1296,30 +1386,23 @@ declare module "littlejs.esm" {
|
|
|
1296
1386
|
* // play the music
|
|
1297
1387
|
* music_example.play();
|
|
1298
1388
|
*/
|
|
1299
|
-
export class Music {
|
|
1389
|
+
export class Music extends Sound {
|
|
1300
1390
|
/** Create a music object and cache the zzfx music samples for later use
|
|
1301
1391
|
* @param {Array} zzfxMusic - Array of zzfx music parameters
|
|
1302
1392
|
*/
|
|
1303
1393
|
constructor(zzfxMusic: any[]);
|
|
1304
|
-
|
|
1394
|
+
sampleChannels: any[];
|
|
1305
1395
|
/** Play the music
|
|
1306
1396
|
* @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
|
|
1397
|
+
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1398
|
+
* @return {AudioBufferSourceNode} - The audio source node
|
|
1309
1399
|
*/
|
|
1310
1400
|
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
1401
|
}
|
|
1319
|
-
/** Play an mp3 or wav audio from a local file or url
|
|
1402
|
+
/** Play an mp3, ogg, or wav audio from a local file or url
|
|
1320
1403
|
* @param {String} url - Location of sound file to play
|
|
1321
1404
|
* @param {Number} [volume=1] - How much to scale volume by
|
|
1322
|
-
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1405
|
+
* @param {Boolean} [loop=1] - True if the music should loop
|
|
1323
1406
|
* @return {HTMLAudioElement} - The audio element for this sound
|
|
1324
1407
|
* @memberof Audio */
|
|
1325
1408
|
export function playAudioFile(url: string, volume?: number, loop?: boolean): HTMLAudioElement;
|
|
@@ -1350,9 +1433,10 @@ declare module "littlejs.esm" {
|
|
|
1350
1433
|
* @param {Number} [rate=1] - The playback rate to use
|
|
1351
1434
|
* @param {Number} [pan=0] - How much to apply stereo panning
|
|
1352
1435
|
* @param {Boolean} [loop=0] - True if the sound should loop when it reaches the end
|
|
1436
|
+
* @param {Number} [sampleRate=44100] - Sample rate for the sound
|
|
1353
1437
|
* @return {AudioBufferSourceNode} - The audio node of the sound played
|
|
1354
1438
|
* @memberof Audio */
|
|
1355
|
-
export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean): AudioBufferSourceNode;
|
|
1439
|
+
export function playSamples(sampleChannels: any[], volume?: number, rate?: number, pan?: number, loop?: boolean, sampleRate?: number): AudioBufferSourceNode;
|
|
1356
1440
|
/** Generate and play a ZzFX sound
|
|
1357
1441
|
*
|
|
1358
1442
|
* <a href=https://killedbyapixel.github.io/ZzFX/>Create sounds using the ZzFX Sound Designer.</a>
|
|
@@ -1360,6 +1444,17 @@ declare module "littlejs.esm" {
|
|
|
1360
1444
|
* @return {AudioBufferSourceNode} - The audio node of the sound played
|
|
1361
1445
|
* @memberof Audio */
|
|
1362
1446
|
export function zzfx(...zzfxSound: any[]): AudioBufferSourceNode;
|
|
1447
|
+
/**
|
|
1448
|
+
* LittleJS Tile Layer System
|
|
1449
|
+
* - Caches arrays of tiles to off screen canvas for fast rendering
|
|
1450
|
+
* - Unlimted numbers of layers, allocates canvases as needed
|
|
1451
|
+
* - Interfaces with EngineObject for collision
|
|
1452
|
+
* - Collision layer is separate from visible layers
|
|
1453
|
+
* - It is recommended to have a visible layer that matches the collision
|
|
1454
|
+
* - Tile layers can be drawn to using their context with canvas2d
|
|
1455
|
+
* - Drawn directly to the main canvas without using WebGL
|
|
1456
|
+
* @namespace TileCollision
|
|
1457
|
+
*/
|
|
1363
1458
|
/** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
|
|
1364
1459
|
* @type {Array}
|
|
1365
1460
|
* @memberof TileCollision */
|
|
@@ -1499,6 +1594,9 @@ declare module "littlejs.esm" {
|
|
|
1499
1594
|
* @param {Number} [angle=0] */
|
|
1500
1595
|
drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number): void;
|
|
1501
1596
|
}
|
|
1597
|
+
/**
|
|
1598
|
+
* LittleJS Particle System
|
|
1599
|
+
*/
|
|
1502
1600
|
/**
|
|
1503
1601
|
* Particle Emitter - Spawns particles with the given settings
|
|
1504
1602
|
* @extends EngineObject
|
|
@@ -1609,6 +1707,13 @@ declare module "littlejs.esm" {
|
|
|
1609
1707
|
*/
|
|
1610
1708
|
constructor(pos: any, tileIndex?: number, tileSize?: Vector2, angle?: number);
|
|
1611
1709
|
}
|
|
1710
|
+
/**
|
|
1711
|
+
* LittleJS Medal System
|
|
1712
|
+
* - Tracks and displays medals
|
|
1713
|
+
* - Saves medals to local storage
|
|
1714
|
+
* - Newgrounds integration
|
|
1715
|
+
* @namespace Medals
|
|
1716
|
+
*/
|
|
1612
1717
|
/** List of all medals
|
|
1613
1718
|
* @type {Array}
|
|
1614
1719
|
* @memberof Medals */
|
|
@@ -1717,6 +1822,16 @@ declare module "littlejs.esm" {
|
|
|
1717
1822
|
call(component: string, parameters?: any, async?: boolean): any;
|
|
1718
1823
|
CryptoJS(): any;
|
|
1719
1824
|
}
|
|
1825
|
+
/**
|
|
1826
|
+
* LittleJS WebGL Interface
|
|
1827
|
+
* - All webgl used by the engine is wrapped up here
|
|
1828
|
+
* - For normal stuff you won't need to see or call anything in this file
|
|
1829
|
+
* - For advanced stuff there are helper functions to create shaders, textures, etc
|
|
1830
|
+
* - Can be disabled with glEnable to revert to 2D canvas rendering
|
|
1831
|
+
* - Batches sprite rendering on GPU for incredibly fast performance
|
|
1832
|
+
* - Sprite transform math is done in the shader where possible
|
|
1833
|
+
* @namespace WebGL
|
|
1834
|
+
*/
|
|
1720
1835
|
/** The WebGL canvas which appears above the main canvas and below the overlay canvas
|
|
1721
1836
|
* @type {HTMLCanvasElement}
|
|
1722
1837
|
* @memberof WebGL */
|
|
@@ -1756,6 +1871,25 @@ declare module "littlejs.esm" {
|
|
|
1756
1871
|
* @param {Boolean} includeOverlay
|
|
1757
1872
|
* @memberof WebGL */
|
|
1758
1873
|
export function glInitPostProcess(shaderCode: string, includeOverlay: boolean): void;
|
|
1874
|
+
/**
|
|
1875
|
+
* LittleJS - The Tiny JavaScript Game Engine That Can!
|
|
1876
|
+
* MIT License - Copyright 2021 Frank Force
|
|
1877
|
+
*
|
|
1878
|
+
* Engine Features
|
|
1879
|
+
* - Object oriented system with base class engine object
|
|
1880
|
+
* - Base class object handles update, physics, collision, rendering, etc
|
|
1881
|
+
* - Engine helper classes and functions like Vector2, Color, and Timer
|
|
1882
|
+
* - Super fast rendering system for tile sheets
|
|
1883
|
+
* - Sound effects audio with zzfx and music with zzfxm
|
|
1884
|
+
* - Input processing system with gamepad and touchscreen support
|
|
1885
|
+
* - Tile layer rendering and collision system
|
|
1886
|
+
* - Particle effect system
|
|
1887
|
+
* - Medal system tracks and displays achievements
|
|
1888
|
+
* - Debug tools and debug rendering system
|
|
1889
|
+
* - Post processing effects
|
|
1890
|
+
* - Call engineInit() to start it up!
|
|
1891
|
+
* @namespace Engine
|
|
1892
|
+
*/
|
|
1759
1893
|
/** Name of engine
|
|
1760
1894
|
* @type {String}
|
|
1761
1895
|
* @default
|