2017-09-09 02:17:13 +00:00
|
|
|
// Phaser.Input.Gamepad.Button
|
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var GamepadEvent = require('./events/');
|
|
|
|
|
|
|
|
var Button = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Button (pad, index)
|
|
|
|
{
|
|
|
|
this.pad = pad;
|
|
|
|
|
|
|
|
this.events = pad.events;
|
|
|
|
|
|
|
|
this.index = index;
|
|
|
|
|
2017-09-11 00:28:09 +00:00
|
|
|
// Between 0 and 1
|
2017-09-09 02:17:13 +00:00
|
|
|
this.value = 0;
|
2017-09-11 00:28:09 +00:00
|
|
|
|
|
|
|
// Can be set for Analogue buttons to enable a 'pressure' threshold before considered as 'pressed'
|
|
|
|
this.threshold = 0;
|
|
|
|
|
|
|
|
this.pressed = false;
|
2017-09-09 02:17:13 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
update: function (data)
|
|
|
|
{
|
2017-09-11 00:28:09 +00:00
|
|
|
this.value = data.value;
|
|
|
|
|
|
|
|
if (this.value >= this.threshold)
|
2017-09-09 02:17:13 +00:00
|
|
|
{
|
|
|
|
if (!this.pressed)
|
|
|
|
{
|
|
|
|
this.pressed = true;
|
|
|
|
this.events.dispatch(new GamepadEvent.DOWN(this.pad, this, this.value, data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (this.pressed)
|
|
|
|
{
|
|
|
|
this.pressed = false;
|
|
|
|
this.events.dispatch(new GamepadEvent.UP(this.pad, this, this.value, data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Button;
|