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.release.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}
|
|
@@ -1087,15 +1087,17 @@ function lineTest(posStart, posEnd, testFunction, normal)
|
|
|
1087
1087
|
// set hit point
|
|
1088
1088
|
const hitPos = vec2(posStart.x + dirX*t, posStart.y + dirY*t);
|
|
1089
1089
|
|
|
1090
|
-
//
|
|
1090
|
+
// ensure result is inside the tile
|
|
1091
1091
|
const e = 1e-9;
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
hitPos.y
|
|
1092
|
+
const hitPosFloor = hitPos.floor();
|
|
1093
|
+
if (hitPosFloor.x < pos.x)
|
|
1094
|
+
hitPos.x = pos.x;
|
|
1095
|
+
else if (hitPosFloor.x > pos.x)
|
|
1096
|
+
hitPos.x = pos.x + 1 - e;
|
|
1097
|
+
if (hitPosFloor.y < pos.y)
|
|
1098
|
+
hitPos.y = pos.y;
|
|
1099
|
+
else if (hitPosFloor.y > pos.y)
|
|
1100
|
+
hitPos.y = pos.y + 1 - e;
|
|
1099
1101
|
|
|
1100
1102
|
// set normal
|
|
1101
1103
|
if (normal)
|
|
@@ -2334,6 +2336,12 @@ let touchGamepadSize = 99;
|
|
|
2334
2336
|
* @memberof Settings */
|
|
2335
2337
|
let touchGamepadAlpha = .3;
|
|
2336
2338
|
|
|
2339
|
+
/** How long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
2340
|
+
* @type {number}
|
|
2341
|
+
* @default
|
|
2342
|
+
* @memberof Settings */
|
|
2343
|
+
let touchGamepadDisplayTime = 3;
|
|
2344
|
+
|
|
2337
2345
|
/** Allow vibration hardware if it exists
|
|
2338
2346
|
* @type {boolean}
|
|
2339
2347
|
* @default
|
|
@@ -2608,6 +2616,11 @@ function setTouchGamepadSize(size) { touchGamepadSize = size; }
|
|
|
2608
2616
|
* @memberof Settings */
|
|
2609
2617
|
function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
|
|
2610
2618
|
|
|
2619
|
+
/** Set how long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
2620
|
+
* @param {number} time
|
|
2621
|
+
* @memberof Settings */
|
|
2622
|
+
function setTouchGamepadDisplayTime(time) { touchGamepadDisplayTime = time; }
|
|
2623
|
+
|
|
2611
2624
|
/** Set to allow vibration hardware if it exists
|
|
2612
2625
|
* @param {boolean} enable
|
|
2613
2626
|
* @memberof Settings */
|
|
@@ -5079,10 +5092,10 @@ function inputRender()
|
|
|
5079
5092
|
function touchGamepadRender()
|
|
5080
5093
|
{
|
|
5081
5094
|
if (!touchInputEnable || !isTouchDevice || headlessMode) return;
|
|
5082
|
-
if (!touchGamepadEnable || !touchGamepadTimer.isSet()) return;
|
|
5095
|
+
if (!touchGamepadEnable || !touchGamepadTimer.isSet() && touchGamepadDisplayTime) return;
|
|
5083
5096
|
|
|
5084
5097
|
// fade off when not touching or paused
|
|
5085
|
-
const alpha = percent(touchGamepadTimer.get(),
|
|
5098
|
+
const alpha = touchGamepadDisplayTime ? percent(touchGamepadTimer.get(), touchGamepadDisplayTime+1, touchGamepadDisplayTime) : 1;
|
|
5086
5099
|
if (!alpha || paused) return;
|
|
5087
5100
|
|
|
5088
5101
|
// setup the canvas
|
|
@@ -8653,7 +8666,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
|
|
|
8653
8666
|
* - Buttons
|
|
8654
8667
|
* - Checkboxes
|
|
8655
8668
|
* - Images
|
|
8656
|
-
* -
|
|
8669
|
+
* - Sliders
|
|
8657
8670
|
* - Video
|
|
8658
8671
|
* @namespace UISystem
|
|
8659
8672
|
*/
|
|
@@ -9850,7 +9863,7 @@ class UICheckbox extends UIObject
|
|
|
9850
9863
|
ASSERT(isString(text), 'ui checkbox must be a string');
|
|
9851
9864
|
ASSERT(isColor(color), 'ui checkbox color must be a color');
|
|
9852
9865
|
|
|
9853
|
-
/** @property {boolean} - Current percentage value of this
|
|
9866
|
+
/** @property {boolean} - Current percentage value of this slider 0-1 */
|
|
9854
9867
|
this.checked = checked;
|
|
9855
9868
|
// set properties
|
|
9856
9869
|
this.text = text;
|
|
@@ -9885,13 +9898,13 @@ class UICheckbox extends UIObject
|
|
|
9885
9898
|
|
|
9886
9899
|
///////////////////////////////////////////////////////////////////////////////
|
|
9887
9900
|
/**
|
|
9888
|
-
*
|
|
9901
|
+
* UISlider - A UI object that acts as a slider or scrollbar
|
|
9889
9902
|
* @extends UIObject
|
|
9890
9903
|
* @memberof UISystem
|
|
9891
9904
|
*/
|
|
9892
|
-
class
|
|
9905
|
+
class UISlider extends UIObject
|
|
9893
9906
|
{
|
|
9894
|
-
/** Create a
|
|
9907
|
+
/** Create a UISlider object
|
|
9895
9908
|
* @param {Vector2} [pos]
|
|
9896
9909
|
* @param {Vector2} [size]
|
|
9897
9910
|
* @param {number} [value]
|
|
@@ -9903,14 +9916,14 @@ class UIScrollbar extends UIObject
|
|
|
9903
9916
|
{
|
|
9904
9917
|
super(pos, size);
|
|
9905
9918
|
|
|
9906
|
-
ASSERT(isNumber(value), 'ui
|
|
9907
|
-
ASSERT(isString(text), 'ui
|
|
9908
|
-
ASSERT(isColor(color), 'ui
|
|
9909
|
-
ASSERT(isColor(handleColor), 'ui
|
|
9919
|
+
ASSERT(isNumber(value), 'ui slider value must be a number');
|
|
9920
|
+
ASSERT(isString(text), 'ui slider must be a string');
|
|
9921
|
+
ASSERT(isColor(color), 'ui slider color must be a color');
|
|
9922
|
+
ASSERT(isColor(handleColor), 'ui slider handleColor must be a color');
|
|
9910
9923
|
|
|
9911
|
-
/** @property {number} - Current percentage value of this
|
|
9924
|
+
/** @property {number} - Current percentage value of this slider 0-1 */
|
|
9912
9925
|
this.value = value;
|
|
9913
|
-
/** @property {Color} - Color for the handle part of the
|
|
9926
|
+
/** @property {Color} - Color for the handle part of the slider */
|
|
9914
9927
|
this.handleColor = handleColor.copy();
|
|
9915
9928
|
/** @property {boolean} - Should it fill up like a progress bar? */
|
|
9916
9929
|
this.fillMode = false;
|
|
@@ -9929,7 +9942,7 @@ class UIScrollbar extends UIObject
|
|
|
9929
9942
|
const oldValue = this.value;
|
|
9930
9943
|
if (this.isActiveObject())
|
|
9931
9944
|
{
|
|
9932
|
-
// handle horizontal or vertical
|
|
9945
|
+
// handle horizontal or vertical slider
|
|
9933
9946
|
const isHorizontal = this.size.x > this.size.y;
|
|
9934
9947
|
const handleSize = isHorizontal ? this.size.y : this.size.x;
|
|
9935
9948
|
const barSize = isHorizontal ? this.size.x : this.size.y;
|
|
@@ -9957,7 +9970,7 @@ class UIScrollbar extends UIObject
|
|
|
9957
9970
|
{
|
|
9958
9971
|
super.render();
|
|
9959
9972
|
|
|
9960
|
-
// handle horizontal or vertical
|
|
9973
|
+
// handle horizontal or vertical slider
|
|
9961
9974
|
const isHorizontal = this.size.x > this.size.y;
|
|
9962
9975
|
const barWidth = isHorizontal ? this.size.x : this.size.y;
|
|
9963
9976
|
const handleWidth = isHorizontal ? this.size.y : this.size.x;
|
|
@@ -9975,7 +9988,7 @@ class UIScrollbar extends UIObject
|
|
|
9975
9988
|
}
|
|
9976
9989
|
else
|
|
9977
9990
|
{
|
|
9978
|
-
// draw the
|
|
9991
|
+
// draw the slider handle
|
|
9979
9992
|
const value = clamp(isHorizontal ? this.value : 1 - this.value);
|
|
9980
9993
|
const p = (barWidth - handleWidth) * (value - .5);
|
|
9981
9994
|
const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
|
|
@@ -9984,7 +9997,7 @@ class UIScrollbar extends UIObject
|
|
|
9984
9997
|
uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
|
|
9985
9998
|
}
|
|
9986
9999
|
|
|
9987
|
-
// draw the text scaled to fit on the
|
|
10000
|
+
// draw the text scaled to fit on the slider
|
|
9988
10001
|
const textSize = this.getTextSize();
|
|
9989
10002
|
uiSystem.drawText(this.text, this.pos, textSize,
|
|
9990
10003
|
this.textColor, this.textLineWidth, this.textLineColor, this.align, this.font, this.fontStyle, true, this.textShadow);
|
|
@@ -10259,7 +10272,7 @@ class Box2dObject extends EngineObject
|
|
|
10259
10272
|
// draw non-edge fixtures
|
|
10260
10273
|
this.getFixtureList().forEach((fixture)=>
|
|
10261
10274
|
{
|
|
10262
|
-
const shape = box2d.
|
|
10275
|
+
const shape = box2d.castShapeObject(fixture.GetShape());
|
|
10263
10276
|
if (shape.GetType() !== box2d.instance.b2Shape.e_edge)
|
|
10264
10277
|
{
|
|
10265
10278
|
box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, useWebGL, context);
|
|
@@ -10899,7 +10912,7 @@ class Box2dJoint
|
|
|
10899
10912
|
constructor(jointDef)
|
|
10900
10913
|
{
|
|
10901
10914
|
/** @property {Object} - The Box2d joint */
|
|
10902
|
-
this.box2dJoint = box2d.
|
|
10915
|
+
this.box2dJoint = box2d.castJointObject(box2d.world.CreateJoint(jointDef));
|
|
10903
10916
|
}
|
|
10904
10917
|
|
|
10905
10918
|
/** Destroy this joint */
|
|
@@ -11184,7 +11197,7 @@ class Box2dRevoluteJoint extends Box2dJoint
|
|
|
11184
11197
|
|
|
11185
11198
|
/** Enable/disable the joint limit
|
|
11186
11199
|
* @param {boolean} [enable] */
|
|
11187
|
-
enableLimit(enable=true) { return this.box2dJoint.
|
|
11200
|
+
enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
|
|
11188
11201
|
|
|
11189
11202
|
/** Get the lower joint limit
|
|
11190
11203
|
* @return {number} */
|
|
@@ -11342,7 +11355,7 @@ class Box2dPrismaticJoint extends Box2dJoint
|
|
|
11342
11355
|
|
|
11343
11356
|
/** Enable/disable the joint limit
|
|
11344
11357
|
* @param {boolean} [enable] */
|
|
11345
|
-
enableLimit(enable=true) { return this.box2dJoint.
|
|
11358
|
+
enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
|
|
11346
11359
|
|
|
11347
11360
|
/** Get the lower joint limit
|
|
11348
11361
|
* @return {number} */
|
|
@@ -11956,7 +11969,7 @@ class Box2dPlugin
|
|
|
11956
11969
|
* @param {CanvasRenderingContext2D} [context] */
|
|
11957
11970
|
drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, useWebgl, context)
|
|
11958
11971
|
{
|
|
11959
|
-
const shape = box2d.
|
|
11972
|
+
const shape = box2d.castShapeObject(fixture.GetShape());
|
|
11960
11973
|
switch (shape.GetType())
|
|
11961
11974
|
{
|
|
11962
11975
|
case box2d.instance.b2Shape.e_polygon:
|
|
@@ -12014,9 +12027,9 @@ class Box2dPlugin
|
|
|
12014
12027
|
* @param {Object} o */
|
|
12015
12028
|
isNull(o) { return !box2d.instance.getPointer(o); }
|
|
12016
12029
|
|
|
12017
|
-
/** casts a box2d object to
|
|
12030
|
+
/** casts a box2d object to a shape type
|
|
12018
12031
|
* @param {Object} o */
|
|
12019
|
-
|
|
12032
|
+
castShapeObject(o)
|
|
12020
12033
|
{
|
|
12021
12034
|
switch (o.GetType())
|
|
12022
12035
|
{
|
|
@@ -12028,6 +12041,17 @@ class Box2dPlugin
|
|
|
12028
12041
|
return box2d.instance.castObject(o, box2d.instance.b2PolygonShape);
|
|
12029
12042
|
case box2d.instance.b2Shape.e_chain:
|
|
12030
12043
|
return box2d.instance.castObject(o, box2d.instance.b2ChainShape);
|
|
12044
|
+
}
|
|
12045
|
+
|
|
12046
|
+
ASSERT(false, 'Unknown box2d object type');
|
|
12047
|
+
}
|
|
12048
|
+
|
|
12049
|
+
/** casts a box2d object to a joint type
|
|
12050
|
+
* @param {Object} o */
|
|
12051
|
+
castJointObject(o)
|
|
12052
|
+
{
|
|
12053
|
+
switch (o.GetType())
|
|
12054
|
+
{
|
|
12031
12055
|
case box2d.instance.e_revoluteJoint:
|
|
12032
12056
|
return box2d.instance.castObject(o, box2d.instance.b2RevoluteJoint);
|
|
12033
12057
|
case box2d.instance.e_prismaticJoint:
|
package/examples/shorts/music.js
CHANGED
|
@@ -20,7 +20,7 @@ function gameInit()
|
|
|
20
20
|
musicPlayer.addChild(infoText);
|
|
21
21
|
|
|
22
22
|
// volume slider
|
|
23
|
-
const volumeSlider = new
|
|
23
|
+
const volumeSlider = new UISlider(vec2(0, -20), vec2(400, 30),
|
|
24
24
|
musicVolume, 'Music Volume');
|
|
25
25
|
volumeSlider.fillMode = true;
|
|
26
26
|
musicPlayer.addChild(volumeSlider);
|
|
@@ -26,7 +26,7 @@ function gameInit()
|
|
|
26
26
|
musicPlayer.addChild(dropZoneText);
|
|
27
27
|
|
|
28
28
|
// volume slider
|
|
29
|
-
const volumeSlider = new
|
|
29
|
+
const volumeSlider = new UISlider(vec2(0, -20), vec2(400, 30),
|
|
30
30
|
musicVolume, 'Music Volume');
|
|
31
31
|
volumeSlider.fillMode = true;
|
|
32
32
|
musicPlayer.addChild(volumeSlider);
|
|
@@ -58,8 +58,8 @@ function gameInit()
|
|
|
58
58
|
stopButton.onClick = ()=> musicInstance?.stop();
|
|
59
59
|
musicPlayer.addChild(stopButton);
|
|
60
60
|
|
|
61
|
-
// progress bar and
|
|
62
|
-
progressBar = new
|
|
61
|
+
// progress bar and slider for seeking
|
|
62
|
+
progressBar = new UISlider(vec2(0, 120), vec2(400, 30), 0);
|
|
63
63
|
progressBar.disabledColor = RED;
|
|
64
64
|
progressBar.onChange = ()=>
|
|
65
65
|
{
|
|
@@ -91,7 +91,7 @@ function gameInit()
|
|
|
91
91
|
// create tempo slider
|
|
92
92
|
const minTempo = 120, maxTempo = 480;
|
|
93
93
|
const tempoPercent = percent(tempo, minTempo, maxTempo);
|
|
94
|
-
const tempoSlider = new
|
|
94
|
+
const tempoSlider = new UISlider(vec2(380,500), vec2(340,40), tempoPercent);
|
|
95
95
|
tempoSlider.onChange = ()=>
|
|
96
96
|
{
|
|
97
97
|
tempo = lerp(minTempo, maxTempo, tempoSlider.value);
|
|
@@ -30,7 +30,7 @@ function gameInit()
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// create non-interactive slider to display timer
|
|
33
|
-
timerSlider = new
|
|
33
|
+
timerSlider = new UISlider(vec2(0, 100), vec2(400, 50));
|
|
34
34
|
timerSlider.interactive = false;
|
|
35
35
|
timerSlider.update = ()=>
|
|
36
36
|
{
|
|
@@ -33,12 +33,12 @@ function gameInit()
|
|
|
33
33
|
uiMenu.addChild(textInput);
|
|
34
34
|
textInput.onChange = ()=> canvasClearColor = randColor();
|
|
35
35
|
|
|
36
|
-
// example
|
|
37
|
-
const
|
|
36
|
+
// example slider
|
|
37
|
+
const slider = new UISlider(vec2(0,90), vec2(400, 50),
|
|
38
38
|
soundVolume, 'Volume');
|
|
39
|
-
|
|
40
|
-
uiMenu.addChild(
|
|
41
|
-
|
|
39
|
+
slider.navigationIndex = ++navigationIndex;
|
|
40
|
+
uiMenu.addChild(slider);
|
|
41
|
+
slider.onChange = ()=> setSoundVolume(slider.value);
|
|
42
42
|
|
|
43
43
|
// exit button
|
|
44
44
|
const button1 = new UIButton(vec2(0,170), vec2(200, 50), 'Exit Menu');
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</head><body>
|
|
8
8
|
|
|
9
9
|
<!-- LittleJS Engine -->
|
|
10
|
-
<script src=../../dist/littlejs.js?1.
|
|
10
|
+
<script src=../../dist/littlejs.js?1.18.0></script>
|
|
11
11
|
|
|
12
12
|
<!-- LittleJS Engine Source
|
|
13
13
|
<script src=../../src/engine.js></script>
|
|
@@ -32,4 +32,4 @@
|
|
|
32
32
|
-->
|
|
33
33
|
|
|
34
34
|
<!-- Add your game scripts here -->
|
|
35
|
-
<script src=game.js?1.
|
|
35
|
+
<script src=game.js?1.18.0></script>
|
|
@@ -67,12 +67,12 @@ function createUI()
|
|
|
67
67
|
checkbox.navigationIndex = ++navigationIndex;
|
|
68
68
|
checkbox.text = 'Test Checkbox';
|
|
69
69
|
|
|
70
|
-
// example
|
|
71
|
-
const
|
|
72
|
-
uiMenu.addChild(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
// example slider
|
|
71
|
+
const slider = new LJS.UISlider(vec2(0,60), vec2(350, 50));
|
|
72
|
+
uiMenu.addChild(slider);
|
|
73
|
+
slider.onChange = ()=> slider.text = slider.value.toFixed(2)
|
|
74
|
+
slider.onChange();
|
|
75
|
+
slider.navigationIndex = ++navigationIndex;
|
|
76
76
|
|
|
77
77
|
// example button
|
|
78
78
|
const button1 = new LJS.UIButton(vec2(0,140), vec2(350, 50), 'Test Button');
|
package/package.json
CHANGED
package/plugins/box2d.js
CHANGED
|
@@ -119,7 +119,7 @@ class Box2dObject extends EngineObject
|
|
|
119
119
|
// draw non-edge fixtures
|
|
120
120
|
this.getFixtureList().forEach((fixture)=>
|
|
121
121
|
{
|
|
122
|
-
const shape = box2d.
|
|
122
|
+
const shape = box2d.castShapeObject(fixture.GetShape());
|
|
123
123
|
if (shape.GetType() !== box2d.instance.b2Shape.e_edge)
|
|
124
124
|
{
|
|
125
125
|
box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, useWebGL, context);
|
|
@@ -759,7 +759,7 @@ class Box2dJoint
|
|
|
759
759
|
constructor(jointDef)
|
|
760
760
|
{
|
|
761
761
|
/** @property {Object} - The Box2d joint */
|
|
762
|
-
this.box2dJoint = box2d.
|
|
762
|
+
this.box2dJoint = box2d.castJointObject(box2d.world.CreateJoint(jointDef));
|
|
763
763
|
}
|
|
764
764
|
|
|
765
765
|
/** Destroy this joint */
|
|
@@ -1044,7 +1044,7 @@ class Box2dRevoluteJoint extends Box2dJoint
|
|
|
1044
1044
|
|
|
1045
1045
|
/** Enable/disable the joint limit
|
|
1046
1046
|
* @param {boolean} [enable] */
|
|
1047
|
-
enableLimit(enable=true) { return this.box2dJoint.
|
|
1047
|
+
enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
|
|
1048
1048
|
|
|
1049
1049
|
/** Get the lower joint limit
|
|
1050
1050
|
* @return {number} */
|
|
@@ -1202,7 +1202,7 @@ class Box2dPrismaticJoint extends Box2dJoint
|
|
|
1202
1202
|
|
|
1203
1203
|
/** Enable/disable the joint limit
|
|
1204
1204
|
* @param {boolean} [enable] */
|
|
1205
|
-
enableLimit(enable=true) { return this.box2dJoint.
|
|
1205
|
+
enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
|
|
1206
1206
|
|
|
1207
1207
|
/** Get the lower joint limit
|
|
1208
1208
|
* @return {number} */
|
|
@@ -1816,7 +1816,7 @@ class Box2dPlugin
|
|
|
1816
1816
|
* @param {CanvasRenderingContext2D} [context] */
|
|
1817
1817
|
drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, useWebgl, context)
|
|
1818
1818
|
{
|
|
1819
|
-
const shape = box2d.
|
|
1819
|
+
const shape = box2d.castShapeObject(fixture.GetShape());
|
|
1820
1820
|
switch (shape.GetType())
|
|
1821
1821
|
{
|
|
1822
1822
|
case box2d.instance.b2Shape.e_polygon:
|
|
@@ -1874,9 +1874,9 @@ class Box2dPlugin
|
|
|
1874
1874
|
* @param {Object} o */
|
|
1875
1875
|
isNull(o) { return !box2d.instance.getPointer(o); }
|
|
1876
1876
|
|
|
1877
|
-
/** casts a box2d object to
|
|
1877
|
+
/** casts a box2d object to a shape type
|
|
1878
1878
|
* @param {Object} o */
|
|
1879
|
-
|
|
1879
|
+
castShapeObject(o)
|
|
1880
1880
|
{
|
|
1881
1881
|
switch (o.GetType())
|
|
1882
1882
|
{
|
|
@@ -1888,6 +1888,17 @@ class Box2dPlugin
|
|
|
1888
1888
|
return box2d.instance.castObject(o, box2d.instance.b2PolygonShape);
|
|
1889
1889
|
case box2d.instance.b2Shape.e_chain:
|
|
1890
1890
|
return box2d.instance.castObject(o, box2d.instance.b2ChainShape);
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
ASSERT(false, 'Unknown box2d object type');
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
/** casts a box2d object to a joint type
|
|
1897
|
+
* @param {Object} o */
|
|
1898
|
+
castJointObject(o)
|
|
1899
|
+
{
|
|
1900
|
+
switch (o.GetType())
|
|
1901
|
+
{
|
|
1891
1902
|
case box2d.instance.e_revoluteJoint:
|
|
1892
1903
|
return box2d.instance.castObject(o, box2d.instance.b2RevoluteJoint);
|
|
1893
1904
|
case box2d.instance.e_prismaticJoint:
|
package/plugins/pluginExport.js
CHANGED
package/plugins/uiSystem.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* - Buttons
|
|
8
8
|
* - Checkboxes
|
|
9
9
|
* - Images
|
|
10
|
-
* -
|
|
10
|
+
* - Sliders
|
|
11
11
|
* - Video
|
|
12
12
|
* @namespace UISystem
|
|
13
13
|
*/
|
|
@@ -1206,7 +1206,7 @@ class UICheckbox extends UIObject
|
|
|
1206
1206
|
ASSERT(isString(text), 'ui checkbox must be a string');
|
|
1207
1207
|
ASSERT(isColor(color), 'ui checkbox color must be a color');
|
|
1208
1208
|
|
|
1209
|
-
/** @property {boolean} - Current percentage value of this
|
|
1209
|
+
/** @property {boolean} - Current percentage value of this slider 0-1 */
|
|
1210
1210
|
this.checked = checked;
|
|
1211
1211
|
// set properties
|
|
1212
1212
|
this.text = text;
|
|
@@ -1241,13 +1241,13 @@ class UICheckbox extends UIObject
|
|
|
1241
1241
|
|
|
1242
1242
|
///////////////////////////////////////////////////////////////////////////////
|
|
1243
1243
|
/**
|
|
1244
|
-
*
|
|
1244
|
+
* UISlider - A UI object that acts as a slider or scrollbar
|
|
1245
1245
|
* @extends UIObject
|
|
1246
1246
|
* @memberof UISystem
|
|
1247
1247
|
*/
|
|
1248
|
-
class
|
|
1248
|
+
class UISlider extends UIObject
|
|
1249
1249
|
{
|
|
1250
|
-
/** Create a
|
|
1250
|
+
/** Create a UISlider object
|
|
1251
1251
|
* @param {Vector2} [pos]
|
|
1252
1252
|
* @param {Vector2} [size]
|
|
1253
1253
|
* @param {number} [value]
|
|
@@ -1259,14 +1259,14 @@ class UIScrollbar extends UIObject
|
|
|
1259
1259
|
{
|
|
1260
1260
|
super(pos, size);
|
|
1261
1261
|
|
|
1262
|
-
ASSERT(isNumber(value), 'ui
|
|
1263
|
-
ASSERT(isString(text), 'ui
|
|
1264
|
-
ASSERT(isColor(color), 'ui
|
|
1265
|
-
ASSERT(isColor(handleColor), 'ui
|
|
1262
|
+
ASSERT(isNumber(value), 'ui slider value must be a number');
|
|
1263
|
+
ASSERT(isString(text), 'ui slider must be a string');
|
|
1264
|
+
ASSERT(isColor(color), 'ui slider color must be a color');
|
|
1265
|
+
ASSERT(isColor(handleColor), 'ui slider handleColor must be a color');
|
|
1266
1266
|
|
|
1267
|
-
/** @property {number} - Current percentage value of this
|
|
1267
|
+
/** @property {number} - Current percentage value of this slider 0-1 */
|
|
1268
1268
|
this.value = value;
|
|
1269
|
-
/** @property {Color} - Color for the handle part of the
|
|
1269
|
+
/** @property {Color} - Color for the handle part of the slider */
|
|
1270
1270
|
this.handleColor = handleColor.copy();
|
|
1271
1271
|
/** @property {boolean} - Should it fill up like a progress bar? */
|
|
1272
1272
|
this.fillMode = false;
|
|
@@ -1285,7 +1285,7 @@ class UIScrollbar extends UIObject
|
|
|
1285
1285
|
const oldValue = this.value;
|
|
1286
1286
|
if (this.isActiveObject())
|
|
1287
1287
|
{
|
|
1288
|
-
// handle horizontal or vertical
|
|
1288
|
+
// handle horizontal or vertical slider
|
|
1289
1289
|
const isHorizontal = this.size.x > this.size.y;
|
|
1290
1290
|
const handleSize = isHorizontal ? this.size.y : this.size.x;
|
|
1291
1291
|
const barSize = isHorizontal ? this.size.x : this.size.y;
|
|
@@ -1313,7 +1313,7 @@ class UIScrollbar extends UIObject
|
|
|
1313
1313
|
{
|
|
1314
1314
|
super.render();
|
|
1315
1315
|
|
|
1316
|
-
// handle horizontal or vertical
|
|
1316
|
+
// handle horizontal or vertical slider
|
|
1317
1317
|
const isHorizontal = this.size.x > this.size.y;
|
|
1318
1318
|
const barWidth = isHorizontal ? this.size.x : this.size.y;
|
|
1319
1319
|
const handleWidth = isHorizontal ? this.size.y : this.size.x;
|
|
@@ -1331,7 +1331,7 @@ class UIScrollbar extends UIObject
|
|
|
1331
1331
|
}
|
|
1332
1332
|
else
|
|
1333
1333
|
{
|
|
1334
|
-
// draw the
|
|
1334
|
+
// draw the slider handle
|
|
1335
1335
|
const value = clamp(isHorizontal ? this.value : 1 - this.value);
|
|
1336
1336
|
const p = (barWidth - handleWidth) * (value - .5);
|
|
1337
1337
|
const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
|
|
@@ -1340,7 +1340,7 @@ class UIScrollbar extends UIObject
|
|
|
1340
1340
|
uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
|
|
1341
1341
|
}
|
|
1342
1342
|
|
|
1343
|
-
// draw the text scaled to fit on the
|
|
1343
|
+
// draw the text scaled to fit on the slider
|
|
1344
1344
|
const textSize = this.getTextSize();
|
|
1345
1345
|
uiSystem.drawText(this.text, this.pos, textSize,
|
|
1346
1346
|
this.textColor, this.textLineWidth, this.textLineColor, this.align, this.font, this.fontStyle, true, this.textShadow);
|
package/src/engine.js
CHANGED
package/src/engineDebug.js
CHANGED
|
@@ -276,8 +276,6 @@ function debugUpdate()
|
|
|
276
276
|
debugOverlay = !debugOverlay;
|
|
277
277
|
if (debugOverlay)
|
|
278
278
|
{
|
|
279
|
-
if (keyWasPressed('Digit0'))
|
|
280
|
-
debugWatermark = !debugWatermark;
|
|
281
279
|
if (keyWasPressed('Digit1'))
|
|
282
280
|
debugPhysics = !debugPhysics, debugParticles = false;
|
|
283
281
|
if (keyWasPressed('Digit2'))
|
|
@@ -565,7 +563,7 @@ function debugRenderPost()
|
|
|
565
563
|
return;
|
|
566
564
|
}
|
|
567
565
|
|
|
568
|
-
if (!debugWatermark) return;
|
|
566
|
+
if (!debugWatermark && !debugOverlay) return;
|
|
569
567
|
|
|
570
568
|
// update fps display
|
|
571
569
|
mainContext.textAlign = 'right';
|
package/src/engineExport.js
CHANGED
package/src/engineInput.js
CHANGED
|
@@ -727,10 +727,10 @@ function inputRender()
|
|
|
727
727
|
function touchGamepadRender()
|
|
728
728
|
{
|
|
729
729
|
if (!touchInputEnable || !isTouchDevice || headlessMode) return;
|
|
730
|
-
if (!touchGamepadEnable || !touchGamepadTimer.isSet()) return;
|
|
730
|
+
if (!touchGamepadEnable || !touchGamepadTimer.isSet() && touchGamepadDisplayTime) return;
|
|
731
731
|
|
|
732
732
|
// fade off when not touching or paused
|
|
733
|
-
const alpha = percent(touchGamepadTimer.get(),
|
|
733
|
+
const alpha = touchGamepadDisplayTime ? percent(touchGamepadTimer.get(), touchGamepadDisplayTime+1, touchGamepadDisplayTime) : 1;
|
|
734
734
|
if (!alpha || paused) return;
|
|
735
735
|
|
|
736
736
|
// setup the canvas
|
package/src/engineMath.js
CHANGED
|
@@ -360,15 +360,17 @@ function lineTest(posStart, posEnd, testFunction, normal)
|
|
|
360
360
|
// set hit point
|
|
361
361
|
const hitPos = vec2(posStart.x + dirX*t, posStart.y + dirY*t);
|
|
362
362
|
|
|
363
|
-
//
|
|
363
|
+
// ensure result is inside the tile
|
|
364
364
|
const e = 1e-9;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
hitPos.y
|
|
365
|
+
const hitPosFloor = hitPos.floor();
|
|
366
|
+
if (hitPosFloor.x < pos.x)
|
|
367
|
+
hitPos.x = pos.x;
|
|
368
|
+
else if (hitPosFloor.x > pos.x)
|
|
369
|
+
hitPos.x = pos.x + 1 - e;
|
|
370
|
+
if (hitPosFloor.y < pos.y)
|
|
371
|
+
hitPos.y = pos.y;
|
|
372
|
+
else if (hitPosFloor.y > pos.y)
|
|
373
|
+
hitPos.y = pos.y + 1 - e;
|
|
372
374
|
|
|
373
375
|
// set normal
|
|
374
376
|
if (normal)
|
package/src/engineSettings.js
CHANGED
|
@@ -260,6 +260,12 @@ let touchGamepadSize = 99;
|
|
|
260
260
|
* @memberof Settings */
|
|
261
261
|
let touchGamepadAlpha = .3;
|
|
262
262
|
|
|
263
|
+
/** How long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
264
|
+
* @type {number}
|
|
265
|
+
* @default
|
|
266
|
+
* @memberof Settings */
|
|
267
|
+
let touchGamepadDisplayTime = 3;
|
|
268
|
+
|
|
263
269
|
/** Allow vibration hardware if it exists
|
|
264
270
|
* @type {boolean}
|
|
265
271
|
* @default
|
|
@@ -534,6 +540,11 @@ function setTouchGamepadSize(size) { touchGamepadSize = size; }
|
|
|
534
540
|
* @memberof Settings */
|
|
535
541
|
function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
|
|
536
542
|
|
|
543
|
+
/** Set how long to display the touch gamepad on screen in seconds, set to 0 to always display
|
|
544
|
+
* @param {number} time
|
|
545
|
+
* @memberof Settings */
|
|
546
|
+
function setTouchGamepadDisplayTime(time) { touchGamepadDisplayTime = time; }
|
|
547
|
+
|
|
537
548
|
/** Set to allow vibration hardware if it exists
|
|
538
549
|
* @param {boolean} enable
|
|
539
550
|
* @memberof Settings */
|