littlejsengine 1.16.1 → 1.17.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 +287 -240
- package/dist/littlejs.esm.js +1419 -1259
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +1076 -910
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +977 -815
- package/examples/box2d/gameObjects.js +6 -6
- package/examples/breakout/game.js +5 -6
- package/examples/electron/index.html +2 -2
- package/examples/electron/tiles.png +0 -0
- package/examples/htmlMenu/tiles.png +0 -0
- package/examples/index.html +1 -1
- package/examples/logo.png +0 -0
- package/examples/logo2.png +0 -0
- package/examples/module/tiles.png +0 -0
- package/examples/platformer/gameEffects.js +24 -23
- package/examples/platformer/gameLevel.js +24 -25
- package/examples/shorts/base.html +2 -1
- package/examples/shorts/clock.js +3 -3
- package/examples/shorts/fontImage.js +4 -3
- package/examples/shorts/parallax.js +1 -1
- package/examples/shorts/sequencer.js +1 -1
- package/examples/shorts/shapes.js +1 -1
- package/examples/shorts/texture.js +10 -6
- package/examples/shorts/tiles.png +0 -0
- package/examples/shorts/tiltedView.js +2 -0
- package/examples/starter/index.html +3 -2
- package/examples/starter/tiles.png +0 -0
- package/examples/typescript/tiles.png +0 -0
- package/examples/uiSystem/game.js +1 -1
- package/examples/uiSystem/tiles.png +0 -0
- package/package.json +1 -1
- package/plugins/postProcess.js +47 -28
- package/plugins/uiSystem.js +16 -16
- package/reference.md +6 -6
- package/src/engine.js +186 -198
- package/src/engineAudio.js +6 -10
- package/src/engineBuild.js +1 -0
- package/src/engineDebug.js +100 -98
- package/src/engineDraw.js +185 -148
- package/src/engineExport.js +327 -333
- package/src/engineFont.png +0 -0
- package/src/engineInput.js +17 -26
- package/src/engineMath.js +1112 -0
- package/src/engineMedals.js +4 -4
- package/src/engineObject.js +27 -27
- package/src/engineParticles.js +2 -2
- package/src/engineRelease.js +1 -3
- package/src/engineSettings.js +2 -2
- package/src/engineTileLayer.js +200 -176
- package/src/engineUtilities.js +48 -1097
- package/src/engineWebGL.js +127 -79
package/src/engineInput.js
CHANGED
|
@@ -55,6 +55,10 @@ let inputPreventDefault = true;
|
|
|
55
55
|
* @memberof Input */
|
|
56
56
|
let gamepadPrimary = 0;
|
|
57
57
|
|
|
58
|
+
/** True if a touch device has been detected
|
|
59
|
+
* @memberof Input */
|
|
60
|
+
const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
|
|
61
|
+
|
|
58
62
|
/** Prevents input continuing to the default browser handling
|
|
59
63
|
* This is useful to disable for html menus so the browser can handle input normally
|
|
60
64
|
* @param {boolean} preventDefault
|
|
@@ -253,10 +257,6 @@ function gamepadStickCount(gamepad=gamepadPrimary)
|
|
|
253
257
|
return gamepadStickData[gamepad]?.length ?? 0;
|
|
254
258
|
}
|
|
255
259
|
|
|
256
|
-
/** True if a touch device has been detected
|
|
257
|
-
* @memberof Input */
|
|
258
|
-
const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
|
|
259
|
-
|
|
260
260
|
///////////////////////////////////////////////////////////////////////////////
|
|
261
261
|
|
|
262
262
|
/** Pulse the vibration hardware if it exists
|
|
@@ -265,7 +265,7 @@ const isTouchDevice = !headlessMode && window.ontouchstart !== undefined;
|
|
|
265
265
|
function vibrate(pattern=100)
|
|
266
266
|
{
|
|
267
267
|
ASSERT(isNumber(pattern) || isArray(pattern), 'pattern must be a number or array');
|
|
268
|
-
vibrateEnable && !headlessMode && navigator
|
|
268
|
+
vibrateEnable && !headlessMode && navigator?.vibrate?.(pattern);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
/** Cancel any ongoing vibration
|
|
@@ -365,8 +365,7 @@ function inputInit()
|
|
|
365
365
|
}
|
|
366
366
|
function onMouseDown(e)
|
|
367
367
|
{
|
|
368
|
-
if (isTouchDevice && touchInputEnable)
|
|
369
|
-
return;
|
|
368
|
+
if (isTouchDevice && touchInputEnable) return;
|
|
370
369
|
|
|
371
370
|
// fix stalled audio requiring user interaction
|
|
372
371
|
if (soundEnable && !headlessMode && audioContext && !audioIsRunning())
|
|
@@ -384,8 +383,8 @@ function inputInit()
|
|
|
384
383
|
}
|
|
385
384
|
function onMouseUp(e)
|
|
386
385
|
{
|
|
387
|
-
if (isTouchDevice && touchInputEnable)
|
|
388
|
-
|
|
386
|
+
if (isTouchDevice && touchInputEnable) return;
|
|
387
|
+
|
|
389
388
|
inputData[0][e.button] = (inputData[0][e.button]&2) | 4;
|
|
390
389
|
}
|
|
391
390
|
function onMouseMove(e)
|
|
@@ -417,8 +416,7 @@ function inputInit()
|
|
|
417
416
|
let wasTouching;
|
|
418
417
|
function handleTouch(e)
|
|
419
418
|
{
|
|
420
|
-
if (!touchInputEnable)
|
|
421
|
-
return;
|
|
419
|
+
if (!touchInputEnable) return;
|
|
422
420
|
|
|
423
421
|
// route touch to gamepad
|
|
424
422
|
if (touchGamepadEnable)
|
|
@@ -482,8 +480,7 @@ function inputInit()
|
|
|
482
480
|
}
|
|
483
481
|
|
|
484
482
|
// don't process touch gamepad if paused
|
|
485
|
-
if (paused)
|
|
486
|
-
return;
|
|
483
|
+
if (paused) return;
|
|
487
484
|
|
|
488
485
|
// get center of left and right sides
|
|
489
486
|
const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
|
|
@@ -573,8 +570,7 @@ function inputUpdate()
|
|
|
573
570
|
// update touch gamepad if enabled
|
|
574
571
|
if (touchGamepadEnable && isTouchDevice)
|
|
575
572
|
{
|
|
576
|
-
if (!touchGamepadTimer.isSet())
|
|
577
|
-
return;
|
|
573
|
+
if (!touchGamepadTimer.isSet()) return;
|
|
578
574
|
|
|
579
575
|
// read virtual analog stick
|
|
580
576
|
gamepadPrimary = 0; // touch gamepad uses index 0
|
|
@@ -612,12 +608,10 @@ function inputUpdate()
|
|
|
612
608
|
}
|
|
613
609
|
|
|
614
610
|
// return if gamepads are disabled or not supported
|
|
615
|
-
if (!gamepadsEnable || !navigator || !navigator.getGamepads)
|
|
616
|
-
return;
|
|
611
|
+
if (!gamepadsEnable || !navigator || !navigator.getGamepads) return;
|
|
617
612
|
|
|
618
613
|
// only poll gamepads when focused or in debug mode
|
|
619
|
-
if (!debug && !document.hasFocus())
|
|
620
|
-
return;
|
|
614
|
+
if (!debug && !document.hasFocus()) return;
|
|
621
615
|
|
|
622
616
|
// poll gamepads
|
|
623
617
|
const maxGamepads = 8;
|
|
@@ -654,8 +648,7 @@ function inputUpdate()
|
|
|
654
648
|
data[j] = button.pressed ? wasDown ? 1 : 3 : wasDown ? 4 : 0;
|
|
655
649
|
|
|
656
650
|
// check for any input on this gamepad, analog must be full press
|
|
657
|
-
if (button.pressed)
|
|
658
|
-
if (!button.value || button.value > .9)
|
|
651
|
+
if (button.pressed && (!button.value || button.value > .9))
|
|
659
652
|
hadInput = true;
|
|
660
653
|
}
|
|
661
654
|
|
|
@@ -684,7 +677,7 @@ function inputUpdate()
|
|
|
684
677
|
}
|
|
685
678
|
|
|
686
679
|
// copy dpad to left analog stick when pressed
|
|
687
|
-
if (gamepadDirectionEmulateStick &&
|
|
680
|
+
if (gamepadDirectionEmulateStick && (dpad.x || dpad.y))
|
|
688
681
|
sticks[0] = dpad.clampLength();
|
|
689
682
|
}
|
|
690
683
|
|
|
@@ -713,13 +706,11 @@ function inputRender()
|
|
|
713
706
|
function touchGamepadRender()
|
|
714
707
|
{
|
|
715
708
|
if (!touchInputEnable || !isTouchDevice || headlessMode) return;
|
|
716
|
-
if (!touchGamepadEnable || !touchGamepadTimer.isSet())
|
|
717
|
-
return;
|
|
709
|
+
if (!touchGamepadEnable || !touchGamepadTimer.isSet()) return;
|
|
718
710
|
|
|
719
711
|
// fade off when not touching or paused
|
|
720
712
|
const alpha = percent(touchGamepadTimer.get(), 4, 3);
|
|
721
|
-
if (!alpha || paused)
|
|
722
|
-
return;
|
|
713
|
+
if (!alpha || paused) return;
|
|
723
714
|
|
|
724
715
|
// setup the canvas
|
|
725
716
|
const context = mainContext;
|