littlejsengine 1.15.8 → 1.16.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 (53) hide show
  1. package/dist/littlejs.d.ts +87 -85
  2. package/dist/littlejs.esm.js +578 -532
  3. package/dist/littlejs.esm.min.js +1 -1
  4. package/dist/littlejs.js +562 -521
  5. package/dist/littlejs.min.js +1 -1
  6. package/dist/littlejs.release.js +485 -444
  7. package/examples/box2d/game.js +2 -2
  8. package/examples/breakout/game.js +3 -3
  9. package/examples/electron/game.js +1 -2
  10. package/examples/electron/index.html +2 -2
  11. package/examples/htmlMenu/game.js +0 -1
  12. package/examples/index.html +1 -1
  13. package/examples/module/game.js +1 -2
  14. package/examples/particles/index.html +1 -1
  15. package/examples/platformer/game.js +11 -4
  16. package/examples/puzzle/game.js +2 -2
  17. package/examples/shorts/base.html +3 -4
  18. package/examples/shorts/box2dPool.js +2 -2
  19. package/examples/shorts/empty.js +1 -1
  20. package/examples/shorts/{systemFont.js → fontImage.js} +3 -3
  21. package/examples/shorts/fps.js +1 -1
  22. package/examples/shorts/helloWorld.js +2 -2
  23. package/examples/shorts/nineSlice.js +2 -2
  24. package/examples/shorts/slidingPuzzle.js +1 -1
  25. package/examples/shorts/uiSystem.js +1 -1
  26. package/examples/starter/game.js +1 -2
  27. package/examples/starter/index.html +2 -3
  28. package/examples/stress/index.html +1 -1
  29. package/examples/typescript/game.js +1 -2
  30. package/examples/typescript/game.ts +1 -2
  31. package/examples/uiSystem/game.js +4 -7
  32. package/package.json +1 -1
  33. package/plugins/box2d.js +8 -8
  34. package/plugins/drawUtilities.js +6 -6
  35. package/plugins/postProcess.js +13 -20
  36. package/plugins/uiSystem.js +15 -3
  37. package/reference.md +4 -6
  38. package/src/engine.js +240 -53
  39. package/src/engineAudio.js +3 -3
  40. package/src/engineBuild.js +0 -1
  41. package/src/engineDebug.js +78 -78
  42. package/src/engineDraw.js +107 -109
  43. package/src/engineExport.js +16 -11
  44. package/src/engineInput.js +14 -2
  45. package/src/engineMedals.js +3 -3
  46. package/src/engineObject.js +4 -2
  47. package/src/engineParticles.js +8 -6
  48. package/src/engineRelease.js +1 -1
  49. package/src/engineSettings.js +44 -30
  50. package/src/engineTileLayer.js +6 -6
  51. package/src/engineUtilities.js +2 -10
  52. package/src/engineWebGL.js +6 -5
  53. package/src/engineSplash.js +0 -173
@@ -26,7 +26,7 @@ const debugPointSize = .5;
26
26
  * @type {boolean}
27
27
  * @default
28
28
  * @memberof Debug */
29
- let showWatermark = true;
29
+ let debugWatermark = true;
30
30
 
31
31
  /** Key code used to toggle debug mode, Esc by default
32
32
  * @type {string}
@@ -312,12 +312,19 @@ function debugUpdate()
312
312
  if (!debug)
313
313
  return;
314
314
 
315
+ if (debugVideoCaptureIsActive())
316
+ {
317
+ // control to stop video capture
318
+ if (keyWasPressed('Digit6') || keyWasPressed(debugKey))
319
+ debugVideoCaptureStop();
320
+ }
321
+
315
322
  if (keyWasPressed(debugKey)) // Esc
316
323
  debugOverlay = !debugOverlay;
317
324
  if (debugOverlay)
318
325
  {
319
326
  if (keyWasPressed('Digit0'))
320
- showWatermark = !showWatermark;
327
+ debugWatermark = !debugWatermark;
321
328
  if (keyWasPressed('Digit1'))
322
329
  debugPhysics = !debugPhysics, debugParticles = false;
323
330
  if (keyWasPressed('Digit2'))
@@ -328,8 +335,8 @@ function debugUpdate()
328
335
  debugRaycast = !debugRaycast;
329
336
  if (keyWasPressed('Digit5'))
330
337
  debugScreenshot();
331
- if (keyWasPressed('Digit6'))
332
- debugVideoCaptureIsActive() ? debugVideoCaptureStop() : debugVideoCaptureStart();
338
+ if (keyWasPressed('Digit6') && !debugVideoCaptureIsActive())
339
+ debugVideoCaptureStart();
333
340
  }
334
341
  }
335
342
 
@@ -345,13 +352,11 @@ function debugRender()
345
352
  {
346
353
  // combine canvases, remove alpha and save
347
354
  combineCanvases();
348
- const w = mainCanvas.width, h = mainCanvas.height;
349
- overlayContext.fillRect(0,0,w,h);
350
- overlayContext.drawImage(mainCanvas, 0, 0);
351
- debugSaveCanvas(overlayCanvas);
355
+ debugSaveCanvas(mainCanvas);
352
356
  debugTakeScreenshot = 0;
353
357
  }
354
358
 
359
+ const debugContext = mainContext;
355
360
  if (debugGamepads && gamepadsEnable)
356
361
  {
357
362
  // draw gamepads
@@ -399,9 +404,6 @@ function debugRender()
399
404
  let debugObject;
400
405
  if (debugOverlay)
401
406
  {
402
- const saveContext = mainContext;
403
- mainContext = overlayContext;
404
-
405
407
  // draw red rectangle around screen
406
408
  const cameraSize = getCameraSize();
407
409
  debugRect(cameraPos, cameraSize.subtract(vec2(.1)), '#f008');
@@ -433,15 +435,14 @@ function debugRender()
433
435
  // show floored tile pick for tile collision
434
436
  drawRect(mousePos.floor().add(vec2(.5)), vec2(1), rgb(1,1,0,.5));
435
437
  }
436
- mainContext = saveContext;
437
438
  }
438
439
 
439
440
  {
440
441
  // draw debug primitives
441
- overlayContext.lineWidth = 2;
442
+ debugContext.lineWidth = 2;
442
443
  debugPrimitives.forEach(p=>
443
444
  {
444
- overlayContext.save();
445
+ debugContext.save();
445
446
 
446
447
  // create canvas transform from world space to screen space
447
448
  // without scaling because we want consistent pixel sizes
@@ -452,55 +453,56 @@ function debugRender()
452
453
  scale = cameraScale;
453
454
  angle -= cameraAngle;
454
455
  }
455
- overlayContext.translate(pos.x|0, pos.y|0);
456
- overlayContext.rotate(angle);
457
- overlayContext.scale(1, p.text ? 1 : -1);
458
- overlayContext.fillStyle = overlayContext.strokeStyle = p.color;
456
+ debugContext.translate(pos.x|0, pos.y|0);
457
+ debugContext.rotate(angle);
458
+ debugContext.scale(1, p.text ? 1 : -1);
459
+ debugContext.fillStyle = p.color;
460
+ debugContext.strokeStyle = p.color;
459
461
  if (p.text !== undefined)
460
462
  {
461
- overlayContext.font = p.size*scale + 'px '+ p.font;
462
- overlayContext.textAlign = 'center';
463
- overlayContext.textBaseline = 'middle';
464
- overlayContext.fillText(p.text, 0, 0);
463
+ debugContext.font = p.size*scale + 'px '+ p.font;
464
+ debugContext.textAlign = 'center';
465
+ debugContext.textBaseline = 'middle';
466
+ debugContext.fillText(p.text, 0, 0);
465
467
  }
466
468
  else if (p.points !== undefined)
467
469
  {
468
470
  // poly
469
- overlayContext.beginPath();
471
+ debugContext.beginPath();
470
472
  for (const point of p.points)
471
473
  {
472
474
  const p2 = point.scale(scale).floor();
473
- overlayContext.lineTo(p2.x, p2.y);
475
+ debugContext.lineTo(p2.x, p2.y);
474
476
  }
475
- overlayContext.closePath();
476
- p.fill && overlayContext.fill();
477
- overlayContext.stroke();
477
+ debugContext.closePath();
478
+ p.fill && debugContext.fill();
479
+ debugContext.stroke();
478
480
  }
479
481
  else if (p.size === 0 || (p.size.x === 0 && p.size.y === 0))
480
482
  {
481
483
  // point
482
484
  const pointSize = debugPointSize * scale;
483
- overlayContext.fillRect(-pointSize/2, -1, pointSize, 3);
484
- overlayContext.fillRect(-1, -pointSize/2, 3, pointSize);
485
+ debugContext.fillRect(-pointSize/2, -1, pointSize, 3);
486
+ debugContext.fillRect(-1, -pointSize/2, 3, pointSize);
485
487
  }
486
488
  else if (p.size.x !== undefined)
487
489
  {
488
490
  // rect
489
491
  const s = p.size.scale(scale).floor();
490
492
  const w = s.x, h = s.y;
491
- p.fill && overlayContext.fillRect(-w/2|0, -h/2|0, w, h);
492
- overlayContext.strokeRect(-w/2|0, -h/2|0, w, h);
493
+ p.fill && debugContext.fillRect(-w/2|0, -h/2|0, w, h);
494
+ debugContext.strokeRect(-w/2|0, -h/2|0, w, h);
493
495
  }
494
496
  else
495
497
  {
496
498
  // circle
497
- overlayContext.beginPath();
498
- overlayContext.arc(0, 0, p.size*scale/2, 0, 9);
499
- p.fill && overlayContext.fill();
500
- overlayContext.stroke();
499
+ debugContext.beginPath();
500
+ debugContext.arc(0, 0, p.size*scale/2, 0, 9);
501
+ p.fill && debugContext.fill();
502
+ debugContext.stroke();
501
503
  }
502
504
 
503
- overlayContext.restore();
505
+ debugContext.restore();
504
506
  });
505
507
 
506
508
  // remove expired primitives
@@ -509,55 +511,53 @@ function debugRender()
509
511
 
510
512
  if (debugObject)
511
513
  {
512
- const saveContext = mainContext;
513
- mainContext = overlayContext;
514
514
  const raycastHitPos = tileCollisionRaycast(debugObject.pos, mousePos);
515
515
  raycastHitPos && drawRect(raycastHitPos.floor().add(vec2(.5)), vec2(1), rgb(0,1,1,.3));
516
516
  drawLine(mousePos, debugObject.pos, .1, raycastHitPos ? rgb(1,0,0,.5) : rgb(0,1,0,.5));
517
517
 
518
- const debugText = 'mouse pos = ' + mousePos +
519
- '\nmouse collision = ' + tileCollisionGetData(mousePos) +
520
- '\n\n--- object info ---\n' +
521
- debugObject.toString();
518
+ let debugText = 'mouse pos = ' + mousePos;
519
+ if (tileCollisionLayers.length)
520
+ debugText += '\nmouse collision = ' + tileCollisionGetData(mousePos);
521
+ debugText += '\n\n--- object info ---\n';
522
+ debugText += debugObject.toString();
522
523
  drawTextScreen(debugText, mousePosScreen, 24, rgb(), .05, undefined, 'center', 'monospace');
523
- mainContext = saveContext;
524
524
  }
525
525
 
526
526
  {
527
527
  // draw debug overlay
528
528
  const fontSize = 20;
529
529
  const lineHeight = fontSize * 1.2 | 0;
530
- overlayContext.save();
531
- overlayContext.fillStyle = '#fff';
532
- overlayContext.textAlign = 'left';
533
- overlayContext.textBaseline = 'top';
534
- overlayContext.font = fontSize + 'px monospace';
535
- overlayContext.shadowColor = '#000';
536
- overlayContext.shadowBlur = 9;
530
+ debugContext.save();
531
+ debugContext.fillStyle = '#fff';
532
+ debugContext.textAlign = 'left';
533
+ debugContext.textBaseline = 'top';
534
+ debugContext.font = fontSize + 'px monospace';
535
+ debugContext.shadowColor = '#000';
536
+ debugContext.shadowBlur = 9;
537
537
 
538
538
  let x = 9, y = 0, h = lineHeight;
539
539
  if (debugOverlay)
540
540
  {
541
- overlayContext.fillText(`${engineName} v${engineVersion}`, x, y += h/2 );
542
- overlayContext.fillText('Time: ' + formatTime(time), x, y += h);
543
- overlayContext.fillText('FPS: ' + averageFPS.toFixed(1) + (glEnable?' WebGL':' Canvas2D'),
541
+ debugContext.fillText(`${engineName} v${engineVersion}`, x, y += h/2 );
542
+ debugContext.fillText('Time: ' + formatTime(time), x, y += h);
543
+ debugContext.fillText('FPS: ' + averageFPS.toFixed(1) + (glEnable?' WebGL':' Canvas2D'),
544
544
  x, y += h);
545
- overlayContext.fillText('Objects: ' + engineObjects.length, x, y += h);
546
- overlayContext.fillText('Draw Count: ' + drawCount, x, y += h);
547
- overlayContext.fillText('---------', x, y += h);
548
- overlayContext.fillStyle = '#f00';
549
- overlayContext.fillText('ESC: Debug Overlay', x, y += h);
550
- overlayContext.fillStyle = debugPhysics ? '#f00' : '#fff';
551
- overlayContext.fillText('1: Debug Physics', x, y += h);
552
- overlayContext.fillStyle = debugParticles ? '#f00' : '#fff';
553
- overlayContext.fillText('2: Debug Particles', x, y += h);
554
- overlayContext.fillStyle = debugGamepads ? '#f00' : '#fff';
555
- overlayContext.fillText('3: Debug Gamepads', x, y += h);
556
- overlayContext.fillStyle = debugRaycast ? '#f00' : '#fff';
557
- overlayContext.fillText('4: Debug Raycasts', x, y += h);
558
- overlayContext.fillStyle = '#fff';
559
- overlayContext.fillText('5: Save Screenshot', x, y += h);
560
- overlayContext.fillText('6: Toggle Video Capture', x, y += h);
545
+ debugContext.fillText('Objects: ' + engineObjects.length, x, y += h);
546
+ debugContext.fillText('Draw Count: ' + drawCount, x, y += h);
547
+ debugContext.fillText('---------', x, y += h);
548
+ debugContext.fillStyle = '#f00';
549
+ debugContext.fillText('ESC: Debug Overlay', x, y += h);
550
+ debugContext.fillStyle = debugPhysics ? '#f00' : '#fff';
551
+ debugContext.fillText('1: Debug Physics', x, y += h);
552
+ debugContext.fillStyle = debugParticles ? '#f00' : '#fff';
553
+ debugContext.fillText('2: Debug Particles', x, y += h);
554
+ debugContext.fillStyle = debugGamepads ? '#f00' : '#fff';
555
+ debugContext.fillText('3: Debug Gamepads', x, y += h);
556
+ debugContext.fillStyle = debugRaycast ? '#f00' : '#fff';
557
+ debugContext.fillText('4: Debug Raycasts', x, y += h);
558
+ debugContext.fillStyle = '#fff';
559
+ debugContext.fillText('5: Save Screenshot', x, y += h);
560
+ debugContext.fillText('6: Toggle Video Capture', x, y += h);
561
561
 
562
562
  let keysPressed = '';
563
563
  let mousePressed = '';
@@ -570,8 +570,8 @@ function debugRender()
570
570
  else if (keyIsDown(i, 0))
571
571
  keysPressed += i + ' ' ;
572
572
  }
573
- mousePressed && overlayContext.fillText('Mouse: ' + mousePressed, x, y += h);
574
- keysPressed && overlayContext.fillText('Keys: ' + keysPressed, x, y += h);
573
+ mousePressed && debugContext.fillText('Mouse: ' + mousePressed, x, y += h);
574
+ keysPressed && debugContext.fillText('Keys: ' + keysPressed, x, y += h);
575
575
 
576
576
  // show gamepad buttons
577
577
  for (let i = 1; i < inputData.length; i++)
@@ -583,18 +583,18 @@ function debugRender()
583
583
  if (keyIsDown(j, i))
584
584
  buttonsPressed += j + ' ' ;
585
585
  }
586
- buttonsPressed && overlayContext.fillText(`Gamepad ${i-1}: ` + buttonsPressed, x, y += h);
586
+ buttonsPressed && debugContext.fillText(`Gamepad ${i-1}: ` + buttonsPressed, x, y += h);
587
587
  }
588
588
  }
589
589
  else
590
590
  {
591
- overlayContext.fillText(debugPhysics ? 'Debug Physics' : '', x, y += h);
592
- overlayContext.fillText(debugParticles ? 'Debug Particles' : '', x, y += h);
593
- overlayContext.fillText(debugRaycast ? 'Debug Raycasts' : '', x, y += h);
594
- overlayContext.fillText(debugGamepads ? 'Debug Gamepads' : '', x, y += h);
591
+ debugContext.fillText(debugPhysics ? 'Debug Physics' : '', x, y += h);
592
+ debugContext.fillText(debugParticles ? 'Debug Particles' : '', x, y += h);
593
+ debugContext.fillText(debugRaycast ? 'Debug Raycasts' : '', x, y += h);
594
+ debugContext.fillText(debugGamepads ? 'Debug Gamepads' : '', x, y += h);
595
595
  }
596
596
 
597
- overlayContext.restore();
597
+ debugContext.restore();
598
598
  }
599
599
  }
600
600
 
@@ -645,7 +645,7 @@ function debugVideoCaptureStart()
645
645
  // start recording
646
646
  LOG('Video capture started.');
647
647
  debugVideoCapture.start();
648
- debugVideoCaptureTimer = new Timer(0);
648
+ debugVideoCaptureTimer = new Timer(0, true);
649
649
 
650
650
  if (!debugVideoCaptureIcon)
651
651
  {