littlejsengine 1.15.9 → 1.16.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 (54) hide show
  1. package/dist/littlejs.d.ts +154 -158
  2. package/dist/littlejs.esm.js +573 -570
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +553 -553
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +392 -396
  7. package/examples/box2d/game.js +1 -1
  8. package/examples/box2d/gameObjects.js +5 -5
  9. package/examples/breakout/game.js +3 -3
  10. package/examples/electron/game.js +1 -2
  11. package/examples/electron/index.html +2 -2
  12. package/examples/htmlMenu/game.js +0 -1
  13. package/examples/index.html +1 -1
  14. package/examples/logo.png +0 -0
  15. package/examples/logo2.png +0 -0
  16. package/examples/module/game.js +1 -2
  17. package/examples/particles/index.html +1 -1
  18. package/examples/platformer/game.js +4 -4
  19. package/examples/platformer/gameEffects.js +1 -1
  20. package/examples/puzzle/game.js +2 -2
  21. package/examples/shorts/base.html +4 -3
  22. package/examples/shorts/box2dPool.js +2 -2
  23. package/examples/shorts/empty.js +1 -1
  24. package/examples/shorts/{systemFont.js → fontImage.js} +3 -3
  25. package/examples/shorts/fps.js +1 -1
  26. package/examples/shorts/helloWorld.js +2 -2
  27. package/examples/shorts/nineSlice.js +2 -2
  28. package/examples/shorts/slidingPuzzle.js +1 -1
  29. package/examples/starter/game.js +1 -2
  30. package/examples/starter/index.html +3 -2
  31. package/examples/stress/index.html +1 -1
  32. package/examples/typescript/game.js +1 -2
  33. package/examples/typescript/game.ts +1 -2
  34. package/package.json +1 -1
  35. package/plugins/box2d.js +8 -8
  36. package/plugins/drawUtilities.js +6 -6
  37. package/plugins/postProcess.js +13 -20
  38. package/plugins/uiSystem.js +16 -4
  39. package/reference.md +9 -11
  40. package/src/engine.js +40 -54
  41. package/src/engineAudio.js +5 -7
  42. package/src/engineBuild.js +1 -0
  43. package/src/engineDebug.js +163 -161
  44. package/src/engineDraw.js +108 -130
  45. package/src/engineExport.js +20 -17
  46. package/src/engineInput.js +4 -7
  47. package/src/engineMath.js +1201 -0
  48. package/src/engineMedals.js +7 -7
  49. package/src/engineObject.js +5 -4
  50. package/src/engineRelease.js +2 -4
  51. package/src/engineSettings.js +22 -32
  52. package/src/engineTileLayer.js +9 -10
  53. package/src/engineUtilities.js +34 -1187
  54. package/src/engineWebGL.js +13 -15
@@ -13,7 +13,7 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- /** The WebGL canvas which appears above the main canvas and below the overlay canvas
16
+ /** The WebGL canvas which appears below the main canvas
17
17
  * @type {HTMLCanvasElement}
18
18
  * @memberof WebGL */
19
19
  let glCanvas;
@@ -43,7 +43,7 @@ const gl_MAX_POLY_VERTEXES = gl_ARRAY_BUFFER_SIZE / gl_POLY_VERTEX_BYTE_STRIDE |
43
43
  ///////////////////////////////////////////////////////////////////////////////
44
44
 
45
45
  // Initialize WebGL, called automatically by the engine
46
- function glInit()
46
+ function glInit(rootElement)
47
47
  {
48
48
  // keep set of texture infos so they can be restored if context is lost
49
49
  glTextureInfos = new Set;
@@ -67,8 +67,7 @@ function glInit()
67
67
  return;
68
68
  }
69
69
 
70
- // attach the WebGL canvas
71
- const rootElement = mainCanvas.parentElement;
70
+ // attach the WebGL canvas;
72
71
  rootElement.appendChild(glCanvas);
73
72
 
74
73
  // startup webgl
@@ -169,8 +168,7 @@ function glInit()
169
168
 
170
169
  function glSetInstancedMode()
171
170
  {
172
- if (!glPolyMode)
173
- return;
171
+ if (!glPolyMode) return;
174
172
 
175
173
  // setup instanced mode
176
174
  glFlush();
@@ -203,8 +201,7 @@ function glSetInstancedMode()
203
201
 
204
202
  function glSetPolyMode()
205
203
  {
206
- if (glPolyMode)
207
- return;
204
+ if (glPolyMode) return;
208
205
 
209
206
  // setup poly mode
210
207
  glFlush();
@@ -283,9 +280,12 @@ function glClearCanvas()
283
280
  if (!glContext) return;
284
281
 
285
282
  // clear and set to same size as main canvas
286
- glCanvas.width = drawCanvas.width;
287
- glCanvas.height = drawCanvas.height;
283
+ glCanvas.width = mainCanvasSize.x;
284
+ glCanvas.height = mainCanvasSize.y;
288
285
  glContext.viewport(0, 0, glCanvas.width, glCanvas.height);
286
+ const color = canvasClearColor;
287
+ if (color.a > 0)
288
+ glContext.clearColor(color.r, color.g, color.b, color.a);
289
289
  glContext.clear(glContext.COLOR_BUFFER_BIT);
290
290
  }
291
291
 
@@ -297,8 +297,7 @@ function glClearCanvas()
297
297
  function glSetTexture(texture, wrap=false)
298
298
  {
299
299
  // must flush cache with the old texture to set a new one
300
- if (!glContext || texture === glActiveTexture)
301
- return;
300
+ if (!glContext || texture === glActiveTexture) return;
302
301
 
303
302
  glFlush();
304
303
  glActiveTexture = texture;
@@ -394,6 +393,7 @@ function glCreateTexture(image)
394
393
  function glDeleteTexture(texture)
395
394
  {
396
395
  if (!glContext) return;
396
+
397
397
  glContext.deleteTexture(texture);
398
398
  }
399
399
 
@@ -478,8 +478,7 @@ function glFlush()
478
478
  * @memberof WebGL */
479
479
  function glCopyToContext(context)
480
480
  {
481
- if (!glEnable || !glContext)
482
- return;
481
+ if (!glEnable || !glContext) return;
483
482
 
484
483
  glFlush();
485
484
  context.drawImage(glCanvas, 0, 0);
@@ -515,7 +514,6 @@ function glDraw(x, y, sizeX, sizeY, angle=0, uv0X=0, uv0Y=0, uv1X=1, uv1Y=1, rgb
515
514
  glFlush();
516
515
  glSetInstancedMode();
517
516
 
518
- glPolyMode = false;
519
517
  let offset = glBatchCount++ * gl_INDICES_PER_INSTANCE;
520
518
  glPositionData[offset++] = x;
521
519
  glPositionData[offset++] = y;