diff options
author | Justin Worthe <justin.worthe@entelect.co.za> | 2014-07-18 17:34:53 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@entelect.co.za> | 2014-07-18 17:34:53 +0200 |
commit | 76c53168629511ec46124ed221044d210e4f87c6 (patch) | |
tree | 52033fd81604b415a174d7d752f286441352237d | |
parent | 920eccd0fe8a8acc6ff03f4333a400a9782f6d1a (diff) |
Started adding gamepad support
-rw-r--r-- | game/states/play.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/game/states/play.js b/game/states/play.js index ca259b4..aed4f90 100644 --- a/game/states/play.js +++ b/game/states/play.js @@ -33,6 +33,7 @@ Play.prototype = { preload: function() { }, create: function() { + this.game.input.gamepad.start(); this.readLevelFile(); this.world.scale = {x:50, y:50}; @@ -121,6 +122,9 @@ Play.prototype = { right: Phaser.Keyboard.RIGHT }; + var padA = this.game.input.gamepad.pad1; + var padB = this.game.input.gamepad.pad2; + function addKeyCaptures(controls, keyboard) { for (var index in controls) { if (controls.hasOwnProperty(index)) { @@ -135,6 +139,10 @@ Play.prototype = { this.game.input.keyboard.addKey(this.playerAControls.down).onDown.add(this.movePlayer.bind(this, this.playerA, 0, 1), this); this.game.input.keyboard.addKey(this.playerAControls.left).onDown.add(this.movePlayer.bind(this, this.playerA, -1, 0), this); this.game.input.keyboard.addKey(this.playerAControls.right).onDown.add(this.movePlayer.bind(this, this.playerA, 1, 0), this); + padA.getButton(Phaser.Gamepad.XBOX360_DPAD_UP).onDown.add(this.movePlayer.bind(this, this.playerA, 0, -1), this); + padA.getButton(Phaser.Gamepad.XBOX360_DPAD_DOWN).onDown.add(this.movePlayer.bind(this, this.playerA, 0, 1), this); + padA.getButton(Phaser.Gamepad.XBOX360_DPAD_LEFT).onDown.add(this.movePlayer.bind(this, this.playerA, -1, 0), this); + padA.getButton(Phaser.Gamepad.XBOX360_DPAD_RIGHT).onDown.add(this.movePlayer.bind(this, this.playerA, 1, 0), this); this.game.input.keyboard.addKey(this.playerBControls.up).onDown.add(this.movePlayer.bind(this, this.playerB, 0, -1), this); this.game.input.keyboard.addKey(this.playerBControls.down).onDown.add(this.movePlayer.bind(this, this.playerB, 0, 1), this); |