Browse Source

Gamepad input

Josh Engebretson 11 years ago
parent
commit
ac95d178c4
1 changed files with 10 additions and 0 deletions
  1. 10 0
      PhysicsPlatformer/Resources/Components/Avatar.js

+ 10 - 0
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -108,6 +108,16 @@ function handleInput(timeStep) {
     var right = input.getKeyDown(Atomic.KEY_D);
     var jump = input.getKeyDown(Atomic.KEY_SPACE);
 
+    if (input.getNumJoysticks()) {
+        var state = GetGamepadState(0);
+        if (state.axis0 < -0.5)
+            left = true;
+        if (state.axis0 > 0.5)
+            right = true;
+
+        if (state.button0)
+            jump = true;
+    }
 
     if (left && vel[0] > -MAX_VELOCITY) {
         body.applyLinearImpulse([-2, 0], pos, true);