Skip to content

Commit aa3b71f

Browse files
committed
Adding partial support for gamepad pausing - Phaser 2.6 prevents gamepad inputs on pause
1 parent 49e95a6 commit aa3b71f

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/old/environment/UserControl.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,16 @@ p.initExternalJoypad = function () {
6060
game.externalJoypad.down = this.gamepad.getButton(Phaser.Gamepad.BUTTON_13);
6161
game.externalJoypad.left = this.gamepad.getButton(Phaser.Gamepad.BUTTON_14);
6262
game.externalJoypad.right = this.gamepad.getButton(Phaser.Gamepad.BUTTON_15);
63+
game.externalJoypad.selectPressed = this.gamepad.getButton(Phaser.Gamepad.BUTTON_8);
64+
game.externalJoypad.startPressed = this.gamepad.getButton(Phaser.Gamepad.BUTTON_9);
6365
this.gotoInputMode(); //hide virtual gamepad
6466
}.bind(this)
6567
};
6668
this.gamepad.addCallbacks(this, connectionObj);
6769
this.gamepad2.addCallbacks(this, connectionObj);
70+
// this.gamepad.onUpCallback = function(val, i) {
71+
// console.log("gamepad", val, i);
72+
// };
6873
game.input.gamepad.start();
6974
};
7075

src/old/states/play.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ module.exports = {
203203
if (this.uiMode || this.isGameOver) {
204204
ui.update(this.uiMode);
205205
}
206-
if (game.controls.useExternalJoypad &&
207-
gameState.trainingMode &&
208-
ui.missionDialog.enabled) {
209-
ui.missionDialog.update();
210-
}
206+
// if (game.controls.useExternalJoypad &&
207+
// gameState.trainingMode &&
208+
// ui.missionDialog.enabled) {
209+
// ui.missionDialog.update();
210+
// }
211211
if (this.isDevMode) {
212212
this.devModeUpdate();
213213
}
@@ -914,7 +914,7 @@ module.exports = {
914914
if (this.uiPaused) {
915915
this.uiPaused.destroy();
916916
}
917-
this.uiPaused = game.add.text(game.width / 2, game.height / 2, "GAME PAUSED", style);
917+
this.uiPaused = game.add.text(game.width / 2, game.height / 2, "GAME PAUSED\n\nHIT ESCAPE or TAP SCREEN", style);
918918
this.uiPaused.anchor.setTo(0.5);
919919
this.uiPaused.fixedToCamera = true;
920920
this.uiPaused.visible = false;
@@ -1046,17 +1046,7 @@ module.exports = {
10461046
* @method initControls
10471047
*/
10481048
initControls: function () {
1049-
10501049
console.log("play :: initControls : options.controls=", game.controls.useKeys, options.controls);
1051-
1052-
if (game.controls.useVirtualJoypad && !game.controls.useExternalJoypad) {
1053-
//game.controls.buttonA.onDown.add(this.pressButtonA, this);
1054-
//game.controls.buttonA.onUp.add(this.upButtonA, this);
1055-
//game.controls.buttonB.onDown.add(this.pressButtonB, this);
1056-
//game.controls.buttonB.onUp.add(this.upButtonB, this);
1057-
//game.controls.fireButtonDown.add(this.pressButtonA, this);
1058-
//game.controls.fireButtonUp.add(this.upButtonA, this);
1059-
}
10601050
if (game.controls.useKeys || game.controls.useVirtualJoypad) {
10611051
if (options.controls.classicKeys) {
10621052
game.controls.cursors.up = game.controls.keyShiftPress;
@@ -1071,12 +1061,24 @@ module.exports = {
10711061
game.controls.xKey.onUp.add(this.xUp, this);
10721062
game.controls.esc.onUp.add(this.escPressed, this);
10731063
}
1064+
if (game.controls.useExternalJoypad) {
1065+
game.controls.gamepad.onUpCallback = function(val, index) {
1066+
// console.log("gamepad", val, i);
1067+
if (val === 9 || val === 8) {
1068+
this.escPressed();
1069+
}
1070+
}.bind(this);
1071+
}
1072+
1073+
1074+
10741075
},
10751076

10761077
/**
10771078
* @method escPressed
10781079
*/
10791080
escPressed: function () {
1081+
console.log("esc pressed");
10801082
game.paused = this.uiPaused.visible = !game.paused;
10811083
},
10821084

0 commit comments

Comments
 (0)