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
114 lines (101 loc) · 2.54 KB
/
Copy pathButton.js
File metadata and controls
114 lines (101 loc) · 2.54 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../utils/Class');
/**
* @classdesc
* [description]
*
* @class Button
* @memberOf Phaser.Input.Gamepad
* @constructor
* @since 3.0.0
*
* @param {Phaser.Input.Gamepad.Gamepad} pad - [description]
* @param {integer} index - [description]
*/
var Button = new Class({
initialize:
function Button (pad, index)
{
/**
* [description]
*
* @name Phaser.Input.Gamepad.Button#pad
* @type {Phaser.Input.Gamepad.Gamepad}
* @since 3.0.0
*/
this.pad = pad;
/**
* [description]
*
* @name Phaser.Input.Gamepad.Button#events
* @type {Phaser.Events.EventEmitter}
* @since 3.0.0
*/
this.events = pad.manager;
/**
* [description]
*
* @name Phaser.Input.Gamepad.Button#index
* @type {integer}
* @since 3.0.0
*/
this.index = index;
/**
* Between 0 and 1.
*
* @name Phaser.Input.Gamepad.Button#value
* @type {float}
* @default 0
* @since 3.0.0
*/
this.value = 0;
/**
* Can be set for Analogue buttons to enable a 'pressure' threshold before considered as 'pressed'.
*
* @name Phaser.Input.Gamepad.Button#threshold
* @type {float}
* @default 1
* @since 3.0.0
*/
this.threshold = 1;
/**
* Is the Button being pressed down or not?
*
* @name Phaser.Input.Gamepad.Button#pressed
* @type {boolean}
* @default false
* @since 3.0.0
*/
this.pressed = false;
},
/**
* [description]
*
* @method Phaser.Input.Gamepad.Button#update
* @since 3.0.0
*
* @param {GamepadButton} data - [description]
*/
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;