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.
- package/dist/littlejs.d.ts +87 -85
- package/dist/littlejs.esm.js +578 -532
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +562 -521
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +485 -444
- package/examples/box2d/game.js +2 -2
- package/examples/breakout/game.js +3 -3
- package/examples/electron/game.js +1 -2
- package/examples/electron/index.html +2 -2
- package/examples/htmlMenu/game.js +0 -1
- package/examples/index.html +1 -1
- package/examples/module/game.js +1 -2
- package/examples/particles/index.html +1 -1
- package/examples/platformer/game.js +11 -4
- package/examples/puzzle/game.js +2 -2
- package/examples/shorts/base.html +3 -4
- package/examples/shorts/box2dPool.js +2 -2
- package/examples/shorts/empty.js +1 -1
- package/examples/shorts/{systemFont.js → fontImage.js} +3 -3
- package/examples/shorts/fps.js +1 -1
- package/examples/shorts/helloWorld.js +2 -2
- package/examples/shorts/nineSlice.js +2 -2
- package/examples/shorts/slidingPuzzle.js +1 -1
- package/examples/shorts/uiSystem.js +1 -1
- package/examples/starter/game.js +1 -2
- package/examples/starter/index.html +2 -3
- package/examples/stress/index.html +1 -1
- package/examples/typescript/game.js +1 -2
- package/examples/typescript/game.ts +1 -2
- package/examples/uiSystem/game.js +4 -7
- package/package.json +1 -1
- package/plugins/box2d.js +8 -8
- package/plugins/drawUtilities.js +6 -6
- package/plugins/postProcess.js +13 -20
- package/plugins/uiSystem.js +15 -3
- package/reference.md +4 -6
- package/src/engine.js +240 -53
- package/src/engineAudio.js +3 -3
- package/src/engineBuild.js +0 -1
- package/src/engineDebug.js +78 -78
- package/src/engineDraw.js +107 -109
- package/src/engineExport.js +16 -11
- package/src/engineInput.js +14 -2
- package/src/engineMedals.js +3 -3
- package/src/engineObject.js +4 -2
- package/src/engineParticles.js +8 -6
- package/src/engineRelease.js +1 -1
- package/src/engineSettings.js +44 -30
- package/src/engineTileLayer.js +6 -6
- package/src/engineUtilities.js +2 -10
- package/src/engineWebGL.js +6 -5
- package/src/engineSplash.js +0 -173
package/src/engineDebug.js
CHANGED
|
@@ -26,7 +26,7 @@ const debugPointSize = .5;
|
|
|
26
26
|
* @type {boolean}
|
|
27
27
|
* @default
|
|
28
28
|
* @memberof Debug */
|
|
29
|
-
let
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
442
|
+
debugContext.lineWidth = 2;
|
|
442
443
|
debugPrimitives.forEach(p=>
|
|
443
444
|
{
|
|
444
|
-
|
|
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
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
471
|
+
debugContext.beginPath();
|
|
470
472
|
for (const point of p.points)
|
|
471
473
|
{
|
|
472
474
|
const p2 = point.scale(scale).floor();
|
|
473
|
-
|
|
475
|
+
debugContext.lineTo(p2.x, p2.y);
|
|
474
476
|
}
|
|
475
|
-
|
|
476
|
-
p.fill &&
|
|
477
|
-
|
|
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
|
-
|
|
484
|
-
|
|
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 &&
|
|
492
|
-
|
|
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
|
-
|
|
498
|
-
|
|
499
|
-
p.fill &&
|
|
500
|
-
|
|
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
|
-
|
|
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
|
-
|
|
519
|
-
|
|
520
|
-
'\
|
|
521
|
-
|
|
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
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
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
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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 &&
|
|
574
|
-
keysPressed &&
|
|
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 &&
|
|
586
|
+
buttonsPressed && debugContext.fillText(`Gamepad ${i-1}: ` + buttonsPressed, x, y += h);
|
|
587
587
|
}
|
|
588
588
|
}
|
|
589
589
|
else
|
|
590
590
|
{
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
|
|
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
|
{
|