littlejsengine 1.9.11 → 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.
Files changed (53) hide show
  1. package/README.md +4 -0
  2. package/dist/littlejs.d.ts +80 -9
  3. package/dist/littlejs.esm.js +193 -71
  4. package/dist/littlejs.esm.min.js +1 -1
  5. package/dist/littlejs.js +175 -69
  6. package/dist/littlejs.min.js +1 -1
  7. package/dist/littlejs.release.js +174 -68
  8. package/examples/box2d/game.js +1 -1
  9. package/examples/box2d/index.html +7 -6
  10. package/examples/breakout/game.js +1 -1
  11. package/examples/breakout/index.html +5 -4
  12. package/examples/breakoutTutorial/index.html +4 -3
  13. package/examples/electron/game.js +1 -1
  14. package/examples/electron/index.html +4 -3
  15. package/examples/empty/game.js +1 -1
  16. package/examples/empty/index.html +2 -1
  17. package/examples/htmlMenu/game.js +67 -0
  18. package/examples/htmlMenu/index.html +56 -0
  19. package/examples/htmlMenu/tiles.png +0 -0
  20. package/examples/index.html +33 -0
  21. package/examples/js13k/game.js +1 -1
  22. package/examples/js13k/index.html +17 -14
  23. package/examples/module/game.js +1 -1
  24. package/examples/module/index.html +3 -2
  25. package/examples/particles/index.html +4 -3
  26. package/examples/platformer/game.js +1 -1
  27. package/examples/platformer/gameLevel.js +2 -2
  28. package/examples/platformer/gameObjects.js +0 -1
  29. package/examples/platformer/index.html +10 -9
  30. package/examples/puzzle/game.js +1 -1
  31. package/examples/puzzle/index.html +4 -3
  32. package/examples/starter/game.js +4 -4
  33. package/examples/starter/index.html +15 -14
  34. package/examples/stress/index.html +3 -2
  35. package/examples/typescript/game.js +1 -1
  36. package/examples/typescript/index.html +3 -2
  37. package/examples/uiSystem/game.js +134 -0
  38. package/examples/uiSystem/index.html +25 -0
  39. package/examples/uiSystem/tiles.png +0 -0
  40. package/jsconfig.json +11 -0
  41. package/package.json +1 -1
  42. package/plugins/box2d.js +2 -1
  43. package/plugins/postProcess.js +6 -7
  44. package/plugins/uiSystem.js +243 -0
  45. package/src/engine.js +48 -20
  46. package/src/engineAudio.js +10 -13
  47. package/src/engineDebug.js +1 -1
  48. package/src/engineDraw.js +101 -27
  49. package/src/engineExport.js +18 -2
  50. package/src/engineInput.js +2 -2
  51. package/src/engineSettings.js +1 -1
  52. package/src/engineUtilities.js +1 -1
  53. package/src/engineWebGL.js +11 -4
@@ -1,4 +1,4 @@
1
- /**
1
+ /**
2
2
  * LittleJS Module Export
3
3
  * - Export engine as a module
4
4
  */
@@ -20,8 +20,9 @@ export {
20
20
  engineObjectsUpdate,
21
21
  engineObjectsDestroy,
22
22
  engineObjectsCallback,
23
+ engineObjectsRaycast,
23
24
  engineAddPlugin,
24
-
25
+
25
26
  // Globals
26
27
  debug,
27
28
  debugOverlay,
@@ -140,6 +141,7 @@ export {
140
141
  smoothStep,
141
142
  nearestPowerOfTwo,
142
143
  isOverlapping,
144
+ isIntersecting,
143
145
  wave,
144
146
  formatTime,
145
147
 
@@ -159,6 +161,20 @@ export {
159
161
  vec2,
160
162
  rgb,
161
163
  hsl,
164
+ isColor,
165
+
166
+ // Default Colors
167
+ WHITE,
168
+ BLACK,
169
+ GRAY,
170
+ RED,
171
+ ORANGE,
172
+ YELLOW,
173
+ GREEN,
174
+ CYAN,
175
+ BLUE,
176
+ PURPLE,
177
+ MAGENTA,
162
178
 
163
179
  // Draw
164
180
  textureInfos,
@@ -167,7 +167,7 @@ function inputInit()
167
167
 
168
168
  onkeydown = (e)=>
169
169
  {
170
- if (debug && e.target != document.body) return;
170
+ if (debug && e.target != engineRoot) return;
171
171
  if (!e.repeat)
172
172
  {
173
173
  isUsingGamepad = false;
@@ -180,7 +180,7 @@ function inputInit()
180
180
 
181
181
  onkeyup = (e)=>
182
182
  {
183
- if (debug && e.target != document.body) return;
183
+ if (debug && e.target != engineRoot) return;
184
184
  inputData[0][e.code] = 4;
185
185
  if (inputWASDEmulateDirection)
186
186
  inputData[0][remapKey(e.code)] = 4;
@@ -89,7 +89,7 @@ let tileSizeDefault = vec2(16);
89
89
  * @type {Number}
90
90
  * @default
91
91
  * @memberof Settings */
92
- let tileFixBleedScale = .5;
92
+ let tileFixBleedScale = 0;
93
93
 
94
94
  ///////////////////////////////////////////////////////////////////////////////
95
95
  // Object settings
@@ -735,7 +735,7 @@ class Color
735
735
  * @return {String} */
736
736
  toString(useAlpha = true)
737
737
  {
738
- const toHex = (c)=> ((c=c*255|0)<16 ? '0' : '') + c.toString(16);
738
+ const toHex = (c)=> ((c=clamp(c)*255|0)<16 ? '0' : '') + c.toString(16);
739
739
  return '#' + toHex(this.r) + toHex(this.g) + toHex(this.b) + (useAlpha ? toHex(this.a) : '');
740
740
  }
741
741
 
@@ -34,10 +34,10 @@ function glInit()
34
34
 
35
35
  // create the canvas and textures
36
36
  glCanvas = document.createElement('canvas');
37
- glContext = glCanvas.getContext('webgl2');
37
+ glContext = glCanvas.getContext('webgl2', {antialias:!canvasPixelated});
38
38
 
39
39
  // some browsers are much faster without copying the gl buffer so we just overlay it instead
40
- glOverlay && document.body.appendChild(glCanvas);
40
+ glOverlay && engineRoot.appendChild(glCanvas);
41
41
 
42
42
  // setup vertex and fragment shaders
43
43
  glShader = glCreateProgram(
@@ -92,7 +92,8 @@ function glPreRender()
92
92
  // set up the shader
93
93
  glContext.useProgram(glShader);
94
94
  glContext.activeTexture(gl_TEXTURE0);
95
- glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = textureInfos[0].glTexture);
95
+ if (textureInfos[0])
96
+ glContext.bindTexture(gl_TEXTURE_2D, glActiveTexture = textureInfos[0].glTexture);
96
97
 
97
98
  // set vertex attributes
98
99
  let offset = glAdditive = glBatchAdditive = 0;
@@ -190,8 +191,14 @@ function glCreateTexture(image)
190
191
  // build the texture
191
192
  const texture = glContext.createTexture();
192
193
  glContext.bindTexture(gl_TEXTURE_2D, texture);
193
- if (image)
194
+ if (image && image.width)
194
195
  glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, gl_RGBA, gl_UNSIGNED_BYTE, image);
196
+ else
197
+ {
198
+ // create a white texture
199
+ const whitePixel = new Uint8Array([255, 255, 255, 255]);
200
+ glContext.texImage2D(gl_TEXTURE_2D, 0, gl_RGBA, 1, 1, 0, gl_RGBA, gl_UNSIGNED_BYTE, whitePixel);
201
+ }
195
202
 
196
203
  // use point filtering for pixelated rendering
197
204
  const filter = canvasPixelated ? gl_NEAREST : gl_LINEAR;