diff --git a/bkcore.coffee/controllers/GamepadController.coffee b/bkcore.coffee/controllers/GamepadController.coffee index 253ecd6..38c0908 100644 --- a/bkcore.coffee/controllers/GamepadController.coffee +++ b/bkcore.coffee/controllers/GamepadController.coffee @@ -26,11 +26,16 @@ class GamepadController return false if not gamepads?[0] gp = gamepads[0] return if not gp.buttons? or not gp.axes? - @acceleration = gp.buttons[0] @lstickx = gp.axes[0] - @ltrigger = gp.buttons[6] - @rtrigger = gp.buttons[7] - @select = gp.buttons[8] + accel = gp.buttons[0] + lt = gp.buttons[6] + rt = gp.buttons[7] + sel = gp.buttons[8] + # API fallback + @acceleration = accel.pressed ? accel + @ltrigger = lt.pressed ? lt + @rtrigger = rt.pressed ? rt + @select = sel.pressed ? sel @buttonPressCallback this true diff --git a/bkcore.coffee/controllers/GamepadController.js b/bkcore.coffee/controllers/GamepadController.js index c1d778b..5e77631 100644 --- a/bkcore.coffee/controllers/GamepadController.js +++ b/bkcore.coffee/controllers/GamepadController.js @@ -33,7 +33,7 @@ GamepadController.prototype.updateAvailable = function() { - var gamepads, gp; + var accel, gamepads, gp, lt, rt, sel, _ref, _ref1, _ref2, _ref3; if (!this.active) { return false; } @@ -45,11 +45,15 @@ if ((gp.buttons == null) || (gp.axes == null)) { return; } - this.acceleration = gp.buttons[0]; this.lstickx = gp.axes[0]; - this.ltrigger = gp.buttons[6]; - this.rtrigger = gp.buttons[7]; - this.select = gp.buttons[8]; + accel = gp.buttons[0]; + lt = gp.buttons[6]; + rt = gp.buttons[7]; + sel = gp.buttons[8]; + this.acceleration = (_ref = accel.pressed) != null ? _ref : accel; + this.ltrigger = (_ref1 = lt.pressed) != null ? _ref1 : lt; + this.rtrigger = (_ref2 = rt.pressed) != null ? _ref2 : rt; + this.select = (_ref3 = sel.pressed) != null ? _ref3 : sel; this.buttonPressCallback(this); return true; }; diff --git a/bkcore/hexgl/ShipControls.js b/bkcore/hexgl/ShipControls.js index d03acd4..81c31a6 100644 --- a/bkcore/hexgl/ShipControls.js +++ b/bkcore/hexgl/ShipControls.js @@ -386,17 +386,17 @@ bkcore.hexgl.ShipControls.prototype.update = function(dt) angularAmount -= this.touchController.stickVector.x/100 * this.angularSpeed * dt; rollAmount += this.touchController.stickVector.x/100 * this.rollAngle; } - if(this.orientationController != null) + else if(this.orientationController != null) { angularAmount += this.orientationController.beta/45 * this.angularSpeed * dt; rollAmount -= this.orientationController.beta/45 * this.rollAngle; } - if(this.gamepadController != null && this.gamepadController.updateAvailable()) + else if(this.gamepadController != null && this.gamepadController.updateAvailable()) { - angularAmount -= this.gamepadController.lstickx * 0.2 * this.angularSpeed * dt; + angularAmount -= this.gamepadController.lstickx * this.angularSpeed * dt; rollAmount += this.gamepadController.lstickx * this.rollAngle; } - if(this.leapBridge != null && this.leapBridge.hasHands) + else if(this.leapBridge != null && this.leapBridge.hasHands) { angularAmount += this.leapBridge.palmNormal[0] * 2 * this.angularSpeed * dt; this.speed += Math.max(0.0, (0.5 + this.leapBridge.palmNormal[2])) * 3 * this.thrust * dt;