GamePad and SinglePad onAxisCallback parameters have changed. You are now sent: this (a reference to the SinglePad that caused the callback), the axis index and the axis value in that order.

GamePad axis detection now works again properly in Firefox (#1035)
This commit is contained in:
photonstorm 2014-08-29 15:55:05 +01:00
parent 32119e9892
commit 7b9c1a561e
3 changed files with 45 additions and 29 deletions

View file

@ -119,6 +119,7 @@ Version 2.1.0 - "Cairhien" - -in development-
* P2.InversePointProxy.x and y values are now returned in pixels (previously they were returned in meters). See PointProxy.mx/my for meter values.
* Arcade.overlap and collide are now more consistent about allowing a Group vs. Group or Group vs. Array of Groups set (thanks @pyromanfo #877 #1147)
* The Pointer move callbacks are now sent an extra parameter: `fromClick` allowing your callbacks to distinguish between the Pointer just moving, or moving as a result of being pressed down (thanks @iforce2d #1055)
* GamePad and SinglePad onAxisCallback parameters have changed. You are now sent: this (a reference to the SinglePad that caused the callback), the axis index and the axis value in that order.
### Bug Fixes
@ -145,6 +146,7 @@ Version 2.1.0 - "Cairhien" - -in development-
* The P2.World.postBroadphaseHandler now checks if the returned pairs array is empty or not before processing it (thanks @wayfu #934)
* Tilemap.hasTile now checks the Tile.index value and will return false if the index is -1 (i.e. a non-active tile) (thanks @elgansayer #859)
* Sound.restart used to cause the Sound to double-up if it was already playing when called. Now correctly stops the sound before restarting it (thanks @wombatbuddy #1136)
* GamePad axis detection now works again properly in Firefox (#1035)
### p2.js 0.6.0 Changes and New Features

View file

@ -24,17 +24,6 @@ Phaser.Gamepad = function (game) {
*/
this.game = game;
/**
* @property {Array<Phaser.SinglePad>} _gamepads - The four Phaser Gamepads.
* @private
*/
this._gamepads = [
new Phaser.SinglePad(game, this),
new Phaser.SinglePad(game, this),
new Phaser.SinglePad(game, this),
new Phaser.SinglePad(game, this)
];
/**
* @property {Object} _gamepadIndexMap - Maps the browsers gamepad indices to our Phaser Gamepads
* @private
@ -131,6 +120,17 @@ Phaser.Gamepad = function (game) {
*/
this._gamepaddisconnected = null;
/**
* @property {Array<Phaser.SinglePad>} _gamepads - The four Phaser Gamepads.
* @private
*/
this._gamepads = [
new Phaser.SinglePad(game, this),
new Phaser.SinglePad(game, this),
new Phaser.SinglePad(game, this),
new Phaser.SinglePad(game, this)
];
};
Phaser.Gamepad.prototype = {
@ -172,6 +172,16 @@ Phaser.Gamepad.prototype = {
this._active = true;
var _this = this;
this._onGamepadConnected = function (event) {
return _this.onGamepadConnected(event);
};
this._onGamepadDisconnected = function (event) {
return _this.onGamepadDisconnected(event);
};
window.addEventListener('gamepadconnected', this._onGamepadConnected, false);
window.addEventListener('gamepaddisconnected', this._onGamepadDisconnected, false);
@ -180,14 +190,13 @@ Phaser.Gamepad.prototype = {
/**
* Handles the connection of a Gamepad.
*
* @method _onGamepadConnected
* @method onGamepadConnected
* @private
* @param {object} event - The DOM event.
*/
_onGamepadConnected: function (event) {
onGamepadConnected: function (event) {
var newPad = event.gamepad;
this._rawPads.push(newPad);
this._gamepads[newPad.index].connect(newPad);
@ -196,11 +205,11 @@ Phaser.Gamepad.prototype = {
/**
* Handles the disconnection of a Gamepad.
*
* @method _onGamepadDisconnected
* @method onGamepadDisconnected
* @private
* @param {object} event - The DOM event.
*/
_onGamepadDisconnected: function (event) {
onGamepadDisconnected: function (event) {
var removedPad = event.gamepad;
@ -619,6 +628,7 @@ Phaser.Gamepad.XBOX360_DPAD_RIGHT = 15;
Phaser.Gamepad.XBOX360_DPAD_UP = 12;
Phaser.Gamepad.XBOX360_DPAD_DOWN = 13;
// On FF 0 = Y, 1 = X, 2 = Y, 3 = X, 4 = left bumper, 5 = dpad left, 6 = dpad right
Phaser.Gamepad.XBOX360_STICK_LEFT_X = 0;
Phaser.Gamepad.XBOX360_STICK_LEFT_Y = 1;
Phaser.Gamepad.XBOX360_STICK_RIGHT_X = 2;

View file

@ -161,7 +161,7 @@ Phaser.SinglePad.prototype = {
},
/**
* Main update function, should be called by Phaser.Gamepad.
* Main update function called by Phaser.Gamepad.
*
* @method Phaser.SinglePad#pollStatus
*/
@ -192,19 +192,18 @@ Phaser.SinglePad.prototype = {
}
}
}
for (var j = 0; j < this._axesLen; j++)
for (var index = 0; index < this._axesLen; index++)
{
var axis = this._rawPad.axes[j];
var value = this._rawPad.axes[index];
if (axis > 0 && axis > this.deadZone || axis < 0 && axis < -this.deadZone)
if ((value > 0 && value > this.deadZone) || (value < 0 && value < -this.deadZone))
{
this.processAxisChange( { axis: j, value: axis } );
this.processAxisChange(index, value);
}
else
{
this.processAxisChange( { axis: j, value: 0 } );
this.processAxisChange(index, 0);
}
}
@ -230,9 +229,14 @@ Phaser.SinglePad.prototype = {
this._buttons = [];
this._buttonsLen = rawPad.buttons.length;
this._axes = rawPad.axes;
this._axes = [];
this._axesLen = rawPad.axes.length;
for (var a = 0; a < this._axesLen; a++)
{
this._axes[a] = rawPad.axes[a];
}
for (var buttonCode in rawPad.buttons)
{
buttonCode = parseInt(buttonCode, 10);
@ -324,23 +328,23 @@ Phaser.SinglePad.prototype = {
* @method Phaser.SinglePad#processAxisChange
* @param {Object} axisState - State of the relevant axis
*/
processAxisChange: function (axisState) {
processAxisChange: function (index, value) {
if (this._axes[axisState.axis] === axisState.value)
if (this._axes[index] === value)
{
return;
}
this._axes[axisState.axis] = axisState.value;
this._axes[index] = value;
if (this._padParent.onAxisCallback)
{
this._padParent.onAxisCallback.call(this._padParent.callbackContext, axisState, this.index);
this._padParent.onAxisCallback.call(this._padParent.callbackContext, this, index, value);
}
if (this.onAxisCallback)
{
this.onAxisCallback.call(this.callbackContext, axisState);
this.onAxisCallback.call(this.callbackContext, this, index, value);
}
},