forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAxis.js
More file actions
43 lines (29 loc) · 773 Bytes
/
Copy pathAxis.js
File metadata and controls
43 lines (29 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Phaser.Input.Gamepad.Axis
var Class = require('../../utils/Class');
var Axis = new Class({
initialize:
function Axis (pad, index)
{
this.pad = pad;
this.events = pad.events;
this.index = index;
// Between -1 and 1 with 0 being dead center
this.value = 0;
this.threshold = 0.05;
},
update: function (value)
{
this.value = value;
},
// Applies threshold to the value and returns it
getValue: function ()
{
var percentage = (Math.abs(this.value) - this.threshold) / (1 - this.threshold);
if (percentage < 0)
{
percentage = 0;
}
return percentage * (this.value > 0 ? 1 : -1);
}
});
module.exports = Axis;