littlejsengine 1.18.1 → 1.18.2

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.js CHANGED
@@ -35,7 +35,7 @@ const engineName = 'LittleJS';
35
35
  * @type {string}
36
36
  * @default
37
37
  * @memberof Engine */
38
- const engineVersion = '1.18.1';
38
+ const engineVersion = '1.18.2';
39
39
 
40
40
  /** Frames per second to update
41
41
  * @type {number}
@@ -3003,18 +3003,22 @@ let touchInputEnable = true;
3003
3003
 
3004
3004
  /** True if touch gamepad should appear on mobile devices
3005
3005
  * - Supports left analog stick, 4 face buttons and start button (button 9)
3006
+ * - setTouchGamepadButtonCount(1) to use face buttons as right analog stick
3007
+ * - Analog stick buttons 10 and 11 are also activated when virtual sticks are touched
3008
+
3006
3009
  * @type {boolean}
3007
3010
  * @default
3008
3011
  * @memberof Settings */
3009
3012
  let touchGamepadEnable = false;
3010
3013
 
3011
3014
  /** True if touch gamepad should have start button in the center
3015
+ * - Prevents activating if overlappng with virtual stick or buttons if they are enabled
3012
3016
  * - When the game is paused, any touch will press the button
3013
- * - This can function as a way to pause/unpause the game
3014
- * @type {boolean}
3017
+ * - Set size to enable the center button
3018
+ * @type {number}
3015
3019
  * @default
3016
3020
  * @memberof Settings */
3017
- let touchGamepadCenterButton = true;
3021
+ let touchGamepadCenterButtonSize = 300;
3018
3022
 
3019
3023
  /** Number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
3020
3024
  * @type {number}
@@ -3032,7 +3036,7 @@ let touchGamepadAnalog = true;
3032
3036
  * @type {number}
3033
3037
  * @default
3034
3038
  * @memberof Settings */
3035
- let touchGamepadSize = 99;
3039
+ let touchGamepadSize = 100;
3036
3040
 
3037
3041
  /** Transparency of touch gamepad overlay
3038
3042
  * @type {number}
@@ -3300,11 +3304,12 @@ function setTouchInputEnable(enable) { touchInputEnable = enable; }
3300
3304
  * @memberof Settings */
3301
3305
  function setTouchGamepadEnable(enable) { touchGamepadEnable = enable; }
3302
3306
 
3303
- /** True if touch gamepad should have start button in the center
3304
- * - This can function as a way to pause/unpause the game
3305
- * @param {boolean} enable
3307
+ /** Set if touch gamepad should have start button in the center
3308
+ * - Set size to enable the center button
3309
+ * - When the game is paused, any touch will press the button
3310
+ * @param {number} size
3306
3311
  * @memberof Settings */
3307
- function setTouchGamepadCenterButton(enable) { touchGamepadCenterButton = enable; }
3312
+ function setTouchGamepadCenterButtonSize(size) { touchGamepadCenterButtonSize = size; }
3308
3313
 
3309
3314
  /** Set number of buttons on touch gamepad (0-4), if 1 also acts as right analog stick
3310
3315
  * @param {number} count
@@ -3842,6 +3847,7 @@ class EngineObject
3842
3847
  child.parent = this;
3843
3848
  child.localPos = localPos.copy();
3844
3849
  child.localAngle = localAngle;
3850
+ child.updateTransforms();
3845
3851
  return child;
3846
3852
  }
3847
3853
 
@@ -5573,7 +5579,7 @@ function inputInit()
5573
5579
  if (touching)
5574
5580
  {
5575
5581
  touchGamepadTimer.set();
5576
- if (touchGamepadCenterButton && !wasTouching && paused)
5582
+ if (touchGamepadCenterButtonSize && !wasTouching && paused)
5577
5583
  {
5578
5584
  // touch anywhere to press start when paused
5579
5585
  touchGamepadButtons[9] = 1;
@@ -5598,6 +5604,7 @@ function inputInit()
5598
5604
  // virtual analog stick
5599
5605
  const delta = touchPos.subtract(stickCenter);
5600
5606
  touchGamepadSticks[0] = delta.scale(2/touchGamepadSize).clampLength();
5607
+ touchGamepadButtons[10] = 1; // also press a button when touching stick
5601
5608
  }
5602
5609
  else if (buttonCenter.distance(touchPos) < touchGamepadSize)
5603
5610
  {
@@ -5606,6 +5613,7 @@ function inputInit()
5606
5613
  // virtual right analog stick
5607
5614
  const delta = touchPos.subtract(buttonCenter);
5608
5615
  touchGamepadSticks[1] = delta.scale(2/touchGamepadSize).clampLength();
5616
+ touchGamepadButtons[11] = 1; // also press a button when touching right stick
5609
5617
  }
5610
5618
  // virtual face buttons
5611
5619
  let button = buttonCenter.subtract(touchPos).direction();
@@ -5622,8 +5630,7 @@ function inputInit()
5622
5630
  if (button < touchGamepadButtonCount)
5623
5631
  touchGamepadButtons[button] = 1;
5624
5632
  }
5625
- else if (touchGamepadCenterButton &&
5626
- startCenter.distance(touchPos) < touchGamepadSize)
5633
+ else if (startCenter.distance(touchPos) < touchGamepadCenterButtonSize)
5627
5634
  {
5628
5635
  // virtual start button in center
5629
5636
  touchGamepadButtons[9] = 1;
@@ -5672,6 +5679,18 @@ function inputUpdate()
5672
5679
  // update touch gamepad if enabled
5673
5680
  if (touchGamepadEnable && isTouchDevice)
5674
5681
  {
5682
+ if (debugGamepads)
5683
+ {
5684
+ const stickCenter = vec2(touchGamepadSize, mainCanvasSize.y-touchGamepadSize);
5685
+ const buttonCenter = touchGamepadButtonCenter();
5686
+ const startCenter = mainCanvasSize.scale(.5);
5687
+
5688
+ debugCircle(stickCenter, 2*touchGamepadSize, 'cyan', 0, false, true);
5689
+ debugCircle(buttonCenter, 2*touchGamepadSize, 'cyan', 0, false, true);
5690
+ if (touchGamepadCenterButtonSize)
5691
+ debugCircle(startCenter, 2*touchGamepadCenterButtonSize, 'cyan', 0, false, true);
5692
+ }
5693
+
5675
5694
  if (!touchGamepadTimer.isSet()) return;
5676
5695
 
5677
5696
  // read virtual analog stick
@@ -5699,7 +5718,7 @@ function inputUpdate()
5699
5718
 
5700
5719
  // read virtual gamepad buttons
5701
5720
  const data = inputData[1] ?? (inputData[1] = []);
5702
- for (let i=10; i--;)
5721
+ for (let i=12; i--;)
5703
5722
  {
5704
5723
  const wasDown = gamepadIsDown(i,0);
5705
5724
  data[i] = touchGamepadButtons[i] ? wasDown ? 1 : 3 : wasDown ? 4 : 0;