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.
@@ -500,6 +500,11 @@ declare module "littlejsengine" {
500
500
  * @default
501
501
  * @memberof Settings */
502
502
  export let touchGamepadAlpha: number;
503
+ /** How long to display the touch gamepad on screen in seconds, set to 0 to always display
504
+ * @type {number}
505
+ * @default
506
+ * @memberof Settings */
507
+ export let touchGamepadDisplayTime: number;
503
508
  /** Allow vibration hardware if it exists
504
509
  * @type {boolean}
505
510
  * @default
@@ -3304,7 +3309,7 @@ declare module "littlejsengine" {
3304
3309
  * - Buttons
3305
3310
  * - Checkboxes
3306
3311
  * - Images
3307
- * - Scrollbars
3312
+ * - Sliders
3308
3313
  * - Video
3309
3314
  * @namespace UISystem
3310
3315
  */
@@ -3719,18 +3724,18 @@ declare module "littlejsengine" {
3719
3724
  * @param {Color} [color=uiSystem.defaultButtonColor]
3720
3725
  */
3721
3726
  constructor(pos?: Vector2, size?: Vector2, checked?: boolean, text?: string, color?: Color);
3722
- /** @property {boolean} - Current percentage value of this scrollbar 0-1 */
3727
+ /** @property {boolean} - Current percentage value of this slider 0-1 */
3723
3728
  checked: boolean;
3724
3729
  text: string;
3725
3730
  click(): void;
3726
3731
  }
3727
3732
  /**
3728
- * UIScrollbar - A UI object that acts as a scrollbar
3733
+ * UISlider - A UI object that acts as a slider or scrollbar
3729
3734
  * @extends UIObject
3730
3735
  * @memberof UISystem
3731
3736
  */
3732
- export class UIScrollbar extends UIObject {
3733
- /** Create a UIScrollbar object
3737
+ export class UISlider extends UIObject {
3738
+ /** Create a UISlider object
3734
3739
  * @param {Vector2} [pos]
3735
3740
  * @param {Vector2} [size]
3736
3741
  * @param {number} [value]
@@ -3739,9 +3744,9 @@ declare module "littlejsengine" {
3739
3744
  * @param {Color} [handleColor=WHITE]
3740
3745
  */
3741
3746
  constructor(pos?: Vector2, size?: Vector2, value?: number, text?: string, color?: Color, handleColor?: Color);
3742
- /** @property {number} - Current percentage value of this scrollbar 0-1 */
3747
+ /** @property {number} - Current percentage value of this slider 0-1 */
3743
3748
  value: number;
3744
- /** @property {Color} - Color for the handle part of the scrollbar */
3749
+ /** @property {Color} - Color for the handle part of the slider */
3745
3750
  handleColor: Color;
3746
3751
  /** @property {boolean} - Should it fill up like a progress bar? */
3747
3752
  fillMode: boolean;
@@ -3921,9 +3926,12 @@ declare module "littlejsengine" {
3921
3926
  /** checks if a box2d object is null
3922
3927
  * @param {Object} o */
3923
3928
  isNull(o: any): boolean;
3924
- /** casts a box2d object to its correct type
3929
+ /** casts a box2d object to a shape type
3930
+ * @param {Object} o */
3931
+ castShapeObject(o: any): any;
3932
+ /** casts a box2d object to a joint type
3925
3933
  * @param {Object} o */
3926
- castObjectType(o: any): any;
3934
+ castJointObject(o: any): any;
3927
3935
  }
3928
3936
  /**
3929
3937
  * Box2D Object - extend with your own custom physics objects
@@ -35,7 +35,7 @@ const engineName = 'LittleJS';
35
35
  * @type {string}
36
36
  * @default
37
37
  * @memberof Engine */
38
- const engineVersion = '1.17.14';
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
- // move inside of tile if on positive edge
1768
+ // ensure result is inside the tile
1771
1769
  const e = 1e-9;
1772
- if (wasX)
1773
- {
1774
- if (stepX < 0)
1775
- hitPos.x -= e;
1776
- }
1777
- else if (stepY < 0)
1778
- hitPos.y -= e;
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(), 4, 3);
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
- * - Scrollbars
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 scrollbar 0-1 */
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
- * UIScrollbar - A UI object that acts as a scrollbar
10579
+ * UISlider - A UI object that acts as a slider or scrollbar
10569
10580
  * @extends UIObject
10570
10581
  * @memberof UISystem
10571
10582
  */
10572
- class UIScrollbar extends UIObject
10583
+ class UISlider extends UIObject
10573
10584
  {
10574
- /** Create a UIScrollbar object
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 scrollbar value must be a number');
10587
- ASSERT(isString(text), 'ui scrollbar must be a string');
10588
- ASSERT(isColor(color), 'ui scrollbar color must be a color');
10589
- ASSERT(isColor(handleColor), 'ui scrollbar handleColor must be a color');
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 scrollbar 0-1 */
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 scrollbar */
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 scrollbar
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 scrollbar
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 scrollbar handle
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 scrollbar
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.castObjectType(fixture.GetShape());
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.castObjectType(box2d.world.CreateJoint(jointDef));
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.enableLimit(enable); }
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.enableLimit(enable); }
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.castObjectType(fixture.GetShape());
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 its correct type
12708
+ /** casts a box2d object to a shape type
12698
12709
  * @param {Object} o */
12699
- castObjectType(o)
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:
@@ -13062,6 +13084,7 @@ export
13062
13084
  touchGamepadAnalog,
13063
13085
  touchGamepadSize,
13064
13086
  touchGamepadAlpha,
13087
+ touchGamepadDisplayTime,
13065
13088
  vibrateEnable,
13066
13089
  soundEnable,
13067
13090
  soundVolume,
@@ -13358,7 +13381,7 @@ export
13358
13381
  UITile,
13359
13382
  UIButton,
13360
13383
  UICheckbox,
13361
- UIScrollbar,
13384
+ UISlider,
13362
13385
  UIVideo,
13363
13386
 
13364
13387
  // Box2D Physics