littlejsengine 1.7.21 → 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.
Files changed (51) hide show
  1. package/README.md +27 -55
  2. package/build/littlejs.d.ts +101 -58
  3. package/build/littlejs.esm.js +497 -419
  4. package/build/littlejs.esm.min.js +1 -1
  5. package/build/littlejs.js +493 -228
  6. package/build/littlejs.min.js +1 -1
  7. package/build/littlejs.release.js +493 -228
  8. package/examples/breakout/game.js +17 -14
  9. package/examples/breakout/gameObjects.js +29 -8
  10. package/examples/breakout/index.html +3 -3
  11. package/examples/breakoutTutorial/README.md +2 -2
  12. package/examples/breakoutTutorial/game.js +4 -4
  13. package/examples/breakoutTutorial/index.html +2 -2
  14. package/examples/electron/game.js +3 -2
  15. package/examples/electron/index.html +2 -2
  16. package/examples/empty/game.js +1 -1
  17. package/examples/favicon.png +0 -0
  18. package/examples/js13k/game.js +20 -15
  19. package/examples/js13k/index.html +14 -14
  20. package/examples/module/game.js +4 -3
  21. package/examples/module/index.html +1 -1
  22. package/examples/particles/index.html +19 -22
  23. package/examples/platformer/game.js +3 -3
  24. package/examples/platformer/gameEffects.js +21 -19
  25. package/examples/platformer/gameLevel.js +6 -6
  26. package/examples/platformer/gameObjects.js +18 -18
  27. package/examples/platformer/gamePlayer.js +4 -3
  28. package/examples/platformer/index.html +6 -6
  29. package/examples/platformer/tiles.png +0 -0
  30. package/examples/platformer/tilesLevel.png +0 -0
  31. package/examples/puzzle/game.js +10 -8
  32. package/examples/puzzle/index.html +2 -2
  33. package/examples/screenshot.jpg +0 -0
  34. package/examples/starter/game.js +32 -21
  35. package/examples/starter/index.html +13 -13
  36. package/examples/starter/tiles.png +0 -0
  37. package/examples/stress/index.html +2 -2
  38. package/examples/typescript/game.js +4 -3
  39. package/examples/typescript/game.ts +4 -3
  40. package/examples/typescript/index.html +1 -1
  41. package/package.json +1 -1
  42. package/src/engine.js +59 -52
  43. package/src/engineDraw.js +137 -38
  44. package/src/engineExport.js +4 -191
  45. package/src/engineMedals.js +13 -45
  46. package/src/engineObject.js +12 -13
  47. package/src/engineParticles.js +17 -17
  48. package/src/engineSettings.js +195 -2
  49. package/src/engineTileLayer.js +23 -22
  50. package/src/engineUtilities.js +6 -6
  51. package/src/engineWebGL.js +31 -32
package/README.md CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
11
  LittleJS is a lightweight open source HTML5 game engine designed for modern web development.
12
12
  It's small footprint is packed with a comprehensive feature set, including hybrid rendering, physics, particles, sound effects, music, input handling, and debug tools.
13
- The code is very clean and well documented with a several examples to get you started. Choo-Choo! 🚂
13
+ The code is very clean and well documented with some fun examples to get you started. Choo-Choo! 🚂
14
14
 
15
15
  <div align="center">
16
16
 
17
- ## [Demo](https://killedbyapixel.github.io/LittleJS/examples/starter/) | [Docs](https://killedbyapixel.github.io/LittleJS/docs) | [Trailer](https://youtu.be/chuBzGjv7Ms) | [Discord](https://discord.gg/zb7hcGkyZe) | [Tutorial](https://github.com/KilledByAPixel/LittleJS/tree/main/examples/breakoutTutorial)
17
+ ## [Demo](https://killedbyapixel.github.io/LittleJS/examples/starter/) | [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)
18
18
 
19
19
  </div>
20
20
 
@@ -22,36 +22,36 @@ The code is very clean and well documented with a several examples to get you st
22
22
 
23
23
  ## About LittleJS
24
24
 
25
- LittleJS is a small but powerful game engine with many features and no depenencies.
25
+ LittleJS is a small but powerful game engine with many features and no dependencies.
26
26
 
27
27
  ### ✨ Graphics
28
28
 
29
29
  - Super fast sprite and tile map rendering engine with WebGL
30
- - Update and render 10,000+ objects at 60fps, often many times more
31
- - Particle effect system and [design tool](https://killedbyapixel.github.io/LittleJS/examples/particles/)
30
+ - Update and render over 10,000 objects at a solid 60fps
32
31
  - Apply [Shadertoy](https://www.shadertoy.com) compatible shaders for post processinge effects
32
+ - Robust particle effect system and [effect design tool](https://killedbyapixel.github.io/LittleJS/examples/particles/)
33
33
 
34
34
  ### 🔊 Audio
35
35
 
36
- - Positional sound effects with wav or [ZzFX](https://killedbyapixel.github.io/ZzFX/) sound effect generator
36
+ - Positional sound effects with wave or [ZzFX](https://killedbyapixel.github.io/ZzFX/)
37
37
  - Music with mp3, ogg, wave, or [ZzFXM](https://keithclark.github.io/ZzFXM/)
38
38
 
39
39
  ### 🎮 Input
40
40
 
41
- - Input processing system for keyboard, mouse, gamepad, and touch
42
- - On screen touch gamepad for mobile devices
41
+ - Comprehensive system for keyboard, mouse, gamepad, and touch
42
+ - On screen touch gamepad designed for mobile devices
43
43
 
44
44
  ### 💥 Physics
45
45
 
46
46
  - 2D physics engine with collision handling for axis aligned boxes
47
- - Very fast collision handling and raycasting for tile maps
47
+ - Very fast collision and raycasting for tile maps
48
48
 
49
49
  ### 🚀 Flexability
50
50
 
51
- - Designed to work with all modern web bowsers and mobile devices
52
- - Compatible with TypeScript and Modules with example projects for both
53
- - For size coding competitions like [js13kGames](https://js13kgames.com/), [a special example project builds to a 7KB zip file](https://killedbyapixel.github.io/LittleJS/examples/js13k)
54
- - Builds to a Windows executable with [Electron](https://www.electronjs.org/) for distribution on PC platforms like Steam
51
+ - Compatible with all modern web bowsers and on mobile devices
52
+ - Support for TypeScript and Modules with example projects for both
53
+ - Ideal for size coding competitions like [js13kGames](https://js13kgames.com/), [starter project builds to a 7KB zip](https://killedbyapixel.github.io/LittleJS/examples/js13k)
54
+ - Builds to an executable with [Electron](https://www.electronjs.org/) for distribution on Windows, macOS, and Linux
55
55
  - Open Source with the [MIT license](https://github.com/KilledByAPixel/LittleJS/blob/main/LICENSE) so it can be used for anything you want forever
56
56
 
57
57
  ### 🛠️ And more...
@@ -66,65 +66,37 @@ LittleJS is a small but powerful game engine with many features and no depenenci
66
66
  ## Demos
67
67
 
68
68
  ### [Starter Project](https://killedbyapixel.github.io/LittleJS/examples/starter/) - Clean example with only a few things to get you started
69
+ ### [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout/) - Breakout game with post processing effect
69
70
  ### [Puzzle Game](https://killedbyapixel.github.io/LittleJS/examples/puzzle/) - Match 3 puzzle game with HD rendering and high score tracking
70
71
  ### [Platformer](https://killedbyapixel.github.io/LittleJS/examples/platformer/) - Platformer/shooter with procedural generation and destruction
71
- ### [Breakout](https://killedbyapixel.github.io/LittleJS/examples/breakout/) - Breakout game with post processing effect
72
72
  ### [Stress Test](https://killedbyapixel.github.io/LittleJS/examples/stress/) - Max sprite/object test and music system demo
73
73
  ### [Particle System Designer](https://killedbyapixel.github.io/LittleJS/examples/particles/) - Particle system editor and visualizer
74
74
 
75
75
  ## How to use LittleJS
76
76
 
77
- To use LittleJS download the latest package from GitHub or call ```npm install littlejsengine```. This package contains the engine and several small examples.
78
-
79
- [You can use the empty example template as a starting point.](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/empty/game.js) This file contains just the minimal setup to start the engine. You can also download and include [littlejs.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.js) or [littlejs.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.min.js).
77
+ To use LittleJS download the latest package from GitHub or call ```npm install littlejsengine```.
80
78
 
81
- If your game loads any files like images you will need to run a local web server. Some editors can do this automatically like [Visual Studio Code](https://code.visualstudio.com/) with the [Live Server plugin](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer). You can also use [http-server](https://www.npmjs.com/package/http-server) via npm.
79
+ [The Breakout Tutorial](https://github.com/KilledByAPixel/LittleJS/tree/main/examples/breakoutTutorial) demonstrates how to make a simple game from scratch. [The tutorial is also available on YouTube.](https://youtu.be/tSwDx-NWTXE?si=bkjMa8-7AN2Wg5MO)
82
80
 
83
- [The Breakout Tutorial](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/breakoutTutorial) is provided to demonstrate how to make a simple game from scratch. [The tutorial is also available on YouTube.](https://youtu.be/tSwDx-NWTXE?si=bkjMa8-7AN2Wg5MO)
81
+ [This GitNation talk explains how LittleJS works with some tips on how to use it.](https://youtu.be/_dXKU0WgAj8?si=ZDXLYAFDWp54hrGT)
84
82
 
85
83
  ## Builds
86
84
 
87
- To easily include LittleJS in your game, you can use one of the 3 pre-built js files. These are also built automatically by the build scripts.
85
+ To easily include LittleJS in your game, you can use one of the pre-built js files.
88
86
 
89
87
  - [littlejs.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.js) - The full game engine with debug mode available
90
88
  - [littlejs.release.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.release.js) - The engine optimized for release builds
91
89
  - [littlejs.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.min.js) - The engine in release mode and minified
92
-
93
- LittleJS can also be imported as a module. There are two module flavors that are automatically built.
94
-
95
90
  - [littlejs.esm.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.esm.js) - The engine exported as a module with debug mode available
96
91
  - [littlejs.esm.min.js](https://github.com/KilledByAPixel/LittleJS/blob/main/build/littlejs.esm.min.js) - The engine exported as a minified module in release mode
97
92
 
98
93
  To rebuild the engine you must first run ```npm install``` to setup the necessary npm dependencies. Then call ```npm run build``` to build the engine.
99
94
 
100
- The starter example project also includes a node js file [build.js](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/starter/build.js) that compresses everything into a tiny zip file using Google Closure, UglifyJS, and ECT Zip.
101
-
102
- ## Engine Source Code
103
-
104
- This engine is made with simplicity in mind using clean easy to read code.
105
- There are only a few core files used by the entire engine.
106
-
107
- - [engine.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engine.js) - Top level engine init, update, and render
108
- - [engineSettings.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineSettings.js) - Global engine settings
109
- - [engineObject.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) - Base object class and physics
110
- - [engineDraw.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDraw.js) - Code for canvas drawing and text
111
- - [engineAudio.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineAudio.js) - Spacial sound effects, and zzfx sound generator
112
- - [engineInput.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineInput.js) - Input for keyboard, mouse, touch, and gamepad
113
- - [engineUtilities.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineUtilities.js) - Vector2, Color, and Timer clases and math functions
114
-
115
- Optional Components, these components are built to synergize with the rest of the engine but are not required.
116
-
117
- - [engineTileLayer.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineTileLayer.js) - Tile layer rendering and collision
118
- - [engineParticles.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineParticles.js) - Particle system with fast rendering and collision
119
- - [engineWebGL.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineWebGL.js) - Super fast rendering with WebGL and post processing
120
- - [engineMedals.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineMedals.js) - Achievement tracker with Newgrounds integration
121
- - [engineDebug.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineDebug.js) - Debug rendering system and information overlay
122
- - [engineExport.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineExport.js) - Included when exporting engine as a module
123
- - [engineBuild.js](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineBuild.js) - Node script used to build the engine
95
+ The starter example project includes a node js file [build.js](https://github.com/KilledByAPixel/LittleJS/blob/main/examples/starter/build.js) that compresses everything into a tiny zip file using Google Closure, UglifyJS, and ECT Zip.
124
96
 
125
97
  ## LittleJS Setup
126
98
 
127
- To start LittleJS, you must create 5 functions and pass them to engineInit. A canvas will automatically be created and added to the document.
99
+ To start LittleJS, you need to create these 5 functions and pass them to engineInit.
128
100
 
129
101
  ```javascript
130
102
  function gameInit()
@@ -158,21 +130,22 @@ function gameRenderPost()
158
130
  }
159
131
 
160
132
  // Startup LittleJS Engine
161
- engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost, 'tiles.png');
133
+ engineInit(gameInit, gameUpdate, gameUpdatePost, gameRender, gameRenderPost);
162
134
  ```
163
135
 
164
136
  ## LittleJS Objects
165
137
 
166
- Though not required, LittleJS is intended to be used as an object oriented system by extending the base class [EngineObject](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) with your own. This lightweight class provides many useful features including physics, collision, parent/child system, and sorted rendering. Engine objects are automatically added to the global list of objects where they will be updated and rendered until destroyed.
138
+ LittleJS can be used as an object oriented system by extending the base class [EngineObject](https://github.com/KilledByAPixel/LittleJS/blob/main/src/engineObject.js) with your own. This lightweight class provides many useful features including physics, collision, parent/child system, and sorted rendering. These objects are added to the global list of objects where they will automatically be updated and rendered until destroyed.
167
139
 
168
140
  Here is a template you can use to make objects that behave however you want. See the examples for a complete demonstration.
169
141
 
170
142
  ```javascript
171
143
  class MyObject extends EngineObject
172
144
  {
173
- constructor(pos, size, tileIndex, tileSize, angle)
145
+ constructor(pos, size, tileInfo, angle)
174
146
  {
175
- super(pos, size, tileIndex, tileSize, angle);
147
+ super(pos, size, tileInfo, angle);
148
+ // setup object
176
149
  }
177
150
 
178
151
  update()
@@ -202,7 +175,7 @@ Debug builds of LittleJS have a special menu that can be opened by pressing the
202
175
 
203
176
  ## Games Made With LittleJS
204
177
 
205
- Here are a few of the amazing games people are making with LittleJS.
178
+ Here are a few of the amazing games people are making with LittleJS...
206
179
 
207
180
  - [Space Huggers](https://www.newgrounds.com/portal/view/819609) - Run and gun platformer with procedural levels
208
181
  - [Undergrowth](https://undergrowth.squidband.uk/) - An interactive music videogame for the band Squid
@@ -214,13 +187,12 @@ Here are a few of the amazing games people are making with LittleJS.
214
187
  - [Necrotic Commander](https://js13kgames.com/entries/necrotic-commander) - Tower defense game by [Daniel Jeffery](https://github.com/d-jeffery/NecroticCommander)
215
188
  - [Boxing up Bamboo](https://patrickgh3.itch.io/boxing-up-bamboo) - A challenging puzzle game by [Patrick Traynor](https://cwpat.me/about)
216
189
  - [Samurai Sam](https://dev.js13kgames.com/2023/games/samurai-sam) - A Fruit Ninja inspired game by [John Edvard](https://reitgames.com)
217
- - Send me your games!
218
190
 
219
191
  ![LittleJS Logo](examples/favicon.png)
220
192
 
221
193
  [npm]: https://img.shields.io/npm/v/littlejsengine
222
194
  [npm-url]: https://www.npmjs.com/package/littlejsengine
223
- [build-size]: https://badgen.net/bundlephobia/minzip/littlejsengine?1
195
+ [build-size]: https://img.shields.io/bundlephobia/minzip/littlejsengine
224
196
  [build-size-url]: https://bundlephobia.com/result?p=littlejsengine
225
197
  [npm-downloads]: https://img.shields.io/npm/dw/littlejsengine
226
198
  [npmtrends-url]: https://www.npmtrends.com/littlejsengine
@@ -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
- /** Prevent tile bleeding from neighbors in pixels
180
+ /** How many pixels smaller to draw tiles to prevent bleeding from neighbors
185
181
  * @type {Number}
186
182
  * @default
187
183
  * @memberof Settings */
@@ -583,10 +579,10 @@ declare module "littlejs.esm" {
583
579
  * - Can be used to create a deterministic random number sequence
584
580
  * @example
585
581
  * let r = new RandomGenerator(123); // random number generator with seed 123
586
- * let a = r.rand(); // random value between 0 and 1
587
- * let b = r.randInt(10); // random integer between 0 and 9
582
+ * let a = r.float(); // random value between 0 and 1
583
+ * let b = r.int(10); // random integer between 0 and 9
588
584
  * r.seed = 123; // reset the seed
589
- * let c = r.rand(); // the same value as a
585
+ * let c = r.float(); // the same value as a
590
586
  */
591
587
  export class RandomGenerator {
592
588
  /** Create a random number generator with the seed passed in
@@ -844,7 +840,7 @@ declare module "littlejs.esm" {
844
840
  }
845
841
  /**
846
842
  * Create a 2d vector, can take another Vector2 to copy, 2 scalars, or 1 scalar
847
- * @param {Number} [x=0]
843
+ * @param {(Number|Vector2)} [x=0]
848
844
  * @param {Number} [y=0]
849
845
  * @return {Vector2}
850
846
  * @example
@@ -854,7 +850,7 @@ declare module "littlejs.esm" {
854
850
  * b = vec2(); // set b to (0, 0)
855
851
  * @memberof Utilities
856
852
  */
857
- export function vec2(x?: number, y?: number): Vector2;
853
+ export function vec2(x?: (number | Vector2), y?: number): Vector2;
858
854
  /**
859
855
  * Create a color object with RGBA values
860
856
  * @param {Number} [r=1] - red
@@ -905,23 +901,20 @@ declare module "littlejs.esm" {
905
901
  */
906
902
  export class EngineObject {
907
903
  /** Create an engine object and adds it to the list of objects
908
- * @param {Vector2} [position=Vector2()] - World space position of the object
909
- * @param {Vector2} [size=Vector2(1,1)] - World space size of the object
910
- * @param {Number} [tileIndex=-1] - Tile to use to render object (-1 is untextured)
911
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
912
- * @param {Number} [angle=0] - Angle the object is rotated by
913
- * @param {Color} [color=Color()] - Color to apply to tile when rendered
914
- * @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
915
910
  */
916
- constructor(pos?: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, angle?: number, color?: Color, renderOrder?: number);
911
+ constructor(pos?: Vector2, size?: Vector2, tileInfo?: TileInfo, angle?: number, color?: Color, renderOrder?: number);
917
912
  /** @property {Vector2} - World space position of the object */
918
913
  pos: Vector2;
919
914
  /** @property {Vector2} - World space width and height of the object */
920
915
  size: Vector2;
921
- /** @property {Number} - Tile to use to render object (-1 is untextured) */
922
- tileIndex: number;
923
- /** @property {Vector2} - Size of tile in source pixels */
924
- tileSize: Vector2;
916
+ /** @property {TileInfo} - Tile info to render object (undefined is untextured) */
917
+ tileInfo: TileInfo;
925
918
  /** @property {Number} - Angle to rotate the object */
926
919
  angle: number;
927
920
  /** @property {Color} - Color to apply when rendered */
@@ -1001,10 +994,64 @@ declare module "littlejs.esm" {
1001
994
  * @return {String} */
1002
995
  toString(): string;
1003
996
  }
1004
- /** Tile sheet for batch rendering system
1005
- * @type {CanvasImageSource}
997
+ /** Array containing texture info for batch rendering system
998
+ * @type {Array}
1006
999
  * @memberof Draw */
1007
- export const tileImage: CanvasImageSource;
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
+ }
1008
1055
  /**
1009
1056
  * LittleJS Drawing System
1010
1057
  * - Hybrid system with both Canvas2D and WebGL available
@@ -1059,7 +1106,7 @@ declare module "littlejs.esm" {
1059
1106
  /** Draw textured tile centered in world space, with color applied if using WebGL
1060
1107
  * @param {Vector2} pos - Center of the tile in world space
1061
1108
  * @param {Vector2} [size=Vector2(1,1)] - Size of the tile in world space
1062
- * @param {Number} [tileIndex=-1] - Tile index to use, negative is untextured
1109
+ * @param {TileInfo}[tileInfo] - Tile info to use, untextured if undefined
1063
1110
  * @param {Vector2} [tileSize=tileSizeDefault] - Tile size in source pixels
1064
1111
  * @param {Color} [color=Color()] - Color to modulate with
1065
1112
  * @param {Number} [angle=0] - Angle to rotate by
@@ -1068,7 +1115,7 @@ declare module "littlejs.esm" {
1068
1115
  * @param {Boolean} [useWebGL=glEnable] - Use accelerated WebGL rendering
1069
1116
  * @param {Boolean} [screenSpace=0] - If true the pos and size are in screen space
1070
1117
  * @memberof Draw */
1071
- export function drawTile(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean): void;
1118
+ export function drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean, additiveColor?: Color, useWebGL?: boolean, screenSpace?: boolean): void;
1072
1119
  /** Draw colored rect centered on pos
1073
1120
  * @param {Vector2} pos
1074
1121
  * @param {Vector2} [size=Vector2(1,1)]
@@ -1146,14 +1193,12 @@ declare module "littlejs.esm" {
1146
1193
  * @param {HTMLImageElement} [image] - Image for the font, if undefined default font is used
1147
1194
  * @param {Vector2} [tileSize=vec2(8)] - Size of the font source tiles
1148
1195
  * @param {Vector2} [paddingSize=vec2(0,1)] - How much extra space to add between characters
1149
- * @param {Number} [startTileIndex=0] - Tile index in image where font starts
1150
1196
  * @param {CanvasRenderingContext2D} [context=overlayContext] - context to draw to
1151
1197
  */
1152
- constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, startTileIndex?: number, context?: CanvasRenderingContext2D);
1198
+ constructor(image?: HTMLImageElement, tileSize?: Vector2, paddingSize?: Vector2, context?: CanvasRenderingContext2D);
1153
1199
  image: any;
1154
1200
  tileSize: Vector2;
1155
1201
  paddingSize: Vector2;
1156
- startTileIndex: number;
1157
1202
  context: CanvasRenderingContext2D;
1158
1203
  /** Draw text in world space using the image font
1159
1204
  * @param {String} text
@@ -1520,7 +1565,7 @@ declare module "littlejs.esm" {
1520
1565
  clear(): void;
1521
1566
  }
1522
1567
  /**
1523
- * Tile layer object - cached rendering system for tile layers
1568
+ * Tile Layer - cached rendering system for tile layers
1524
1569
  * - Each Tile layer is rendered to an off screen canvas
1525
1570
  * - To allow dynamic modifications, layers are rendered using canvas 2d
1526
1571
  * - Some devices like mobile phones are limited to 4k texture resolution
@@ -1535,11 +1580,11 @@ declare module "littlejs.esm" {
1535
1580
  /** Create a tile layer object
1536
1581
  * @param {Vector2} [position=Vector2()] - World space position
1537
1582
  * @param {Vector2} [size=tileCollisionSize] - World space size
1538
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tiles in source pixels
1583
+ * @param {TileInfo} [tileInfo] - Tile info for layer
1539
1584
  * @param {Vector2} [scale=Vector2(1,1)] - How much to scale this layer when rendered
1540
1585
  * @param {Number} [renderOrder=0] - Objects sorted by renderOrder before being rendered
1541
1586
  */
1542
- constructor(pos: any, size?: Vector2, tileSize?: Vector2, scale?: Vector2, renderOrder?: number);
1587
+ constructor(pos: any, size?: Vector2, tileInfo?: TileInfo, scale?: Vector2, renderOrder?: number);
1543
1588
  /** @property {HTMLCanvasElement} - The canvas used by this tile layer */
1544
1589
  canvas: HTMLCanvasElement;
1545
1590
  /** @property {CanvasRenderingContext2D} - The 2D canvas context used by this tile layer */
@@ -1581,12 +1626,11 @@ declare module "littlejs.esm" {
1581
1626
  /** Draw a tile directly onto the layer canvas
1582
1627
  * @param {Vector2} pos
1583
1628
  * @param {Vector2} [size=Vector2(1,1)]
1584
- * @param {Number} [tileIndex=-1]
1585
- * @param {Vector2} [tileSize=tileSizeDefault]
1629
+ * @param {TileInfo} [tileInfo]
1586
1630
  * @param {Color} [color=Color()]
1587
1631
  * @param {Number} [angle=0]
1588
1632
  * @param {Boolean} [mirror=0] */
1589
- drawTile(pos: Vector2, size?: Vector2, tileIndex?: number, tileSize?: Vector2, color?: Color, angle?: number, mirror?: boolean): void;
1633
+ drawTile(pos: Vector2, size?: Vector2, tileInfo?: TileInfo, color?: Color, angle?: number, mirror?: boolean): void;
1590
1634
  /** Draw a rectangle directly onto the layer canvas
1591
1635
  * @param {Vector2} pos
1592
1636
  * @param {Vector2} [size=Vector2(1,1)]
@@ -1606,7 +1650,7 @@ declare module "littlejs.esm" {
1606
1650
  * let particleEmiter = new ParticleEmitter
1607
1651
  * (
1608
1652
  * pos, 0, 1, 0, 500, PI, // pos, angle, emitSize, emitTime, emitRate, emiteCone
1609
- * 0, vec2(16), // tileIndex, tileSize
1653
+ * tile(0, 16), // tileInfo
1610
1654
  * new Color(1,1,1), new Color(0,0,0), // colorStartA, colorStartB
1611
1655
  * new Color(1,1,1,0), new Color(0,0,0,0), // colorEndA, colorEndB
1612
1656
  * 2, .2, .2, .1, .05, // particleTime, sizeStart, sizeEnd, particleSpeed, particleAngleSpeed
@@ -1622,8 +1666,7 @@ declare module "littlejs.esm" {
1622
1666
  * @param {Number} [emitTime=0] - How long to stay alive (0 is forever)
1623
1667
  * @param {Number} [emitRate=100] - How many particles per second to spawn, does not emit if 0
1624
1668
  * @param {Number} [emitConeAngle=PI] - Local angle to apply velocity to particles from emitter
1625
- * @param {Number} [tileIndex=-1] - Index into tile sheet, if <0 no texture is applied
1626
- * @param {Vector2} [tileSize=tileSizeDefault] - Tile size for particles
1669
+ * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
1627
1670
  * @param {Color} [colorStartA=Color()] - Color at start of life 1, randomized between start colors
1628
1671
  * @param {Color} [colorStartB=Color()] - Color at start of life 2, randomized between start colors
1629
1672
  * @param {Color} [colorEndA=Color(1,1,1,0)] - Color at end of life 1, randomized between end colors
@@ -1645,7 +1688,7 @@ declare module "littlejs.esm" {
1645
1688
  * @param {Number} [renderOrder=0] - Render order for particles (additive is above other stuff by default)
1646
1689
  * @param {Boolean} [localSpace=0] - Should it be in local space of emitter (world space is default)
1647
1690
  */
1648
- constructor(pos: any, angle?: number, emitSize?: number, emitTime?: number, emitRate?: number, emitConeAngle?: number, tileIndex?: number, tileSize?: Vector2, 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);
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);
1649
1692
  /** @property {Number} - World space size of the emitter (float for circle diameter, vec2 for rect) */
1650
1693
  emitSize: number;
1651
1694
  /** @property {Number} - How long to stay alive (0 is forever) */
@@ -1701,11 +1744,10 @@ declare module "littlejs.esm" {
1701
1744
  /**
1702
1745
  * Create a particle with the given settings
1703
1746
  * @param {Vector2} position - World space position of the particle
1704
- * @param {Number} [tileIndex=-1] - Tile to use to render, untextured if -1
1705
- * @param {Vector2} [tileSize=tileSizeDefault] - Size of tile in source pixels
1747
+ * @param {TileInfo} [tileInfo] - Tile info to render particles (undefined is untextured)
1706
1748
  * @param {Number} [angle=0] - Angle to rotate the particle
1707
1749
  */
1708
- constructor(pos: any, tileIndex?: number, tileSize?: Vector2, angle?: number);
1750
+ constructor(pos: any, tileInfo?: TileInfo, angle?: number);
1709
1751
  }
1710
1752
  /**
1711
1753
  * LittleJS Medal System
@@ -1732,10 +1774,11 @@ declare module "littlejs.esm" {
1732
1774
  /** This can used to enable Newgrounds functionality
1733
1775
  * @param {Number} app_id - The newgrounds App ID
1734
1776
  * @param {String} [cipher] - The encryption Key (AES-128/Base64)
1777
+ * @param {Object} [cryptoJS] - An instance of CryptoJS, if there is a cipher
1735
1778
  * @memberof Medals */
1736
- export function newgroundsInit(app_id: number, cipher?: string): void;
1779
+ export function newgroundsInit(app_id: number, cipher?: string, cryptoJS?: any): void;
1737
1780
  /**
1738
- * Medal Object - Tracks an unlockable medal
1781
+ * Medal - Tracks an unlockable medal
1739
1782
  * @example
1740
1783
  * // create a medal
1741
1784
  * const medal_example = new Medal(0, 'Example Medal', 'More info about the medal goes here.', '🎖️');
@@ -1747,7 +1790,7 @@ declare module "littlejs.esm" {
1747
1790
  * medal_example.unlock();
1748
1791
  */
1749
1792
  export class Medal {
1750
- /** Create an medal object and adds it to the list of medals
1793
+ /** Create a medal object and adds it to the list of medals
1751
1794
  * @param {Number} id - The unique identifier of the medal
1752
1795
  * @param {String} name - Name of the medal
1753
1796
  * @param {String} [description] - Description of the medal
@@ -1778,20 +1821,20 @@ declare module "littlejs.esm" {
1778
1821
  /**
1779
1822
  * Newgrounds API wrapper object
1780
1823
  * @example
1781
- * // create a newgrounds object, replace the app id and cipher with your own
1824
+ * // create a newgrounds object, replace the app id with your own
1782
1825
  * const app_id = '53123:1ZuSTQ9l';
1783
- * const cipher = 'enF0vGH@Mj/FRASKL23Q==';
1784
- * newgrounds = new Newgrounds(app_id, cipher);
1826
+ * newgrounds = new Newgrounds(app_id);
1785
1827
  */
1786
1828
  export class Newgrounds {
1787
1829
  /** Create a newgrounds object
1788
1830
  * @param {Number} app_id - The newgrounds App ID
1789
- * @param {String} [cipher] - The encryption Key (AES-128/Base64) */
1790
- constructor(app_id: number, cipher?: string);
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);
1791
1834
  app_id: number;
1792
1835
  cipher: string;
1793
- host: string;
1794
1836
  cryptoJS: any;
1837
+ host: string;
1795
1838
  session_id: string;
1796
1839
  medals: any;
1797
1840
  scoreboards: any;
@@ -1820,7 +1863,6 @@ declare module "littlejs.esm" {
1820
1863
  * @return {Object} - The response JSON object
1821
1864
  */
1822
1865
  call(component: string, parameters?: any, async?: boolean): any;
1823
- CryptoJS(): any;
1824
1866
  }
1825
1867
  /**
1826
1868
  * LittleJS WebGL Interface
@@ -1830,6 +1872,7 @@ declare module "littlejs.esm" {
1830
1872
  * - Can be disabled with glEnable to revert to 2D canvas rendering
1831
1873
  * - Batches sprite rendering on GPU for incredibly fast performance
1832
1874
  * - Sprite transform math is done in the shader where possible
1875
+ * - Supports shadertoy style post processing shaders
1833
1876
  * @namespace WebGL
1834
1877
  */
1835
1878
  /** The WebGL canvas which appears above the main canvas and below the overlay canvas
@@ -1844,11 +1887,11 @@ declare module "littlejs.esm" {
1844
1887
  * @param {Boolean} [additive=0]
1845
1888
  * @memberof WebGL */
1846
1889
  export function glSetBlendMode(additive?: boolean): void;
1847
- /** Set the WebGl texture, not normally necessary unless multiple tile sheets are used
1890
+ /** Set the WebGl texture, called automatically if using multiple textures
1848
1891
  * - This may also flush the gl buffer resulting in more draw calls and worse performance
1849
- * @param {WebGLTexture} [texture=glTileTexture]
1892
+ * @param {WebGLTexture} texture
1850
1893
  * @memberof WebGL */
1851
- export function glSetTexture(texture?: WebGLTexture): void;
1894
+ export function glSetTexture(texture: WebGLTexture): void;
1852
1895
  /** Compile WebGL shader of the given type, will throw errors if in debug mode
1853
1896
  * @param {String} source
1854
1897
  * @param type
@@ -1941,9 +1984,9 @@ declare module "littlejs.esm" {
1941
1984
  * @param {Function} gameUpdatePost - Called after physics and objects are updated, setup camera and prepare for render
1942
1985
  * @param {Function} gameRender - Called before objects are rendered, draw any background effects that appear behind objects
1943
1986
  * @param {Function} gameRenderPost - Called after objects are rendered, draw effects or hud that appear above all objects
1944
- * @param {String} [tileImageSource] - Tile image to use, everything starts when the image is finished loading
1987
+ * @param {String} [imageSources='tiles.png'] - Image to load
1945
1988
  * @memberof Engine */
1946
- export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, tileImageSource?: string): void;
1989
+ export function engineInit(gameInit: Function, gameUpdate: Function, gameUpdatePost: Function, gameRender: Function, gameRenderPost: Function, imageSources?: string): void;
1947
1990
  /** Update each engine object, remove destroyed objects, and update time
1948
1991
  * @memberof Engine */
1949
1992
  export function engineObjectsUpdate(): void;