Skip to content

Commit 7104526

Browse files
committed
The Gamepad Axis getValue method now correctly applies the threshold and zeroes out the returned value.
1 parent 88a228e commit 7104526

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ being passed to the simulation. The default value is 1 to remain consistent with
2626
* The RenderTexture now uses the ComputedSize component instead of Size (which requires a frame), allowing calls to getBounds to work. Fix #3451 (thanks @kuoruan)
2727
* PathFollower.start has been renamed to `startFollow`, but PathFollower.setPath was still using `PathFollower.start` (thanks @samid737)
2828
* BaseSoundManager.rate and BaseSoundManager.detune would incorrectly called `setRate` on its sounds, instead of `calculateRate`.
29+
* The Gamepad Axis `getValue` method now correctly applies the threshold and zeroes out the returned value.
2930

3031
### Updates
3132

@@ -36,6 +37,7 @@ being passed to the simulation. The default value is 1 to remain consistent with
3637
* Renamed the Camera Controls module exports for `Fixed` to `FixedKeyControl` and `Smoothed` to `SmoothedKeyControl` to match the class names. Fix #3463 (thanks @seivan)
3738
* The ComputedSize Component now has `setSize` and `setDisplaySize` methods. This component is used for Game Objects that have a non-texture based size.
3839
* The GamepadManager now extends EventEmitter directly, just like the KeyboardManager does.
40+
* The Gamepad Axis threshold has been increased from 0.05 to 0.1.
3941

4042
Also, my thanks to the following for helping with the Phaser 3 Examples, either by reporting errors or fixing them: @gabegordon @melissaelopez @samid737 @nbs @tgrajewski
4143

src/input/gamepad/Axis.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ var Axis = new Class({
5252
this.index = index;
5353

5454
/**
55-
* Between -1 and 1 with 0 being dead center.
55+
* The raw axis value, between -1 and 1 with 0 being dead center.
56+
* Use the method `getValue` to get a normalized value with the threshold applied.
5657
*
5758
* @name Phaser.Input.Gamepad.Axis#value
5859
* @type {float}
@@ -62,14 +63,14 @@ var Axis = new Class({
6263
this.value = 0;
6364

6465
/**
65-
* Movement tolerance threshold.
66+
* Movement tolerance threshold below which axis values are ignored in `getValue`.
6667
*
6768
* @name Phaser.Input.Gamepad.Axis#threshold
6869
* @type {float}
69-
* @default 0.05
70+
* @default 0.1
7071
* @since 3.0.0
7172
*/
72-
this.threshold = 0.05;
73+
this.threshold = 0.1;
7374
},
7475

7576
/**
@@ -95,14 +96,7 @@ var Axis = new Class({
9596
*/
9697
getValue: function ()
9798
{
98-
var percentage = (Math.abs(this.value) - this.threshold) / (1 - this.threshold);
99-
100-
if (percentage < 0)
101-
{
102-
percentage = 0;
103-
}
104-
105-
return percentage * (this.value > 0 ? 1 : -1);
99+
return (Math.abs(this.value) < this.threshold) ? 0 : this.value;
106100
}
107101

108102
});

src/input/gamepad/Gamepad.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,10 @@ var Gamepad = new Class({
134134
{
135135
axes[i] = new Axis(this, i);
136136
}
137-
138-
axes[i].update(axisData);
137+
else
138+
{
139+
axes[i].update(axisData);
140+
}
139141
}
140142
}
141143

0 commit comments

Comments
 (0)