littlejsengine 1.17.14 → 1.18.0
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 +17 -9
- package/dist/littlejs.esm.js +60 -37
- package/dist/littlejs.esm.min.js +1 -1
- package/dist/littlejs.js +58 -36
- package/dist/littlejs.min.js +1 -1
- package/dist/littlejs.release.js +57 -33
- package/examples/shorts/base.html +1 -1
- package/examples/shorts/music.js +1 -1
- package/examples/shorts/musicPlayer.js +3 -3
- package/examples/shorts/sequencer.js +1 -1
- package/examples/shorts/timers.js +1 -1
- package/examples/shorts/uiSystem.js +5 -5
- package/examples/starter/index.html +2 -2
- package/examples/uiSystem/game.js +6 -6
- package/package.json +1 -1
- package/plugins/box2d.js +18 -7
- package/plugins/pluginExport.js +1 -1
- package/plugins/uiSystem.js +15 -15
- package/src/engine.js +1 -1
- package/src/engineDebug.js +1 -3
- package/src/engineExport.js +1 -0
- package/src/engineInput.js +2 -2
- package/src/engineMath.js +10 -8
- package/src/engineSettings.js +11 -0
package/dist/littlejs.js
CHANGED
|
@@ -35,7 +35,7 @@ const engineName = 'LittleJS';
|
|
|
35
35
|
* @type {string}
|
|
36
36
|
* @default
|
|
37
37
|
* @memberof Engine */
|
|
38
|
-
const engineVersion = '1.
|
|
38
|
+
const engineVersion = '1.18.0';
|
|
39
39
|
|
|
40
40
|
/** Frames per second to update
|
|
41
41
|
* @type {number}
|
|
@@ -961,8 +961,6 @@ function debugUpdate()
|
|
|
961
961
|
debugOverlay = !debugOverlay;
|
|
962
962
|
if (debugOverlay)
|
|
963
963
|
{
|
|
964
|
-
if (keyWasPressed('Digit0'))
|
|
965
|
-
debugWatermark = !debugWatermark;
|
|
966
964
|
if (keyWasPressed('Digit1'))
|
|
967
965
|
debugPhysics = !debugPhysics, debugParticles = false;
|
|
968
966
|
if (keyWasPressed('Digit2'))
|
|
@@ -1250,7 +1248,7 @@ function debugRenderPost()
|
|
|
1250
1248
|
return;
|
|
1251
1249
|
}
|
|
1252
1250
|
|
|
1253
|
-
if (!debugWatermark) return;
|
|
1251
|
+
if (!debugWatermark && !debugOverlay) return;
|
|
1254
1252
|
|
|
1255
1253
|
// update fps display
|
|
1256
1254
|
mainContext.textAlign = 'right';
|
|
@@ -1767,15 +1765,17 @@ function lineTest(posStart, posEnd, testFunction, normal)
|
|
|
1767
1765
|
// set hit point
|
|
1768
1766
|
const hitPos = vec2(posStart.x + dirX*t, posStart.y + dirY*t);
|
|
1769
1767
|
|
|
1770
|
-
//
|
|
1768
|
+
// ensure result is inside the tile
|
|
1771
1769
|
const e = 1e-9;
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
hitPos.y
|
|
1770
|
+
const hitPosFloor = hitPos.floor();
|
|
1771
|
+
if (hitPosFloor.x < pos.x)
|
|
1772
|
+
hitPos.x = pos.x;
|
|
1773
|
+
else if (hitPosFloor.x > pos.x)
|
|
1774
|
+
hitPos.x = pos.x + 1 - e;
|
|
1775
|
+
if (hitPosFloor.y < pos.y)
|
|
1776
|
+
hitPos.y = pos.y;
|
|
1777
|
+
else if (hitPosFloor.y > pos.y)
|
|
1778
|
+
hitPos.y = pos.y + 1 - e;
|
|
1779
1779
|
|
|
1780
1780
|
// set normal
|
|
1781
1781
|
if (normal)
|
|
@@ -3014,6 +3014,12 @@ let touchGamepadSize = 99;
|
|
|
3014
3014
|
* @memberof Settings */
|
|
3015
3015
|
let touchGamepadAlpha = .3;
|
|
3016
3016
|
|
|
3017
|
+
/** How long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
3018
|
+
* @type {number}
|
|
3019
|
+
* @default
|
|
3020
|
+
* @memberof Settings */
|
|
3021
|
+
let touchGamepadDisplayTime = 3;
|
|
3022
|
+
|
|
3017
3023
|
/** Allow vibration hardware if it exists
|
|
3018
3024
|
* @type {boolean}
|
|
3019
3025
|
* @default
|
|
@@ -3288,6 +3294,11 @@ function setTouchGamepadSize(size) { touchGamepadSize = size; }
|
|
|
3288
3294
|
* @memberof Settings */
|
|
3289
3295
|
function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
|
|
3290
3296
|
|
|
3297
|
+
/** Set how long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
3298
|
+
* @param {number} time
|
|
3299
|
+
* @memberof Settings */
|
|
3300
|
+
function setTouchGamepadDisplayTime(time) { touchGamepadDisplayTime = time; }
|
|
3301
|
+
|
|
3291
3302
|
/** Set to allow vibration hardware if it exists
|
|
3292
3303
|
* @param {boolean} enable
|
|
3293
3304
|
* @memberof Settings */
|
|
@@ -5759,10 +5770,10 @@ function inputRender()
|
|
|
5759
5770
|
function touchGamepadRender()
|
|
5760
5771
|
{
|
|
5761
5772
|
if (!touchInputEnable || !isTouchDevice || headlessMode) return;
|
|
5762
|
-
if (!touchGamepadEnable || !touchGamepadTimer.isSet()) return;
|
|
5773
|
+
if (!touchGamepadEnable || !touchGamepadTimer.isSet() && touchGamepadDisplayTime) return;
|
|
5763
5774
|
|
|
5764
5775
|
// fade off when not touching or paused
|
|
5765
|
-
const alpha = percent(touchGamepadTimer.get(),
|
|
5776
|
+
const alpha = touchGamepadDisplayTime ? percent(touchGamepadTimer.get(), touchGamepadDisplayTime+1, touchGamepadDisplayTime) : 1;
|
|
5766
5777
|
if (!alpha || paused) return;
|
|
5767
5778
|
|
|
5768
5779
|
// setup the canvas
|
|
@@ -9333,7 +9344,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
9333
9344
|
* - Buttons
|
|
9334
9345
|
* - Checkboxes
|
|
9335
9346
|
* - Images
|
|
9336
|
-
* -
|
|
9347
|
+
* - Sliders
|
|
9337
9348
|
* - Video
|
|
9338
9349
|
* @namespace UISystem
|
|
9339
9350
|
*/
|
|
@@ -10530,7 +10541,7 @@ class UICheckbox extends UIObject
|
|
|
10530
10541
|
ASSERT(isString(text), 'ui checkbox must be a string');
|
|
10531
10542
|
ASSERT(isColor(color), 'ui checkbox color must be a color');
|
|
10532
10543
|
|
|
10533
|
-
/** @property {boolean} - Current percentage value of this
|
|
10544
|
+
/** @property {boolean} - Current percentage value of this slider 0-1 */
|
|
10534
10545
|
this.checked = checked;
|
|
10535
10546
|
// set properties
|
|
10536
10547
|
this.text = text;
|
|
@@ -10565,13 +10576,13 @@ class UICheckbox extends UIObject
|
|
|
10565
10576
|
|
|
10566
10577
|
///////////////////////////////////////////////////////////////////////////////
|
|
10567
10578
|
/**
|
|
10568
|
-
*
|
|
10579
|
+
* UISlider - A UI object that acts as a slider or scrollbar
|
|
10569
10580
|
* @extends UIObject
|
|
10570
10581
|
* @memberof UISystem
|
|
10571
10582
|
*/
|
|
10572
|
-
class
|
|
10583
|
+
class UISlider extends UIObject
|
|
10573
10584
|
{
|
|
10574
|
-
/** Create a
|
|
10585
|
+
/** Create a UISlider object
|
|
10575
10586
|
* @param {Vector2} [pos]
|
|
10576
10587
|
* @param {Vector2} [size]
|
|
10577
10588
|
* @param {number} [value]
|
|
@@ -10583,14 +10594,14 @@ class UIScrollbar extends UIObject
|
|
|
10583
10594
|
{
|
|
10584
10595
|
super(pos, size);
|
|
10585
10596
|
|
|
10586
|
-
ASSERT(isNumber(value), 'ui
|
|
10587
|
-
ASSERT(isString(text), 'ui
|
|
10588
|
-
ASSERT(isColor(color), 'ui
|
|
10589
|
-
ASSERT(isColor(handleColor), 'ui
|
|
10597
|
+
ASSERT(isNumber(value), 'ui slider value must be a number');
|
|
10598
|
+
ASSERT(isString(text), 'ui slider must be a string');
|
|
10599
|
+
ASSERT(isColor(color), 'ui slider color must be a color');
|
|
10600
|
+
ASSERT(isColor(handleColor), 'ui slider handleColor must be a color');
|
|
10590
10601
|
|
|
10591
|
-
/** @property {number} - Current percentage value of this
|
|
10602
|
+
/** @property {number} - Current percentage value of this slider 0-1 */
|
|
10592
10603
|
this.value = value;
|
|
10593
|
-
/** @property {Color} - Color for the handle part of the
|
|
10604
|
+
/** @property {Color} - Color for the handle part of the slider */
|
|
10594
10605
|
this.handleColor = handleColor.copy();
|
|
10595
10606
|
/** @property {boolean} - Should it fill up like a progress bar? */
|
|
10596
10607
|
this.fillMode = false;
|
|
@@ -10609,7 +10620,7 @@ class UIScrollbar extends UIObject
|
|
|
10609
10620
|
const oldValue = this.value;
|
|
10610
10621
|
if (this.isActiveObject())
|
|
10611
10622
|
{
|
|
10612
|
-
// handle horizontal or vertical
|
|
10623
|
+
// handle horizontal or vertical slider
|
|
10613
10624
|
const isHorizontal = this.size.x > this.size.y;
|
|
10614
10625
|
const handleSize = isHorizontal ? this.size.y : this.size.x;
|
|
10615
10626
|
const barSize = isHorizontal ? this.size.x : this.size.y;
|
|
@@ -10637,7 +10648,7 @@ class UIScrollbar extends UIObject
|
|
|
10637
10648
|
{
|
|
10638
10649
|
super.render();
|
|
10639
10650
|
|
|
10640
|
-
// handle horizontal or vertical
|
|
10651
|
+
// handle horizontal or vertical slider
|
|
10641
10652
|
const isHorizontal = this.size.x > this.size.y;
|
|
10642
10653
|
const barWidth = isHorizontal ? this.size.x : this.size.y;
|
|
10643
10654
|
const handleWidth = isHorizontal ? this.size.y : this.size.x;
|
|
@@ -10655,7 +10666,7 @@ class UIScrollbar extends UIObject
|
|
|
10655
10666
|
}
|
|
10656
10667
|
else
|
|
10657
10668
|
{
|
|
10658
|
-
// draw the
|
|
10669
|
+
// draw the slider handle
|
|
10659
10670
|
const value = clamp(isHorizontal ? this.value : 1 - this.value);
|
|
10660
10671
|
const p = (barWidth - handleWidth) * (value - .5);
|
|
10661
10672
|
const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
|
|
@@ -10664,7 +10675,7 @@ class UIScrollbar extends UIObject
|
|
|
10664
10675
|
uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
|
|
10665
10676
|
}
|
|
10666
10677
|
|
|
10667
|
-
// draw the text scaled to fit on the
|
|
10678
|
+
// draw the text scaled to fit on the slider
|
|
10668
10679
|
const textSize = this.getTextSize();
|
|
10669
10680
|
uiSystem.drawText(this.text, this.pos, textSize,
|
|
10670
10681
|
this.textColor, this.textLineWidth, this.textLineColor, this.align, this.font, this.fontStyle, true, this.textShadow);
|
|
@@ -10939,7 +10950,7 @@ class Box2dObject extends EngineObject
|
|
|
10939
10950
|
// draw non-edge fixtures
|
|
10940
10951
|
this.getFixtureList().forEach((fixture)=>
|
|
10941
10952
|
{
|
|
10942
|
-
const shape = box2d.
|
|
10953
|
+
const shape = box2d.castShapeObject(fixture.GetShape());
|
|
10943
10954
|
if (shape.GetType() !== box2d.instance.b2Shape.e_edge)
|
|
10944
10955
|
{
|
|
10945
10956
|
box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, useWebGL, context);
|
|
@@ -11579,7 +11590,7 @@ class Box2dJoint
|
|
|
11579
11590
|
constructor(jointDef)
|
|
11580
11591
|
{
|
|
11581
11592
|
/** @property {Object} - The Box2d joint */
|
|
11582
|
-
this.box2dJoint = box2d.
|
|
11593
|
+
this.box2dJoint = box2d.castJointObject(box2d.world.CreateJoint(jointDef));
|
|
11583
11594
|
}
|
|
11584
11595
|
|
|
11585
11596
|
/** Destroy this joint */
|
|
@@ -11864,7 +11875,7 @@ class Box2dRevoluteJoint extends Box2dJoint
|
|
|
11864
11875
|
|
|
11865
11876
|
/** Enable/disable the joint limit
|
|
11866
11877
|
* @param {boolean} [enable] */
|
|
11867
|
-
enableLimit(enable=true) { return this.box2dJoint.
|
|
11878
|
+
enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
|
|
11868
11879
|
|
|
11869
11880
|
/** Get the lower joint limit
|
|
11870
11881
|
* @return {number} */
|
|
@@ -12022,7 +12033,7 @@ class Box2dPrismaticJoint extends Box2dJoint
|
|
|
12022
12033
|
|
|
12023
12034
|
/** Enable/disable the joint limit
|
|
12024
12035
|
* @param {boolean} [enable] */
|
|
12025
|
-
enableLimit(enable=true) { return this.box2dJoint.
|
|
12036
|
+
enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
|
|
12026
12037
|
|
|
12027
12038
|
/** Get the lower joint limit
|
|
12028
12039
|
* @return {number} */
|
|
@@ -12636,7 +12647,7 @@ class Box2dPlugin
|
|
|
12636
12647
|
* @param {CanvasRenderingContext2D} [context] */
|
|
12637
12648
|
drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, useWebgl, context)
|
|
12638
12649
|
{
|
|
12639
|
-
const shape = box2d.
|
|
12650
|
+
const shape = box2d.castShapeObject(fixture.GetShape());
|
|
12640
12651
|
switch (shape.GetType())
|
|
12641
12652
|
{
|
|
12642
12653
|
case box2d.instance.b2Shape.e_polygon:
|
|
@@ -12694,9 +12705,9 @@ class Box2dPlugin
|
|
|
12694
12705
|
* @param {Object} o */
|
|
12695
12706
|
isNull(o) { return !box2d.instance.getPointer(o); }
|
|
12696
12707
|
|
|
12697
|
-
/** casts a box2d object to
|
|
12708
|
+
/** casts a box2d object to a shape type
|
|
12698
12709
|
* @param {Object} o */
|
|
12699
|
-
|
|
12710
|
+
castShapeObject(o)
|
|
12700
12711
|
{
|
|
12701
12712
|
switch (o.GetType())
|
|
12702
12713
|
{
|
|
@@ -12708,6 +12719,17 @@ class Box2dPlugin
|
|
|
12708
12719
|
return box2d.instance.castObject(o, box2d.instance.b2PolygonShape);
|
|
12709
12720
|
case box2d.instance.b2Shape.e_chain:
|
|
12710
12721
|
return box2d.instance.castObject(o, box2d.instance.b2ChainShape);
|
|
12722
|
+
}
|
|
12723
|
+
|
|
12724
|
+
ASSERT(false, 'Unknown box2d object type');
|
|
12725
|
+
}
|
|
12726
|
+
|
|
12727
|
+
/** casts a box2d object to a joint type
|
|
12728
|
+
* @param {Object} o */
|
|
12729
|
+
castJointObject(o)
|
|
12730
|
+
{
|
|
12731
|
+
switch (o.GetType())
|
|
12732
|
+
{
|
|
12711
12733
|
case box2d.instance.e_revoluteJoint:
|
|
12712
12734
|
return box2d.instance.castObject(o, box2d.instance.b2RevoluteJoint);
|
|
12713
12735
|
case box2d.instance.e_prismaticJoint:
|