2017-09-09 02:17:13 +00:00
|
|
|
// Phaser.Input.Gamepad.Button
|
|
|
|
|
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
|
|
|
|
var Button = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class Button
|
|
|
|
* @memberOf Phaser.Input.Gamepad
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} pad - [description]
|
|
|
|
* @param {integer} index - [description]
|
|
|
|
*/
|
2017-09-09 02:17:13 +00:00
|
|
|
function Button (pad, index)
|
|
|
|
{
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {[type]} pad
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-09 02:17:13 +00:00
|
|
|
this.pad = pad;
|
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {[type]} events
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-09 02:17:13 +00:00
|
|
|
this.events = pad.events;
|
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @property {integer} index
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-09 02:17:13 +00:00
|
|
|
this.index = index;
|
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* Between 0 and 1.
|
|
|
|
*
|
|
|
|
* @property {float} value
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-09 02:17:13 +00:00
|
|
|
this.value = 0;
|
2017-09-11 00:28:09 +00:00
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* Can be set for Analogue buttons to enable a 'pressure' threshold before considered as 'pressed'.
|
|
|
|
*
|
|
|
|
* @property {float} threshold
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-11 00:28:09 +00:00
|
|
|
this.threshold = 0;
|
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* Is the Button being pressed down or not?
|
|
|
|
*
|
|
|
|
* @property {boolean} pressed
|
|
|
|
* @default false
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-09-11 00:28:09 +00:00
|
|
|
this.pressed = false;
|
2017-09-09 02:17:13 +00:00
|
|
|
},
|
|
|
|
|
2018-01-26 06:55:15 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @method Phaser.Input.Gamepad.Button#update
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {[type]} data - [description]
|
|
|
|
*/
|
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;
|
2018-01-12 17:09:09 +00:00
|
|
|
this.events.emit('down', this.pad, this, this.value, data);
|
2017-09-09 02:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-12 17:09:09 +00:00
|
|
|
else if (this.pressed)
|
2017-09-09 02:17:13 +00:00
|
|
|
{
|
2018-01-12 17:09:09 +00:00
|
|
|
this.pressed = false;
|
|
|
|
this.events.emit('up', this.pad, this, this.value, data);
|
2017-09-09 02:17:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Button;
|