littlejsengine 1.14.2 â 1.14.5
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 +3 -3
- package/dist/littlejs.d.ts +59 -19
- package/dist/littlejs.esm.js +239 -90
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +233 -90
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +224 -81
- package/examples/box2d/game.js +4 -4
- package/examples/breakoutTutorial/README.md +1 -1
- package/examples/breakoutTutorial/game.js +1 -1
- package/examples/electron/build.js +1 -1
- package/examples/empty/game.js +1 -1
- package/examples/htmlMenu/index.html +7 -7
- package/examples/index.html +3 -3
- package/examples/platformer/gameEffects.js +1 -7
- package/examples/shorts/music.js +3 -3
- package/examples/shorts/shapes.js +12 -10
- package/examples/stress/index.html +14 -12
- package/examples/typescript/build.js +1 -1
- package/package.json +1 -1
- package/plugins/box2d.js +3 -3
- package/reference.md +9 -7
- package/src/engine.js +7 -3
- package/src/engineBuild.js +2 -2
- package/src/engineDebug.js +9 -9
- package/src/engineDraw.js +140 -18
- package/src/engineExport.js +6 -0
- package/src/engineObject.js +3 -3
- package/src/engineTileLayer.js +0 -1
- package/src/engineUtilities.js +4 -4
- package/src/engineWebGL.js +66 -48
- package/copyToGithub.bat +0 -28
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# LittleJS - The Tiny Fast JavaScript Game Engine
|
|
2
2
|
|
|
3
|
-
<div align=
|
|
3
|
+
<div align='center'>
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
@@ -22,7 +22,7 @@ The code is clean and well documented with some fun examples to get you started
|
|
|
22
22
|
|
|
23
23
|
*The Second Annual LittleJS Game Jam will take place From Oct 3 to Nov 3! Unleash your creativity and develop amazing games using the LittleJS game engine. đšī¸đŽ [Sign up today and get more info about the jam on itch.io!](https://itch.io/jam/littlejs-game-jam-2025)*
|
|
24
24
|
|
|
25
|
-
<div align=
|
|
25
|
+
<div align='center'>
|
|
26
26
|
|
|
27
27
|
## [Demos](https://killedbyapixel.github.io/LittleJS/examples) | [Docs](https://killedbyapixel.github.io/LittleJS/docs) | [Trailer](https://youtu.be/chuBzGjv7Ms) | [Discord](https://discord.gg/zb7hcGkyZe) | [Tutorial](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/breakoutTutorial/README.md) | [FAQ](https://github.com/KilledByAPixel/LittleJS/blob/main/FAQ.md)
|
|
28
28
|
|
|
@@ -80,7 +80,7 @@ LittleJS is a small but powerful game engine with many features and no dependenc
|
|
|
80
80
|
|
|
81
81
|
To get started download the latest LittleJS package from GitHub or install via npm: ```npm install littlejsengine```
|
|
82
82
|
|
|
83
|
-
*You need to run a local web server to run LittleJS games during development!* You may see a console error like
|
|
83
|
+
*You need to run a local web server to run LittleJS games during development!* 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.
|
|
84
84
|
|
|
85
85
|
- [Watch this GitNation talk](https://youtu.be/_dXKU0WgAj8?si=ZDXLYAFDWp54hrGT) to hear more about LittleJS works and get some tips on how to use it.
|
|
86
86
|
- Learn how to make a simple game from scratch with [The Breakout Tutorial.](https://github.com/KilledByAPixel/LittleJS/tree/main/examples/breakoutTutorial)
|
package/dist/littlejs.d.ts
CHANGED
|
@@ -168,12 +168,12 @@ declare module "littlejsengine" {
|
|
|
168
168
|
export function debugPoly(pos: Vector2, points: Array<Vector2>, color?: string, time?: number, angle?: number, fill?: boolean): void;
|
|
169
169
|
/** Draw a debug circle in world space
|
|
170
170
|
* @param {Vector2} pos
|
|
171
|
-
* @param {number} [
|
|
171
|
+
* @param {number} [size] - diameter
|
|
172
172
|
* @param {string} [color]
|
|
173
173
|
* @param {number} [time]
|
|
174
174
|
* @param {boolean} [fill]
|
|
175
175
|
* @memberof Debug */
|
|
176
|
-
export function debugCircle(pos: Vector2,
|
|
176
|
+
export function debugCircle(pos: Vector2, size?: number, color?: string, time?: number, fill?: boolean): void;
|
|
177
177
|
/** Draw a debug point in world space
|
|
178
178
|
* @param {Vector2} pos
|
|
179
179
|
* @param {string} [color]
|
|
@@ -185,10 +185,10 @@ declare module "littlejsengine" {
|
|
|
185
185
|
* @param {Vector2} posA
|
|
186
186
|
* @param {Vector2} posB
|
|
187
187
|
* @param {string} [color]
|
|
188
|
-
* @param {number} [
|
|
188
|
+
* @param {number} [width]
|
|
189
189
|
* @param {number} [time]
|
|
190
190
|
* @memberof Debug */
|
|
191
|
-
export function debugLine(posA: Vector2, posB: Vector2, color?: string,
|
|
191
|
+
export function debugLine(posA: Vector2, posB: Vector2, color?: string, width?: number, time?: number): void;
|
|
192
192
|
/** Draw a debug combined axis aligned bounding box in world space
|
|
193
193
|
* @param {Vector2} posA
|
|
194
194
|
* @param {Vector2} sizeA
|
|
@@ -1216,6 +1216,10 @@ declare module "littlejsengine" {
|
|
|
1216
1216
|
* @type {Array<TextureInfo>}
|
|
1217
1217
|
* @memberof Draw */
|
|
1218
1218
|
export let textureInfos: Array<TextureInfo>;
|
|
1219
|
+
/** Keeps track of how many draw calls there were each frame for debugging
|
|
1220
|
+
* @type {number}
|
|
1221
|
+
* @memberof Draw */
|
|
1222
|
+
export let drawCount: number;
|
|
1219
1223
|
/**
|
|
1220
1224
|
* Create a tile info object using a grid based system
|
|
1221
1225
|
* - This can take vecs or floats for easier use and conversion
|
|
@@ -1318,6 +1322,14 @@ declare module "littlejsengine" {
|
|
|
1318
1322
|
* @type {CanvasRenderingContext2D}
|
|
1319
1323
|
* @memberof Draw */
|
|
1320
1324
|
export let mainContext: CanvasRenderingContext2D;
|
|
1325
|
+
/** The default canvas to use for drawing, usually mainCanvas
|
|
1326
|
+
* @type {HTMLCanvasElement|OffscreenCanvas}
|
|
1327
|
+
* @memberof Draw */
|
|
1328
|
+
export let drawCanvas: HTMLCanvasElement | OffscreenCanvas;
|
|
1329
|
+
/** The default 2d context to use for drawing, usually mainContext
|
|
1330
|
+
* @type {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D}
|
|
1331
|
+
* @memberof Draw */
|
|
1332
|
+
export let drawContext: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
1321
1333
|
/** A canvas that appears on top of everything the same size as mainCanvas
|
|
1322
1334
|
* @type {HTMLCanvasElement}
|
|
1323
1335
|
* @memberof Draw */
|
|
@@ -1363,10 +1375,33 @@ declare module "littlejsengine" {
|
|
|
1363
1375
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1364
1376
|
* @memberof Draw */
|
|
1365
1377
|
export function drawRect(pos: Vector2, size?: Vector2, color?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1378
|
+
/** Draw a rect centered on pos with a gradient from top to bottom
|
|
1379
|
+
* @param {Vector2} pos
|
|
1380
|
+
* @param {Vector2} [size=(1,1)]
|
|
1381
|
+
* @param {Color} [colorTop=(1,1,1,1)]
|
|
1382
|
+
* @param {Color} [colorBottom=(0,0,0,1)]
|
|
1383
|
+
* @param {number} [angle]
|
|
1384
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
1385
|
+
* @param {boolean} [screenSpace]
|
|
1386
|
+
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1387
|
+
* @memberof Draw */
|
|
1388
|
+
export function drawRectGradient(pos: Vector2, size?: Vector2, colorTop?: Color, colorBottom?: Color, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1389
|
+
/** Draw connected lines between a series of points
|
|
1390
|
+
* @param {Array<Vector2>} points
|
|
1391
|
+
* @param {number} [width]
|
|
1392
|
+
* @param {Color} [color=(1,1,1,1)]
|
|
1393
|
+
* @param {boolean} [wrap] - Should the last point connect to the first?
|
|
1394
|
+
* @param {Vector2} [pos=(0,0)] - Offset to apply
|
|
1395
|
+
* @param {number} [angle] - Angle to rotate by
|
|
1396
|
+
* @param {boolean} [useWebGL=glEnable]
|
|
1397
|
+
* @param {boolean} [screenSpace]
|
|
1398
|
+
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1399
|
+
* @memberof Draw */
|
|
1400
|
+
export function drawLineList(points: Array<Vector2>, width?: number, color?: Color, wrap?: boolean, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1366
1401
|
/** Draw colored line between two points
|
|
1367
1402
|
* @param {Vector2} posA
|
|
1368
1403
|
* @param {Vector2} posB
|
|
1369
|
-
* @param {number} [
|
|
1404
|
+
* @param {number} [width]
|
|
1370
1405
|
* @param {Color} [color=(1,1,1,1)]
|
|
1371
1406
|
* @param {Vector2} [pos=(0,0)] - Offset to apply
|
|
1372
1407
|
* @param {number} [angle] - Angle to rotate by
|
|
@@ -1374,7 +1409,7 @@ declare module "littlejsengine" {
|
|
|
1374
1409
|
* @param {boolean} [screenSpace]
|
|
1375
1410
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1376
1411
|
* @memberof Draw */
|
|
1377
|
-
export function drawLine(posA: Vector2, posB: Vector2,
|
|
1412
|
+
export function drawLine(posA: Vector2, posB: Vector2, width?: number, color?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1378
1413
|
/** Draw colored polygon using passed in points
|
|
1379
1414
|
* @param {Array<Vector2>} points - Array of Vector2 points
|
|
1380
1415
|
* @param {Color} [color=(1,1,1,1)]
|
|
@@ -1389,7 +1424,7 @@ declare module "littlejsengine" {
|
|
|
1389
1424
|
export function drawPoly(points: Array<Vector2>, color?: Color, lineWidth?: number, lineColor?: Color, pos?: Vector2, angle?: number, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1390
1425
|
/** Draw colored ellipse using passed in point
|
|
1391
1426
|
* @param {Vector2} pos
|
|
1392
|
-
* @param {Vector2} [size=(1,1)]
|
|
1427
|
+
* @param {Vector2} [size=(1,1)] - Width and height diameter
|
|
1393
1428
|
* @param {Color} [color=(1,1,1,1)]
|
|
1394
1429
|
* @param {number} [angle]
|
|
1395
1430
|
* @param {number} [lineWidth]
|
|
@@ -1401,7 +1436,7 @@ declare module "littlejsengine" {
|
|
|
1401
1436
|
export function drawEllipse(pos: Vector2, size?: Vector2, color?: Color, angle?: number, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1402
1437
|
/** Draw colored circle using passed in point
|
|
1403
1438
|
* @param {Vector2} pos
|
|
1404
|
-
* @param {number} [
|
|
1439
|
+
* @param {number} [size=1] - Diameter
|
|
1405
1440
|
* @param {Color} [color=(1,1,1,1)]
|
|
1406
1441
|
* @param {number} [lineWidth=0]
|
|
1407
1442
|
* @param {Color} [lineColor=(0,0,0,1)]
|
|
@@ -1409,7 +1444,7 @@ declare module "littlejsengine" {
|
|
|
1409
1444
|
* @param {boolean} [screenSpace]
|
|
1410
1445
|
* @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
|
|
1411
1446
|
* @memberof Draw */
|
|
1412
|
-
export function drawCircle(pos: Vector2,
|
|
1447
|
+
export function drawCircle(pos: Vector2, size?: number, color?: Color, lineWidth?: number, lineColor?: Color, useWebGL?: boolean, screenSpace?: boolean, context?: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D): void;
|
|
1413
1448
|
/** Draw directly to a 2d canvas context in world space
|
|
1414
1449
|
* @param {Vector2} pos
|
|
1415
1450
|
* @param {Vector2} size
|
|
@@ -1481,7 +1516,7 @@ declare module "littlejsengine" {
|
|
|
1481
1516
|
* const font = new FontImage;
|
|
1482
1517
|
*
|
|
1483
1518
|
* // draw text
|
|
1484
|
-
* font.drawTextScreen(
|
|
1519
|
+
* font.drawTextScreen('LittleJS\nHello World!', vec2(200, 50));
|
|
1485
1520
|
*/
|
|
1486
1521
|
export class FontImage {
|
|
1487
1522
|
/** Create an image font
|
|
@@ -1614,7 +1649,7 @@ declare module "littlejsengine" {
|
|
|
1614
1649
|
* @memberof WebGL */
|
|
1615
1650
|
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;
|
|
1616
1651
|
/** Transform and add a polygon to the gl draw list
|
|
1617
|
-
* @param {Array} points - Array of Vector2 points
|
|
1652
|
+
* @param {Array<Vector2>} points - Array of Vector2 points
|
|
1618
1653
|
* @param {number} rgba - Color of the polygon as a 32-bit integer
|
|
1619
1654
|
* @param {number} x
|
|
1620
1655
|
* @param {number} y
|
|
@@ -1623,9 +1658,9 @@ declare module "littlejsengine" {
|
|
|
1623
1658
|
* @param {number} angle
|
|
1624
1659
|
* @param {boolean} [tristrip] - should tristrip algorithm be used
|
|
1625
1660
|
* @memberof WebGL */
|
|
1626
|
-
export function glDrawPointsTransform(points:
|
|
1661
|
+
export function glDrawPointsTransform(points: Array<Vector2>, rgba: number, x: number, y: number, sx: number, sy: number, angle: number, tristrip?: boolean): void;
|
|
1627
1662
|
/** Transform and add a polygon to the gl draw list
|
|
1628
|
-
* @param {Array} points - Array of Vector2 points
|
|
1663
|
+
* @param {Array<Vector2>} points - Array of Vector2 points
|
|
1629
1664
|
* @param {number} rgba - Color of the polygon as a 32-bit integer
|
|
1630
1665
|
* @param {number} lineWidth - Width of the outline
|
|
1631
1666
|
* @param {number} x
|
|
@@ -1633,13 +1668,19 @@ declare module "littlejsengine" {
|
|
|
1633
1668
|
* @param {number} sx
|
|
1634
1669
|
* @param {number} sy
|
|
1635
1670
|
* @param {number} angle
|
|
1671
|
+
* @param {boolean} [wrap] - Should the outline connect the first and last points
|
|
1636
1672
|
* @memberof WebGL */
|
|
1637
|
-
export function glDrawOutlineTransform(points:
|
|
1638
|
-
/** Add a
|
|
1639
|
-
* @param {Array} points - Array of Vector2 points in
|
|
1640
|
-
* @param {number} rgba - Color
|
|
1673
|
+
export function glDrawOutlineTransform(points: Array<Vector2>, rgba: number, lineWidth: number, x: number, y: number, sx: number, sy: number, angle: number, wrap?: boolean): void;
|
|
1674
|
+
/** Add a list of points to the gl draw list
|
|
1675
|
+
* @param {Array<Vector2>} points - Array of Vector2 points in tri strip order
|
|
1676
|
+
* @param {number} rgba - Color as a 32-bit integer
|
|
1677
|
+
* @memberof WebGL */
|
|
1678
|
+
export function glDrawPoints(points: Array<Vector2>, rgba: number): void;
|
|
1679
|
+
/** Add a list of colored points to the gl draw list
|
|
1680
|
+
* @param {Array<Vector2>} points - Array of Vector2 points in tri strip order
|
|
1681
|
+
* @param {Array<number>} pointColors - Array of 32-bit integer colors
|
|
1641
1682
|
* @memberof WebGL */
|
|
1642
|
-
export function
|
|
1683
|
+
export function glDrawColoredPoints(points: Array<Vector2>, pointColors: Array<number>): void;
|
|
1643
1684
|
/** Should WebGL be setup with anti-aliasing? must be set before calling engineInit
|
|
1644
1685
|
* @type {boolean}
|
|
1645
1686
|
* @memberof WebGL */
|
|
@@ -2209,7 +2250,6 @@ declare module "littlejsengine" {
|
|
|
2209
2250
|
* - Caches arrays of tiles to off screen canvas for fast rendering
|
|
2210
2251
|
* - Unlimited numbers of layers, allocates canvases as needed
|
|
2211
2252
|
* - Tile layers can be drawn to using their context with canvas2d
|
|
2212
|
-
* - Drawn directly to the main canvas without using WebGL
|
|
2213
2253
|
* - Tile layers can also have collision with EngineObjects
|
|
2214
2254
|
* @namespace TileCollision
|
|
2215
2255
|
*/
|