littlejsengine 1.17.15 → 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.15';
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';
@@ -3016,6 +3014,12 @@ let touchGamepadSize = 99;
3016
3014
  * @memberof Settings */
3017
3015
  let touchGamepadAlpha = .3;
3018
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
+
3019
3023
  /** Allow vibration hardware if it exists
3020
3024
  * @type {boolean}
3021
3025
  * @default
@@ -3290,6 +3294,11 @@ function setTouchGamepadSize(size) { touchGamepadSize = size; }
3290
3294
  * @memberof Settings */
3291
3295
  function setTouchGamepadAlpha(alpha) { touchGamepadAlpha = alpha; }
3292
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
+
3293
3302
  /** Set to allow vibration hardware if it exists
3294
3303
  * @param {boolean} enable
3295
3304
  * @memberof Settings */
@@ -5761,10 +5770,10 @@ function inputRender()
5761
5770
  function touchGamepadRender()
5762
5771
  {
5763
5772
  if (!touchInputEnable || !isTouchDevice || headlessMode) return;
5764
- if (!touchGamepadEnable || !touchGamepadTimer.isSet()) return;
5773
+ if (!touchGamepadEnable || !touchGamepadTimer.isSet() && touchGamepadDisplayTime) return;
5765
5774
 
5766
5775
  // fade off when not touching or paused
5767
- const alpha = percent(touchGamepadTimer.get(), 4, 3);
5776
+ const alpha = touchGamepadDisplayTime ? percent(touchGamepadTimer.get(), touchGamepadDisplayTime+1, touchGamepadDisplayTime) : 1;
5768
5777
  if (!alpha || paused) return;
5769
5778
 
5770
5779
  // setup the canvas
@@ -9335,7 +9344,7 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)
9335
9344
  * - Buttons
9336
9345
  * - Checkboxes
9337
9346
  * - Images
9338
- * - Scrollbars
9347
+ * - Sliders
9339
9348
  * - Video
9340
9349
  * @namespace UISystem
9341
9350
  */
@@ -10532,7 +10541,7 @@ class UICheckbox extends UIObject
10532
10541
  ASSERT(isString(text), 'ui checkbox must be a string');
10533
10542
  ASSERT(isColor(color), 'ui checkbox color must be a color');
10534
10543
 
10535
- /** @property {boolean} - Current percentage value of this scrollbar 0-1 */
10544
+ /** @property {boolean} - Current percentage value of this slider 0-1 */
10536
10545
  this.checked = checked;
10537
10546
  // set properties
10538
10547
  this.text = text;
@@ -10567,13 +10576,13 @@ class UICheckbox extends UIObject
10567
10576
 
10568
10577
  ///////////////////////////////////////////////////////////////////////////////
10569
10578
  /**
10570
- * UIScrollbar - A UI object that acts as a scrollbar
10579
+ * UISlider - A UI object that acts as a slider or scrollbar
10571
10580
  * @extends UIObject
10572
10581
  * @memberof UISystem
10573
10582
  */
10574
- class UIScrollbar extends UIObject
10583
+ class UISlider extends UIObject
10575
10584
  {
10576
- /** Create a UIScrollbar object
10585
+ /** Create a UISlider object
10577
10586
  * @param {Vector2} [pos]
10578
10587
  * @param {Vector2} [size]
10579
10588
  * @param {number} [value]
@@ -10585,14 +10594,14 @@ class UIScrollbar extends UIObject
10585
10594
  {
10586
10595
  super(pos, size);
10587
10596
 
10588
- ASSERT(isNumber(value), 'ui scrollbar value must be a number');
10589
- ASSERT(isString(text), 'ui scrollbar must be a string');
10590
- ASSERT(isColor(color), 'ui scrollbar color must be a color');
10591
- 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');
10592
10601
 
10593
- /** @property {number} - Current percentage value of this scrollbar 0-1 */
10602
+ /** @property {number} - Current percentage value of this slider 0-1 */
10594
10603
  this.value = value;
10595
- /** @property {Color} - Color for the handle part of the scrollbar */
10604
+ /** @property {Color} - Color for the handle part of the slider */
10596
10605
  this.handleColor = handleColor.copy();
10597
10606
  /** @property {boolean} - Should it fill up like a progress bar? */
10598
10607
  this.fillMode = false;
@@ -10611,7 +10620,7 @@ class UIScrollbar extends UIObject
10611
10620
  const oldValue = this.value;
10612
10621
  if (this.isActiveObject())
10613
10622
  {
10614
- // handle horizontal or vertical scrollbar
10623
+ // handle horizontal or vertical slider
10615
10624
  const isHorizontal = this.size.x > this.size.y;
10616
10625
  const handleSize = isHorizontal ? this.size.y : this.size.x;
10617
10626
  const barSize = isHorizontal ? this.size.x : this.size.y;
@@ -10639,7 +10648,7 @@ class UIScrollbar extends UIObject
10639
10648
  {
10640
10649
  super.render();
10641
10650
 
10642
- // handle horizontal or vertical scrollbar
10651
+ // handle horizontal or vertical slider
10643
10652
  const isHorizontal = this.size.x > this.size.y;
10644
10653
  const barWidth = isHorizontal ? this.size.x : this.size.y;
10645
10654
  const handleWidth = isHorizontal ? this.size.y : this.size.x;
@@ -10657,7 +10666,7 @@ class UIScrollbar extends UIObject
10657
10666
  }
10658
10667
  else
10659
10668
  {
10660
- // draw the scrollbar handle
10669
+ // draw the slider handle
10661
10670
  const value = clamp(isHorizontal ? this.value : 1 - this.value);
10662
10671
  const p = (barWidth - handleWidth) * (value - .5);
10663
10672
  const pos = this.pos.add(isHorizontal ? vec2(p, 0) : vec2(0, p));
@@ -10666,7 +10675,7 @@ class UIScrollbar extends UIObject
10666
10675
  uiSystem.drawRect(pos, drawSize, color, this.lineWidth, this.lineColor, this.cornerRadius, this.gradientColor);
10667
10676
  }
10668
10677
 
10669
- // draw the text scaled to fit on the scrollbar
10678
+ // draw the text scaled to fit on the slider
10670
10679
  const textSize = this.getTextSize();
10671
10680
  uiSystem.drawText(this.text, this.pos, textSize,
10672
10681
  this.textColor, this.textLineWidth, this.textLineColor, this.align, this.font, this.fontStyle, true, this.textShadow);
@@ -10941,7 +10950,7 @@ class Box2dObject extends EngineObject
10941
10950
  // draw non-edge fixtures
10942
10951
  this.getFixtureList().forEach((fixture)=>
10943
10952
  {
10944
- const shape = box2d.castObjectType(fixture.GetShape());
10953
+ const shape = box2d.castShapeObject(fixture.GetShape());
10945
10954
  if (shape.GetType() !== box2d.instance.b2Shape.e_edge)
10946
10955
  {
10947
10956
  box2d.drawFixture(fixture, this.pos, this.angle, color, lineColor, lineWidth, useWebGL, context);
@@ -11581,7 +11590,7 @@ class Box2dJoint
11581
11590
  constructor(jointDef)
11582
11591
  {
11583
11592
  /** @property {Object} - The Box2d joint */
11584
- this.box2dJoint = box2d.castObjectType(box2d.world.CreateJoint(jointDef));
11593
+ this.box2dJoint = box2d.castJointObject(box2d.world.CreateJoint(jointDef));
11585
11594
  }
11586
11595
 
11587
11596
  /** Destroy this joint */
@@ -11866,7 +11875,7 @@ class Box2dRevoluteJoint extends Box2dJoint
11866
11875
 
11867
11876
  /** Enable/disable the joint limit
11868
11877
  * @param {boolean} [enable] */
11869
- enableLimit(enable=true) { return this.box2dJoint.enableLimit(enable); }
11878
+ enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
11870
11879
 
11871
11880
  /** Get the lower joint limit
11872
11881
  * @return {number} */
@@ -12024,7 +12033,7 @@ class Box2dPrismaticJoint extends Box2dJoint
12024
12033
 
12025
12034
  /** Enable/disable the joint limit
12026
12035
  * @param {boolean} [enable] */
12027
- enableLimit(enable=true) { return this.box2dJoint.enableLimit(enable); }
12036
+ enableLimit(enable=true) { return this.box2dJoint.EnableLimit(enable); }
12028
12037
 
12029
12038
  /** Get the lower joint limit
12030
12039
  * @return {number} */
@@ -12638,7 +12647,7 @@ class Box2dPlugin
12638
12647
  * @param {CanvasRenderingContext2D} [context] */
12639
12648
  drawFixture(fixture, pos, angle, color=WHITE, lineColor=BLACK, lineWidth=.1, useWebgl, context)
12640
12649
  {
12641
- const shape = box2d.castObjectType(fixture.GetShape());
12650
+ const shape = box2d.castShapeObject(fixture.GetShape());
12642
12651
  switch (shape.GetType())
12643
12652
  {
12644
12653
  case box2d.instance.b2Shape.e_polygon:
@@ -12696,9 +12705,9 @@ class Box2dPlugin
12696
12705
  * @param {Object} o */
12697
12706
  isNull(o) { return !box2d.instance.getPointer(o); }
12698
12707
 
12699
- /** casts a box2d object to its correct type
12708
+ /** casts a box2d object to a shape type
12700
12709
  * @param {Object} o */
12701
- castObjectType(o)
12710
+ castShapeObject(o)
12702
12711
  {
12703
12712
  switch (o.GetType())
12704
12713
  {
@@ -12710,6 +12719,17 @@ class Box2dPlugin
12710
12719
  return box2d.instance.castObject(o, box2d.instance.b2PolygonShape);
12711
12720
  case box2d.instance.b2Shape.e_chain:
12712
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
+ {
12713
12733
  case box2d.instance.e_revoluteJoint:
12714
12734
  return box2d.instance.castObject(o, box2d.instance.b2RevoluteJoint);
12715
12735
  case box2d.instance.e_prismaticJoint:
@@ -13064,6 +13084,7 @@ export
13064
13084
  touchGamepadAnalog,
13065
13085
  touchGamepadSize,
13066
13086
  touchGamepadAlpha,
13087
+ touchGamepadDisplayTime,
13067
13088
  vibrateEnable,
13068
13089
  soundEnable,
13069
13090
  soundVolume,
@@ -13360,7 +13381,7 @@ export
13360
13381
  UITile,
13361
13382
  UIButton,
13362
13383
  UICheckbox,
13363
- UIScrollbar,
13384
+ UISlider,
13364
13385
  UIVideo,
13365
13386
 
13366
13387
  // Box2D Physics