Path: blob/main/projects/HexGL/bkcore.coffee/controllers/GamepadController.coffee
4627 views
###1GamepadController (Orientation + buttons) for touch devices23@class bkcore.GamepadController4@author Mahesh Kulkarni <http://twitter.com/maheshkk>5###6class GamepadController78@isCompatible: ->9return ('getGamepads' of navigator) or ('webkitGetGamepads' of navigator)1011###12Creates a new GamepadController13###14constructor: (@buttonPressCallback) ->15@active = true16@leftStickArray = []17@rightStickArray = []1819###20@public21###22updateAvailable: ->23return false if not @active24gamepads = if navigator.getGamepads then navigator.getGamepads() else navigator.webkitGetGamepads()25return false if not gamepads?[0]26gp = gamepads[0]27return if not gp.buttons? or not gp.axes?28@lstickx = gp.axes[0]29accel = gp.buttons[0]30lt = gp.buttons[6]31rt = gp.buttons[7]32sel = gp.buttons[8]33# API fallback34@acceleration = accel.pressed ? accel35@ltrigger = lt.pressed ? lt36@rtrigger = rt.pressed ? rt37@select = sel.pressed ? sel38@buttonPressCallback this39true4041exports = exports ? @42exports.bkcore ||= {}43exports.bkcore.controllers ||= {}44exports.bkcore.controllers.GamepadController = GamepadController454647