littlejsengine 1.14.4 → 1.14.7

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.
Files changed (42) hide show
  1. package/README.md +3 -3
  2. package/dist/littlejs.d.ts +40 -14
  3. package/dist/littlejs.esm.js +119 -59
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +115 -57
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +108 -50
  8. package/examples/box2d/game.js +1 -3
  9. package/examples/box2d/gameObjects.js +2 -2
  10. package/examples/htmlMenu/game.js +1 -1
  11. package/examples/index.html +85 -49
  12. package/examples/puzzle/game.js +1 -2
  13. package/examples/shorts/animation.js +2 -2
  14. package/examples/shorts/box2d.js +1 -0
  15. package/examples/shorts/box2dCar.js +1 -0
  16. package/examples/shorts/flappyGame.js +2 -1
  17. package/examples/shorts/helloWorld.js +2 -2
  18. package/examples/shorts/hillGlideGame.js +6 -3
  19. package/examples/shorts/maze.js +1 -0
  20. package/examples/shorts/medals.js +3 -0
  21. package/examples/shorts/music.js +6 -8
  22. package/examples/shorts/platformer.js +1 -0
  23. package/examples/shorts/shapes.js +6 -6
  24. package/examples/shorts/sound.js +1 -0
  25. package/examples/shorts/spriteAtlas.js +1 -2
  26. package/examples/shorts/tileLayer.js +1 -0
  27. package/examples/shorts/tiltedView.js +1 -1
  28. package/examples/shorts/timers.js +34 -31
  29. package/examples/shorts/topDown.js +2 -1
  30. package/examples/shorts/uiSystem.js +3 -5
  31. package/examples/stress/index.html +1 -1
  32. package/examples/uiSystem/game.js +1 -1
  33. package/package.json +1 -1
  34. package/plugins/uiSystem.js +35 -17
  35. package/reference.md +1 -1
  36. package/src/engine.js +23 -6
  37. package/src/engineDebug.js +7 -7
  38. package/src/engineDraw.js +18 -11
  39. package/src/engineExport.js +4 -2
  40. package/src/engineSettings.js +10 -0
  41. package/src/engineUtilities.js +4 -0
  42. package/src/engineWebGL.js +18 -16
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LittleJS - The Tiny Fast JavaScript Game Engine
2
2
 
3
- <div align=center>
3
+ <div align='center'>
4
4
 
5
5
  ![LittleJS Screenshot](examples/logo.png)
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=center>
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 "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.
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)
@@ -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} [radius]
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, radius?: number, color?: string, time?: number, fill?: boolean): void;
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]
@@ -268,6 +268,10 @@ declare module "littlejsengine" {
268
268
  * @default
269
269
  * @memberof Settings */
270
270
  export let canvasColorTiles: boolean;
271
+ /** Color to clear the canvas to before render
272
+ * @type {Color}
273
+ * @memberof Draw */
274
+ export let canvasClearColor: Color;
271
275
  /** The max size of the canvas, centered if window is larger
272
276
  * @type {Vector2}
273
277
  * @default Vector2(1920,1080)
@@ -467,6 +471,10 @@ declare module "littlejsengine" {
467
471
  * @param {boolean} colorTiles
468
472
  * @memberof Settings */
469
473
  export function setCanvasColorTiles(colorTiles: boolean): void;
474
+ /** Set color to clear the canvas to before render
475
+ * @param {Color} color
476
+ * @memberof Settings */
477
+ export function setCanvasClearColor(color: Color): void;
470
478
  /** Set max size of the canvas
471
479
  * @param {Vector2} size
472
480
  * @memberof Settings */
@@ -1105,6 +1113,9 @@ declare module "littlejsengine" {
1105
1113
  /** Get percentage elapsed based on time it was set to, returns 0 if not set
1106
1114
  * @return {number} */
1107
1115
  getPercent(): number;
1116
+ /** Get the time this timer was set to, returns 0 if not set
1117
+ * @return {number} */
1118
+ getSetTime(): number;
1108
1119
  /** Returns this timer expressed as a string
1109
1120
  * @return {string} */
1110
1121
  toString(): string;
@@ -1212,14 +1223,6 @@ declare module "littlejsengine" {
1212
1223
  * @type {Color}
1213
1224
  * @memberof Utilities */
1214
1225
  export const MAGENTA: Color;
1215
- /** Array containing texture info for batch rendering system
1216
- * @type {Array<TextureInfo>}
1217
- * @memberof Draw */
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;
1223
1226
  /**
1224
1227
  * Create a tile info object using a grid based system
1225
1228
  * - This can take vecs or floats for easier use and conversion
@@ -1245,8 +1248,9 @@ declare module "littlejsengine" {
1245
1248
  * @param {Vector2} [size=tileSizeDefault] - Size of tile in pixels
1246
1249
  * @param {number} [textureIndex] - Texture index to use
1247
1250
  * @param {number} [padding] - How many pixels padding around tiles
1251
+ * @param {number} [bleedScale] - How many pixels smaller to draw tiles
1248
1252
  */
1249
- constructor(pos?: Vector2, size?: Vector2, textureIndex?: number, padding?: number);
1253
+ constructor(pos?: Vector2, size?: Vector2, textureIndex?: number, padding?: number, bleedScale?: number);
1250
1254
  /** @property {Vector2} - Top left corner of tile in pixels */
1251
1255
  pos: Vector2;
1252
1256
  /** @property {Vector2} - Size of tile in pixels */
@@ -1257,6 +1261,8 @@ declare module "littlejsengine" {
1257
1261
  padding: number;
1258
1262
  /** @property {TextureInfo} - The texture info for this tile */
1259
1263
  textureInfo: TextureInfo;
1264
+ /** @property {float} - Shrinks tile by this many pixels to prevent neighbors bleeding */
1265
+ bleedScale: number;
1260
1266
  /** Returns a copy of this tile offset by a vector
1261
1267
  * @param {Vector2} offset - Offset to apply in pixels
1262
1268
  * @return {TileInfo}
@@ -1342,6 +1348,14 @@ declare module "littlejsengine" {
1342
1348
  * @type {Vector2}
1343
1349
  * @memberof Draw */
1344
1350
  export let mainCanvasSize: Vector2;
1351
+ /** Array containing texture info for batch rendering system
1352
+ * @type {Array<TextureInfo>}
1353
+ * @memberof Draw */
1354
+ export let textureInfos: Array<TextureInfo>;
1355
+ /** Keeps track of how many draw calls there were each frame for debugging
1356
+ * @type {number}
1357
+ * @memberof Draw */
1358
+ export let drawCount: number;
1345
1359
  /** Convert from screen to world space coordinates
1346
1360
  * @param {Vector2} screenPos
1347
1361
  * @return {Vector2}
@@ -1609,6 +1623,7 @@ declare module "littlejsengine" {
1609
1623
  * @memberof WebGL */
1610
1624
  export function glCreateProgram(vsSource: string, fsSource: string): WebGLProgram;
1611
1625
  /** Create WebGL texture from an image and init the texture settings
1626
+ * Restores the active texture when done
1612
1627
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} [image]
1613
1628
  * @return {WebGLTexture}
1614
1629
  * @memberof WebGL */
@@ -1617,7 +1632,7 @@ declare module "littlejsengine" {
1617
1632
  * @param {WebGLTexture} [texture]
1618
1633
  * @memberof WebGL */
1619
1634
  export function glDeleteTexture(texture?: WebGLTexture): void;
1620
- /** Set WebGL texture data from an image
1635
+ /** Set WebGL texture data from an image, restores the active texture when done
1621
1636
  * @param {WebGLTexture} texture
1622
1637
  * @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas} image
1623
1638
  * @memberof WebGL */
@@ -2859,6 +2874,8 @@ declare module "littlejsengine" {
2859
2874
  defaultLineWidth: number;
2860
2875
  /** @property {number} - Default rounded rect corner radius for UI elements */
2861
2876
  defaultCornerRadius: number;
2877
+ /** @property {number} - Default scale to use for fitting text to object */
2878
+ defaultTextScale: number;
2862
2879
  /** @property {string} - Default font for UI elements */
2863
2880
  defaultFont: string;
2864
2881
  /** @property {Sound} - Default sound when interactive UI element is pressed */
@@ -2901,8 +2918,9 @@ declare module "littlejsengine" {
2901
2918
  * @param {number} [lineWidth=uiSystem.defaultLineWidth]
2902
2919
  * @param {Color} [lineColor=uiSystem.defaultLineColor]
2903
2920
  * @param {string} [align]
2904
- * @param {string} [font=uiSystem.defaultFont] */
2905
- drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string): void;
2921
+ * @param {string} [font=uiSystem.defaultFont]
2922
+ * @param {boolean} [applyMaxWidth=true] */
2923
+ drawText(text: string, pos: Vector2, size: Vector2, color?: Color, lineWidth?: number, lineColor?: Color, align?: string, font?: string, applyMaxWidth?: boolean): void;
2906
2924
  }
2907
2925
  /**
2908
2926
  * UI Object - Base level object for all UI elements
@@ -2939,8 +2957,12 @@ declare module "littlejsengine" {
2939
2957
  cornerRadius: number;
2940
2958
  /** @property {string} - Font for this objecct */
2941
2959
  font: string;
2960
+ /** @property {number} - Override for text width */
2961
+ textWidth: any;
2942
2962
  /** @property {number} - Override for text height */
2943
2963
  textHeight: any;
2964
+ /** @property {number} - Scale text to fit in the object */
2965
+ textScale: number;
2944
2966
  /** @property {boolean} - Should this object be drawn */
2945
2967
  visible: boolean;
2946
2968
  /** @property {Array<UIObject>} - A list of this object's children */
@@ -2975,6 +2997,10 @@ declare module "littlejsengine" {
2975
2997
  render(): void;
2976
2998
  /** Special update when object is not visible */
2977
2999
  updateInvisible(): void;
3000
+ /** Get the size for text with overrides and scale
3001
+ * @return {Vector2}
3002
+ */
3003
+ getTextSize(): Vector2;
2978
3004
  /** Called when the mouse enters the object */
2979
3005
  onEnter(): void;
2980
3006
  /** Called when the mouse leaves the object */