From bf5f285ee846c570ddc0145019f19209308b3d68 Mon Sep 17 00:00:00 2001 From: Pumuckl007 Date: Mon, 18 Aug 2014 07:12:48 -0700 Subject: [PATCH] added gamepad support --- platformer.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/platformer.js b/platformer.js index 9ee01d4..c07cfe2 100644 --- a/platformer.js +++ b/platformer.js @@ -369,6 +369,20 @@ last = now; counter++; fpsmeter.tick(); + var gamepad = navigator.getGamepads()[0]; + if(gamepad){ + player.jump = gamepad.buttons[0].value; + if(gamepad.axes[0]<0.3){ + player.left = true; + } else{ + player.left = false; + } + if(gamepad.axes[0]>-0.3){ + player.right = true; + } else{ + player.right = false; + } + } requestAnimationFrame(frame, canvas); }