forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
47 lines (34 loc) · 969 Bytes
/
Copy pathButton.js
File metadata and controls
47 lines (34 loc) · 969 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
44
45
46
47
// Phaser.Input.Gamepad.Button
var Class = require('../../utils/Class');
var Button = new Class({
initialize:
function Button (pad, index)
{
this.pad = pad;
this.events = pad.events;
this.index = index;
// Between 0 and 1
this.value = 0;
// Can be set for Analogue buttons to enable a 'pressure' threshold before considered as 'pressed'
this.threshold = 0;
this.pressed = false;
},
update: function (data)
{
this.value = data.value;
if (this.value >= this.threshold)
{
if (!this.pressed)
{
this.pressed = true;
this.events.emit('down', this.pad, this, this.value, data);
}
}
else if (this.pressed)
{
this.pressed = false;
this.events.emit('up', this.pad, this, this.value, data);
}
}
});
module.exports = Button;