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.
- package/dist/littlejs.d.ts +154 -158
- package/dist/littlejs.esm.js +573 -570
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +553 -553
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +392 -396
- package/examples/box2d/game.js +1 -1
- package/examples/box2d/gameObjects.js +5 -5
- 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/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/game.js +1 -2
- package/examples/particles/index.html +1 -1
- package/examples/platformer/game.js +4 -4
- package/examples/platformer/gameEffects.js +1 -1
- package/examples/puzzle/game.js +2 -2
- package/examples/shorts/base.html +4 -3
- 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/starter/game.js +1 -2
- package/examples/starter/index.html +3 -2
- package/examples/stress/index.html +1 -1
- package/examples/typescript/game.js +1 -2
- package/examples/typescript/game.ts +1 -2
- 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 +16 -4
- package/reference.md +9 -11
- package/src/engine.js +40 -54
- package/src/engineAudio.js +5 -7
- package/src/engineBuild.js +1 -0
- package/src/engineDebug.js +163 -161
- package/src/engineDraw.js +108 -130
- package/src/engineExport.js +20 -17
- package/src/engineInput.js +4 -7
- package/src/engineMath.js +1201 -0
- package/src/engineMedals.js +7 -7
- package/src/engineObject.js +5 -4
- package/src/engineRelease.js +2 -4
- package/src/engineSettings.js +22 -32
- package/src/engineTileLayer.js +9 -10
- package/src/engineUtilities.js +34 -1187
- package/src/engineWebGL.js +13 -15
package/src/engineMedals.js
CHANGED
|
@@ -32,10 +32,11 @@ function medalsInit(saveName)
|
|
|
32
32
|
|
|
33
33
|
// engine automatically renders medals
|
|
34
34
|
engineAddPlugin(undefined, medalsRender);
|
|
35
|
+
|
|
36
|
+
// plugin functions
|
|
35
37
|
function medalsRender()
|
|
36
38
|
{
|
|
37
|
-
if (!medalsDisplayQueue.length)
|
|
38
|
-
return;
|
|
39
|
+
if (!medalsDisplayQueue.length) return;
|
|
39
40
|
|
|
40
41
|
// update first medal in queue
|
|
41
42
|
const medal = medalsDisplayQueue[0];
|
|
@@ -125,8 +126,7 @@ class Medal
|
|
|
125
126
|
/** Unlocks a medal if not already unlocked */
|
|
126
127
|
unlock()
|
|
127
128
|
{
|
|
128
|
-
if (medalsPreventUnlock || this.unlocked)
|
|
129
|
-
return;
|
|
129
|
+
if (medalsPreventUnlock || this.unlocked) return;
|
|
130
130
|
|
|
131
131
|
// save the medal
|
|
132
132
|
ASSERT(medalsSaveName, 'save name must be set');
|
|
@@ -139,10 +139,10 @@ class Medal
|
|
|
139
139
|
*/
|
|
140
140
|
render(hidePercent=0)
|
|
141
141
|
{
|
|
142
|
-
const context =
|
|
142
|
+
const context = mainContext;
|
|
143
143
|
const width = min(medalDisplaySize.x, mainCanvas.width);
|
|
144
144
|
const height = medalDisplaySize.y;
|
|
145
|
-
const x =
|
|
145
|
+
const x = mainCanvas.width - width;
|
|
146
146
|
const y = -height*hidePercent;
|
|
147
147
|
const backgroundColor = hsl(0,0,.9);
|
|
148
148
|
|
|
@@ -183,7 +183,7 @@ class Medal
|
|
|
183
183
|
{
|
|
184
184
|
// draw the image or icon
|
|
185
185
|
if (this.image)
|
|
186
|
-
|
|
186
|
+
mainContext.drawImage(this.image, pos.x-size/2, pos.y-size/2, size, size);
|
|
187
187
|
else
|
|
188
188
|
drawTextScreen(this.icon, pos, size*.7, BLACK);
|
|
189
189
|
}
|
package/src/engineObject.js
CHANGED
|
@@ -430,10 +430,11 @@ class EngineObject
|
|
|
430
430
|
* @return {number} -1 if this.mirror is true, or 1 if not mirrored */
|
|
431
431
|
getMirrorSign() { return this.mirror ? -1 : 1; }
|
|
432
432
|
|
|
433
|
-
/** Attaches a child to this with a
|
|
433
|
+
/** Attaches a child to this with a local transform, returns child for chaining
|
|
434
434
|
* @param {EngineObject} child
|
|
435
435
|
* @param {Vector2} [localPos=(0,0)]
|
|
436
|
-
* @param {number} [localAngle]
|
|
436
|
+
* @param {number} [localAngle]
|
|
437
|
+
* @return {EngineObject} The child object added */
|
|
437
438
|
addChild(child, localPos=vec2(), localAngle=0)
|
|
438
439
|
{
|
|
439
440
|
ASSERT(!child.parent && !this.children.includes(child));
|
|
@@ -443,6 +444,7 @@ class EngineObject
|
|
|
443
444
|
child.parent = this;
|
|
444
445
|
child.localPos = localPos.copy();
|
|
445
446
|
child.localAngle = localAngle;
|
|
447
|
+
return child;
|
|
446
448
|
}
|
|
447
449
|
|
|
448
450
|
/** Removes a child from this one
|
|
@@ -509,8 +511,7 @@ class EngineObject
|
|
|
509
511
|
/** Render debug info for this object */
|
|
510
512
|
renderDebugInfo()
|
|
511
513
|
{
|
|
512
|
-
if (!debug)
|
|
513
|
-
return;
|
|
514
|
+
if (!debug) return;
|
|
514
515
|
|
|
515
516
|
// show object info for debugging
|
|
516
517
|
const size = vec2(max(this.size.x, .2), max(this.size.y, .2));
|
package/src/engineRelease.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
let
|
|
9
|
+
let debugWatermark = 0;
|
|
10
10
|
let debugKey = '';
|
|
11
11
|
const debug = 0;
|
|
12
12
|
const debugOverlay = 0;
|
|
@@ -22,6 +22,7 @@ function LOG (){}
|
|
|
22
22
|
function debugInit (){}
|
|
23
23
|
function debugUpdate (){}
|
|
24
24
|
function debugRender (){}
|
|
25
|
+
function debugRenderPost (){}
|
|
25
26
|
function debugRect (){}
|
|
26
27
|
function debugPoly (){}
|
|
27
28
|
function debugCircle (){}
|
|
@@ -31,9 +32,6 @@ function debugOverlap (){}
|
|
|
31
32
|
function debugText (){}
|
|
32
33
|
function debugClear (){}
|
|
33
34
|
function debugScreenshot (){}
|
|
34
|
-
function debugSaveCanvas (){}
|
|
35
|
-
function debugSaveText (){}
|
|
36
|
-
function debugSaveDataURL(){}
|
|
37
35
|
function debugShowErrors(){}
|
|
38
36
|
function debugVideoCaptureIsActive(){ return false; }
|
|
39
37
|
function debugVideoCaptureStart (){}
|
package/src/engineSettings.js
CHANGED
|
@@ -37,7 +37,7 @@ let cameraScale = 32;
|
|
|
37
37
|
* @memberof Settings */
|
|
38
38
|
let canvasColorTiles = true;
|
|
39
39
|
|
|
40
|
-
/** Color to clear the canvas to before render
|
|
40
|
+
/** Color to clear the canvas to before render, does not clear if alpha is 0
|
|
41
41
|
* @type {Color}
|
|
42
42
|
* @memberof Draw */
|
|
43
43
|
let canvasClearColor = CLEAR_BLACK;
|
|
@@ -74,15 +74,7 @@ let canvasFixedSize = vec2();
|
|
|
74
74
|
* @type {boolean}
|
|
75
75
|
* @default
|
|
76
76
|
* @memberof Settings */
|
|
77
|
-
let canvasPixelated =
|
|
78
|
-
|
|
79
|
-
/** Use nearest canvas scaling for more pixelated look
|
|
80
|
-
* - If enabled sets css image-rendering:pixelated
|
|
81
|
-
* - This defaults to false because text looks better with smoothing
|
|
82
|
-
* @type {boolean}
|
|
83
|
-
* @default
|
|
84
|
-
* @memberof Settings */
|
|
85
|
-
let overlayCanvasPixelated = false;
|
|
77
|
+
let canvasPixelated = false;
|
|
86
78
|
|
|
87
79
|
/** Disables texture filtering for crisper pixel art
|
|
88
80
|
* @type {boolean}
|
|
@@ -130,13 +122,19 @@ let glCircleSides = 32;
|
|
|
130
122
|
* @type {Vector2}
|
|
131
123
|
* @default Vector2(16,16)
|
|
132
124
|
* @memberof Settings */
|
|
133
|
-
let
|
|
125
|
+
let tileDefaultSize = vec2(16);
|
|
134
126
|
|
|
135
|
-
/**
|
|
127
|
+
/** Default padding pixels around tiles
|
|
136
128
|
* @type {number}
|
|
137
129
|
* @default
|
|
138
130
|
* @memberof Settings */
|
|
139
|
-
let
|
|
131
|
+
let tileDefaultPadding = 0;
|
|
132
|
+
|
|
133
|
+
/** Default amount of pixels smaller to draw tiles to prevent neighbor bleeding
|
|
134
|
+
* @type {number}
|
|
135
|
+
* @default
|
|
136
|
+
* @memberof Settings */
|
|
137
|
+
let tileDefaultBleed = 0;
|
|
140
138
|
|
|
141
139
|
///////////////////////////////////////////////////////////////////////////////
|
|
142
140
|
// Object settings
|
|
@@ -348,7 +346,7 @@ function setCameraScale(scale) { cameraScale = scale; }
|
|
|
348
346
|
* @memberof Settings */
|
|
349
347
|
function setCanvasColorTiles(colorTiles) { canvasColorTiles = colorTiles; }
|
|
350
348
|
|
|
351
|
-
/** Set color to clear the canvas to before render
|
|
349
|
+
/** Set color to clear the canvas to before render, does not clear if alpha is 0
|
|
352
350
|
* @param {Color} color
|
|
353
351
|
* @memberof Settings */
|
|
354
352
|
function setCanvasClearColor(color) { canvasClearColor = color.copy(); }
|
|
@@ -374,7 +372,6 @@ function setCanvasMaxAspect(aspect) { canvasMaxAspect = aspect; }
|
|
|
374
372
|
function setCanvasFixedSize(size) { canvasFixedSize = size.copy(); }
|
|
375
373
|
|
|
376
374
|
/** Use nearest scaling algorithm for canvas for more pixelated look
|
|
377
|
-
* - If enabled sets css image-rendering:pixelated
|
|
378
375
|
* @param {boolean} pixelated
|
|
379
376
|
* @memberof Settings */
|
|
380
377
|
function setCanvasPixelated(pixelated)
|
|
@@ -386,18 +383,6 @@ function setCanvasPixelated(pixelated)
|
|
|
386
383
|
glCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
|
|
387
384
|
}
|
|
388
385
|
|
|
389
|
-
/** Use nearest scaling algorithm for canvas for more pixelated look
|
|
390
|
-
* - If enabled sets css image-rendering:pixelated
|
|
391
|
-
* - This defaults to false because text looks better with smoothing
|
|
392
|
-
* @param {boolean} pixelated
|
|
393
|
-
* @memberof Settings */
|
|
394
|
-
function setOverlayCanvasPixelated(pixelated)
|
|
395
|
-
{
|
|
396
|
-
overlayCanvasPixelated = pixelated;
|
|
397
|
-
if (overlayCanvas)
|
|
398
|
-
overlayCanvas.style.imageRendering = pixelated ? 'pixelated' : '';
|
|
399
|
-
}
|
|
400
|
-
|
|
401
386
|
/** Disables texture filtering for crisper pixel art
|
|
402
387
|
* @param {boolean} pixelated
|
|
403
388
|
* @memberof Settings */
|
|
@@ -441,12 +426,17 @@ function setGLCircleSides(sides) { glCircleSides = sides; }
|
|
|
441
426
|
/** Set default size of tiles in pixels
|
|
442
427
|
* @param {Vector2} size
|
|
443
428
|
* @memberof Settings */
|
|
444
|
-
function
|
|
429
|
+
function setTileDefaultSize(size) { tileDefaultSize = size.copy(); }
|
|
445
430
|
|
|
446
|
-
/**
|
|
447
|
-
* @param {number}
|
|
431
|
+
/** Default padding pixels around tiles
|
|
432
|
+
* @param {number} padding
|
|
433
|
+
* @memberof Settings */
|
|
434
|
+
function setTileDefaultPadding(padding) { tileDefaultPadding = padding; }
|
|
435
|
+
|
|
436
|
+
/** Default amount of pixels smaller to draw tiles to prevent neighbor bleeding
|
|
437
|
+
* @param {number} bleed
|
|
448
438
|
* @memberof Settings */
|
|
449
|
-
function
|
|
439
|
+
function setTileDefaultBleed(bleed) { tileDefaultBleed = bleed; }
|
|
450
440
|
|
|
451
441
|
/** Set if collisions between objects are enabled
|
|
452
442
|
* @param {boolean} enable
|
|
@@ -597,7 +587,7 @@ function setMedalsPreventUnlock(preventUnlock) { medalsPreventUnlock = preventUn
|
|
|
597
587
|
/** Set if watermark with FPS should be shown
|
|
598
588
|
* @param {boolean} show
|
|
599
589
|
* @memberof Debug */
|
|
600
|
-
function
|
|
590
|
+
function setDebugWatermark(show) { debugWatermark = show; }
|
|
601
591
|
|
|
602
592
|
/** Set key code used to toggle debug mode, Esc by default
|
|
603
593
|
* @param {string} key
|
package/src/engineTileLayer.js
CHANGED
|
@@ -443,26 +443,26 @@ class TileLayer extends CanvasLayer
|
|
|
443
443
|
if (!this.context) return;
|
|
444
444
|
|
|
445
445
|
// save current render settings
|
|
446
|
-
/** @type {[
|
|
447
|
-
this.savedRenderSettings = [
|
|
446
|
+
/** @type {[CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D, Vector2, Vector2, number, Color]} */
|
|
447
|
+
this.savedRenderSettings = [drawContext, mainCanvasSize, cameraPos, cameraScale, canvasClearColor];
|
|
448
448
|
|
|
449
449
|
// set the draw canvas and context to this layer
|
|
450
450
|
// use camera settings to match this layer's canvas
|
|
451
|
-
drawCanvas = this.canvas;
|
|
452
451
|
drawContext = this.context;
|
|
453
452
|
cameraPos = this.size.scale(.5);
|
|
454
453
|
const tileSize = this.tileInfo ? this.tileInfo.size : vec2(1);
|
|
455
454
|
cameraScale = tileSize.x;
|
|
455
|
+
canvasClearColor = CLEAR_BLACK;
|
|
456
456
|
mainCanvasSize = this.size.multiply(tileSize);
|
|
457
457
|
if (clear)
|
|
458
458
|
{
|
|
459
459
|
// clear and set size
|
|
460
|
-
|
|
461
|
-
|
|
460
|
+
this.canvas.width = mainCanvasSize.x;
|
|
461
|
+
this.canvas.height = mainCanvasSize.y;
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
// disable smoothing for pixel art
|
|
465
|
-
|
|
465
|
+
drawContext.imageSmoothingEnabled = !tilesPixelated;
|
|
466
466
|
|
|
467
467
|
// setup gl rendering if enabled
|
|
468
468
|
glPreRender();
|
|
@@ -475,10 +475,10 @@ class TileLayer extends CanvasLayer
|
|
|
475
475
|
|
|
476
476
|
ASSERT(drawContext === this.context, 'must call redrawStart() before drawing tiles');
|
|
477
477
|
glCopyToContext(drawContext);
|
|
478
|
-
//
|
|
478
|
+
//saveCanvas(this.canvas);
|
|
479
479
|
|
|
480
480
|
// set stuff back to normal
|
|
481
|
-
[
|
|
481
|
+
[drawContext, mainCanvasSize, cameraPos, cameraScale, canvasClearColor] = this.savedRenderSettings;
|
|
482
482
|
}
|
|
483
483
|
|
|
484
484
|
/** Draw the tile at a given position in the tile grid
|
|
@@ -546,8 +546,7 @@ class TileCollisionLayer extends TileLayer
|
|
|
546
546
|
/** Destroy this tile layer */
|
|
547
547
|
destroy()
|
|
548
548
|
{
|
|
549
|
-
if (this.destroyed)
|
|
550
|
-
return;
|
|
549
|
+
if (this.destroyed) return;
|
|
551
550
|
|
|
552
551
|
// remove from collision layers array and destroy
|
|
553
552
|
const index = tileCollisionLayers.indexOf(this);
|