littlejsengine 1.9.9 → 1.10.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/README.md +6 -0
- package/dist/littlejs.d.ts +107 -14
- package/dist/littlejs.esm.js +250 -102
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +226 -98
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +208 -95
- package/examples/box2d/game.js +29 -10
- package/examples/box2d/gameObjects.js +485 -0
- package/examples/box2d/index.html +7 -5
- package/examples/box2d/scenes.js +28 -247
- package/examples/box2d/tiles.png +0 -0
- package/examples/breakout/game.js +1 -1
- package/examples/breakout/index.html +5 -4
- package/examples/breakoutTutorial/index.html +4 -3
- package/examples/electron/game.js +1 -1
- package/examples/electron/index.html +4 -3
- package/examples/empty/game.js +1 -1
- package/examples/empty/index.html +2 -1
- package/examples/htmlMenu/game.js +67 -0
- package/examples/htmlMenu/index.html +56 -0
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +33 -0
- package/examples/js13k/game.js +1 -1
- package/examples/js13k/index.html +17 -14
- package/examples/module/game.js +1 -1
- package/examples/module/index.html +3 -2
- package/examples/particles/index.html +4 -3
- package/examples/platformer/game.js +1 -1
- package/examples/platformer/gameCharacter.js +1 -0
- package/examples/platformer/gameEffects.js +0 -2
- package/examples/platformer/gameLevel.js +2 -2
- package/examples/platformer/gameObjects.js +1 -2
- package/examples/platformer/index.html +10 -9
- package/examples/puzzle/game.js +1 -1
- package/examples/puzzle/index.html +4 -3
- package/examples/starter/game.js +5 -5
- package/examples/starter/index.html +15 -14
- package/examples/stress/index.html +3 -2
- package/examples/typescript/game.js +1 -1
- package/examples/typescript/index.html +3 -2
- package/examples/uiSystem/game.js +134 -0
- package/examples/uiSystem/index.html +25 -0
- package/examples/uiSystem/tiles.png +0 -0
- package/jsconfig.json +11 -0
- package/package.json +1 -1
- package/plugins/box2d.js +116 -42
- package/plugins/postProcess.js +6 -7
- package/plugins/uiSystem.js +243 -0
- package/src/engine.js +48 -20
- package/src/engineAudio.js +22 -25
- package/src/engineDebug.js +18 -3
- package/src/engineDraw.js +101 -27
- package/src/engineExport.js +23 -4
- package/src/engineInput.js +9 -5
- package/src/engineObject.js +15 -12
- package/src/engineSettings.js +1 -1
- package/src/engineUtilities.js +1 -1
- package/src/engineWebGL.js +11 -4
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ LittleJS is a small but powerful game engine with many features and no dependenc
|
|
|
56
56
|
|
|
57
57
|
- Robust arcade physics system with collision handling
|
|
58
58
|
- Very fast collision and raycasting for tile maps
|
|
59
|
+
- Full Box2d support using [super fast wasm build of box2d.js](https://github.com/kripken/box2d.js/)
|
|
59
60
|
|
|
60
61
|
### 🚀 Flexibility
|
|
61
62
|
|
|
@@ -78,6 +79,10 @@ LittleJS is a small but powerful game engine with many features and no dependenc
|
|
|
78
79
|
|
|
79
80
|
To get started download the latest LittleJS package from GitHub or install via npm: ```npm install littlejsengine```
|
|
80
81
|
|
|
82
|
+
*You will need to run a local web server to run LittleJS games!*
|
|
83
|
+
|
|
84
|
+
This is because web browsers just have protection from loading local files. You may see a console error like "The image element contains cross-origin data." Don't panic, it's easy to fix! If you are using [Visual Studio Code](https://code.visualstudio.com/) there is a [Live Preview Extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.live-server) that will handle this for you automatically. Another option is to setup a simple local web server like [http-server](https://www.npmjs.com/package/http-server) via npm.
|
|
85
|
+
|
|
81
86
|
Learn how to make a simple game from scratch with [The Breakout Tutorial.](https://github.com/KilledByAPixel/LittleJS/tree/main/examples/breakoutTutorial)
|
|
82
87
|
|
|
83
88
|
[LittleJS Engine Quick Reference Sheet](https://github.com/KilledByAPixel/LittleJS/blob/main/reference.md) - This cheat sheet can help you get started.
|
|
@@ -209,6 +214,7 @@ Here are a few of the amazing games people made using LittleJS...
|
|
|
209
214
|
- [Data Warrior: 13kb limit](https://js13kgames.com/2024/games/data-warrior-13kb-limit) - Vampire Survivors-like game by [rndD](https://github.com/rndD)
|
|
210
215
|
- [The Way of the Dodo](https://js13kgames.com/2024/games/the-way-of-the-dodo) - Single button platformer by [repsej](https://github.com/repsej)
|
|
211
216
|
- [Wendol Village](https://js13kgames.com/2024/games/wendol-village) - Warcraft-like RTS game by [sanojian](https://github.com/sanojian)
|
|
217
|
+
- [Unblock](https://js13kgames.com/games/unblock) - Retro style space shooter by [Isaac Benitez](https://github.com/isacben)
|
|
212
218
|
|
|
213
219
|

|
|
214
220
|
|
package/dist/littlejs.d.ts
CHANGED
|
@@ -70,8 +70,9 @@ declare module "littlejsengine" {
|
|
|
70
70
|
* @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
|
|
71
71
|
* @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
|
|
72
72
|
* @param {Array} [imageSources=['tiles.png']] - Image to load
|
|
73
|
+
* @param {HTMLElement} [rootElement] - Root element to attach to, the document body by default
|
|
73
74
|
* @memberof Engine */
|
|
74
|
-
export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: any[]): void;
|
|
75
|
+
export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: any[], rootElement?: HTMLElement): void;
|
|
75
76
|
/** Update each engine object, remove destroyed objects, and update time
|
|
76
77
|
* @memberof Engine */
|
|
77
78
|
export function engineObjectsUpdate(): void;
|
|
@@ -85,6 +86,13 @@ declare module "littlejsengine" {
|
|
|
85
86
|
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
86
87
|
* @memberof Engine */
|
|
87
88
|
export function engineObjectsCallback(pos?: Vector2, size?: number | Vector2, callbackFunction?: Function, objects?: any[]): void;
|
|
89
|
+
/** Return a list of objects intersecting a ray
|
|
90
|
+
* @param {Vector2} start
|
|
91
|
+
* @param {Vector2} end
|
|
92
|
+
* @param {Array} [objects=engineObjects] - List of objects to check
|
|
93
|
+
* @return {Array} - List of objects hit
|
|
94
|
+
* @memberof Engine */
|
|
95
|
+
export function engineObjectsRaycast(start: Vector2, end: Vector2, objects?: any[]): any[];
|
|
88
96
|
/** Add a new update function for a plugin
|
|
89
97
|
* @param {Function} [updateFunction]
|
|
90
98
|
* @param {Function} [renderFunction]
|
|
@@ -664,6 +672,14 @@ declare module "littlejsengine" {
|
|
|
664
672
|
* @return {Boolean} - True if overlapping
|
|
665
673
|
* @memberof Utilities */
|
|
666
674
|
export function isOverlapping(posA: Vector2, sizeA: Vector2, posB: Vector2, sizeB?: Vector2): boolean;
|
|
675
|
+
/** Returns true if a line segment is intersecting an axis aligned box
|
|
676
|
+
* @param {Vector2} start - Start of raycast
|
|
677
|
+
* @param {Vector2} end - End of raycast
|
|
678
|
+
* @param {Vector2} pos - Center of box
|
|
679
|
+
* @param {Vector2} size - Size of box
|
|
680
|
+
* @return {Boolean} - True if intersecting
|
|
681
|
+
* @memberof Utilities */
|
|
682
|
+
export function isIntersecting(start: Vector2, end: Vector2, pos: Vector2, size: Vector2): boolean;
|
|
667
683
|
/** Returns an oscillating wave between 0 and amplitude with frequency of 1 Hz by default
|
|
668
684
|
* @param {Number} [frequency] - Frequency of the wave in Hz
|
|
669
685
|
* @param {Number} [amplitude] - Amplitude (max height) of the wave
|
|
@@ -1025,17 +1041,69 @@ declare module "littlejsengine" {
|
|
|
1025
1041
|
* @memberof Utilities
|
|
1026
1042
|
*/
|
|
1027
1043
|
export function hsl(h?: number, s?: number, l?: number, a?: number): Color;
|
|
1044
|
+
/**
|
|
1045
|
+
* Check if object is a valid Color
|
|
1046
|
+
* @param {any} c
|
|
1047
|
+
* @return {Boolean}
|
|
1048
|
+
* @memberof Utilities
|
|
1049
|
+
*/
|
|
1050
|
+
export function isColor(c: any): boolean;
|
|
1051
|
+
/** Color - White
|
|
1052
|
+
* @type {Color}
|
|
1053
|
+
* @memberof Utilities */
|
|
1054
|
+
export const WHITE: Color;
|
|
1055
|
+
/** Color - Black
|
|
1056
|
+
* @type {Color}
|
|
1057
|
+
* @memberof Utilities */
|
|
1058
|
+
export const BLACK: Color;
|
|
1059
|
+
/** Color - Gray
|
|
1060
|
+
* @type {Color}
|
|
1061
|
+
* @memberof Utilities */
|
|
1062
|
+
export const GRAY: Color;
|
|
1063
|
+
/** Color - Red
|
|
1064
|
+
* @type {Color}
|
|
1065
|
+
* @memberof Utilities */
|
|
1066
|
+
export const RED: Color;
|
|
1067
|
+
/** Color - Orange
|
|
1068
|
+
* @type {Color}
|
|
1069
|
+
* @memberof Utilities */
|
|
1070
|
+
export const ORANGE: Color;
|
|
1071
|
+
/** Color - Yellow
|
|
1072
|
+
* @type {Color}
|
|
1073
|
+
* @memberof Utilities */
|
|
1074
|
+
export const YELLOW: Color;
|
|
1075
|
+
/** Color - Green
|
|
1076
|
+
* @type {Color}
|
|
1077
|
+
* @memberof Utilities */
|
|
1078
|
+
export const GREEN: Color;
|
|
1079
|
+
/** Color - Cyan
|
|
1080
|
+
* @type {Color}
|
|
1081
|
+
* @memberof Utilities */
|
|
1082
|
+
export const CYAN: Color;
|
|
1083
|
+
/** Color - Blue
|
|
1084
|
+
* @type {Color}
|
|
1085
|
+
* @memberof Utilities */
|
|
1086
|
+
export const BLUE: Color;
|
|
1087
|
+
/** Color - Purple
|
|
1088
|
+
* @type {Color}
|
|
1089
|
+
* @memberof Utilities */
|
|
1090
|
+
export const PURPLE: Color;
|
|
1091
|
+
/** Color - Magenta
|
|
1092
|
+
* @type {Color}
|
|
1093
|
+
* @memberof Utilities */
|
|
1094
|
+
export const MAGENTA: Color;
|
|
1028
1095
|
/** Array containing texture info for batch rendering system
|
|
1029
1096
|
* @type {Array}
|
|
1030
1097
|
* @memberof Draw */
|
|
1031
1098
|
export let textureInfos: any[];
|
|
1032
1099
|
/**
|
|
1033
|
-
* Create a tile info object
|
|
1100
|
+
* Create a tile info object using a grid based system
|
|
1034
1101
|
* - This can take vecs or floats for easier use and conversion
|
|
1035
1102
|
* - If an index is passed in, the tile size and index will determine the position
|
|
1036
|
-
* @param {(Number|Vector2)} [pos=
|
|
1103
|
+
* @param {(Number|Vector2)} [pos=0] - Index of tile in sheet
|
|
1037
1104
|
* @param {(Number|Vector2)} [size=tileSizeDefault] - Size of tile in pixels
|
|
1038
1105
|
* @param {Number} [textureIndex] - Texture index to use
|
|
1106
|
+
* @param {Number} [padding] - How many pixels padding around tiles
|
|
1039
1107
|
* @return {TileInfo}
|
|
1040
1108
|
* @example
|
|
1041
1109
|
* tile(2) // a tile at index 2 using the default tile size of 16
|
|
@@ -1044,7 +1112,7 @@ declare module "littlejsengine" {
|
|
|
1044
1112
|
* tile(vec2(4,8), vec2(30,10)) // a tile at pixel location (4,8) with a size of (30,10)
|
|
1045
1113
|
* @memberof Draw
|
|
1046
1114
|
*/
|
|
1047
|
-
export function tile(pos?: (number | Vector2), size?: (number | Vector2), textureIndex?: number): TileInfo;
|
|
1115
|
+
export function tile(pos?: (number | Vector2), size?: (number | Vector2), textureIndex?: number, padding?: number): TileInfo;
|
|
1048
1116
|
/**
|
|
1049
1117
|
* Tile Info - Stores info about how to draw a tile
|
|
1050
1118
|
*/
|
|
@@ -1053,14 +1121,17 @@ declare module "littlejsengine" {
|
|
|
1053
1121
|
* @param {Vector2} [pos=(0,0)] - Top left corner of tile in pixels
|
|
1054
1122
|
* @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
|
|
1055
1123
|
* @param {Number} [textureIndex] - Texture index to use
|
|
1124
|
+
* @param {Number} [padding] - How many pixels padding around tiles
|
|
1056
1125
|
*/
|
|
1057
|
-
constructor(pos?: Vector2, size?: Vector2, textureIndex?: number);
|
|
1126
|
+
constructor(pos?: Vector2, size?: Vector2, textureIndex?: number, padding?: number);
|
|
1058
1127
|
/** @property {Vector2} - Top left corner of tile in pixels */
|
|
1059
1128
|
pos: Vector2;
|
|
1060
1129
|
/** @property {Vector2} - Size of tile in pixels */
|
|
1061
1130
|
size: Vector2;
|
|
1062
1131
|
/** @property {Number} - Texture index to use */
|
|
1063
1132
|
textureIndex: number;
|
|
1133
|
+
/** @property {Number} - How many pixels padding around tiles */
|
|
1134
|
+
padding: number;
|
|
1064
1135
|
/** Returns a copy of this tile offset by a vector
|
|
1065
1136
|
* @param {Vector2} offset - Offset to apply in pixels
|
|
1066
1137
|
* @return {TileInfo}
|
|
@@ -1089,8 +1160,6 @@ declare module "littlejsengine" {
|
|
|
1089
1160
|
size: Vector2;
|
|
1090
1161
|
/** @property {WebGLTexture} - webgl texture */
|
|
1091
1162
|
glTexture: WebGLTexture;
|
|
1092
|
-
/** @property {Vector2} - size to adjust tile to fix bleeding */
|
|
1093
|
-
fixBleedSize: Vector2;
|
|
1094
1163
|
}
|
|
1095
1164
|
/**
|
|
1096
1165
|
* LittleJS Drawing System
|
|
@@ -1203,8 +1272,9 @@ declare module "littlejsengine" {
|
|
|
1203
1272
|
* @param {CanvasTextAlign} [textAlign]
|
|
1204
1273
|
* @param {String} [font=fontDefault]
|
|
1205
1274
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
|
|
1275
|
+
* @param {Number} [maxWidth]
|
|
1206
1276
|
* @memberof Draw */
|
|
1207
|
-
export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1277
|
+
export function drawTextScreen(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, maxWidth?: number): void;
|
|
1208
1278
|
/** Draw text on overlay canvas in world space
|
|
1209
1279
|
* Automatically splits new lines into rows
|
|
1210
1280
|
* @param {String} text
|
|
@@ -1216,8 +1286,9 @@ declare module "littlejsengine" {
|
|
|
1216
1286
|
* @param {CanvasTextAlign} [textAlign='center']
|
|
1217
1287
|
* @param {String} [font=fontDefault]
|
|
1218
1288
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context=overlayContext]
|
|
1289
|
+
* @param {Number} [maxWidth]
|
|
1219
1290
|
* @memberof Draw */
|
|
1220
|
-
export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1291
|
+
export function drawText(text: string, pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, textAlign?: CanvasTextAlign, font?: string, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, maxWidth?: number): void;
|
|
1221
1292
|
export let engineFontImage: any;
|
|
1222
1293
|
/**
|
|
1223
1294
|
* Font Image Object - Draw text on a 2D canvas by using characters in an image
|
|
@@ -1288,17 +1359,17 @@ declare module "littlejsengine" {
|
|
|
1288
1359
|
* @type {WebGL2RenderingContext}
|
|
1289
1360
|
* @memberof WebGL */
|
|
1290
1361
|
export let glContext: WebGL2RenderingContext;
|
|
1291
|
-
/** Set the WebGl texture, called automatically if using multiple textures
|
|
1292
|
-
* - This may also flush the gl buffer resulting in more draw calls and worse performance
|
|
1293
|
-
* @param {WebGLTexture} texture
|
|
1294
|
-
* @memberof WebGL */
|
|
1295
|
-
export function glSetTexture(texture: WebGLTexture): void;
|
|
1296
1362
|
/** Compile WebGL shader of the given type, will throw errors if in debug mode
|
|
1297
1363
|
* @param {String} source
|
|
1298
1364
|
* @param {Number} type
|
|
1299
1365
|
* @return {WebGLShader}
|
|
1300
1366
|
* @memberof WebGL */
|
|
1301
1367
|
export function glCompileShader(source: string, type: number): WebGLShader;
|
|
1368
|
+
/** Draw any sprites still in the buffer, copy to main canvas and clear
|
|
1369
|
+
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} context
|
|
1370
|
+
* @param {Boolean} [forceDraw]
|
|
1371
|
+
* @memberof WebGL */
|
|
1372
|
+
export function glCopyToContext(context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, forceDraw?: boolean): void;
|
|
1302
1373
|
/** Create WebGL program with given shaders
|
|
1303
1374
|
* @param {String} vsSource
|
|
1304
1375
|
* @param {String} fsSource
|
|
@@ -1310,6 +1381,28 @@ declare module "littlejsengine" {
|
|
|
1310
1381
|
* @return {WebGLTexture}
|
|
1311
1382
|
* @memberof WebGL */
|
|
1312
1383
|
export function glCreateTexture(image: HTMLImageElement): WebGLTexture;
|
|
1384
|
+
/** Add a sprite to the gl draw list, used by all gl draw functions
|
|
1385
|
+
* @param {Number} x
|
|
1386
|
+
* @param {Number} y
|
|
1387
|
+
* @param {Number} sizeX
|
|
1388
|
+
* @param {Number} sizeY
|
|
1389
|
+
* @param {Number} angle
|
|
1390
|
+
* @param {Number} uv0X
|
|
1391
|
+
* @param {Number} uv0Y
|
|
1392
|
+
* @param {Number} uv1X
|
|
1393
|
+
* @param {Number} uv1Y
|
|
1394
|
+
* @param {Number} rgba
|
|
1395
|
+
* @param {Number} [rgbaAdditive=0]
|
|
1396
|
+
* @memberof WebGL */
|
|
1397
|
+
export function glDraw(x: number, y: number, sizeX: number, sizeY: number, angle: number, uv0X: number, uv0Y: number, uv1X: number, uv1Y: number, rgba: number, rgbaAdditive?: number): void;
|
|
1398
|
+
/** Draw all sprites and clear out the buffer, called automatically by the system whenever necessary
|
|
1399
|
+
* @memberof WebGL */
|
|
1400
|
+
export function glFlush(): void;
|
|
1401
|
+
/** Set the WebGl texture, called automatically if using multiple textures
|
|
1402
|
+
* - This may also flush the gl buffer resulting in more draw calls and worse performance
|
|
1403
|
+
* @param {WebGLTexture} texture
|
|
1404
|
+
* @memberof WebGL */
|
|
1405
|
+
export function glSetTexture(texture: WebGLTexture): void;
|
|
1313
1406
|
/**
|
|
1314
1407
|
* LittleJS Input System
|
|
1315
1408
|
* - Tracks keyboard down, pressed, and released
|