Skip to content

Instantly share code, notes, and snippets.

@hidde-vb
Created September 1, 2016 07:08
Show Gist options
  • Save hidde-vb/d9e4be6f58d8edd325fe18762f5e18b5 to your computer and use it in GitHub Desktop.
Save hidde-vb/d9e4be6f58d8edd325fe18762f5e18b5 to your computer and use it in GitHub Desktop.
--[[
testing out the joystick API
]]--
--initialize the joysticks
local joysticks = love.joystick.getJoysticks()
function love.load()
for i, joystick in ipairs(joysticks) do
--give useful information
print("\n"..joystick:getName()..": "..joystick:getGUID())
print("------------------")
print("gamepad:\t" ..tostring(joystick:isGamepad()))
print("buttons:\t" ..tostring(joystick:getButtonCount()))
print("axesCount:\t"..tostring(joystick:getAxisCount())) -- supported: 4
print("hatcount:\t" ..tostring(joystick:getHatCount())) -- supported: 1
print("vibrate support:" ..tostring(joystick:isVibrationSupported())) --SDLbug, this will never work!
end
end
function love.draw()
if #love.joystick.getJoysticks() == #joysticks then
for i, joystick in ipairs(joysticks) do
--ANALOG STICK TEST--
--interesting: weird analog stick order: LX, LY, RY, RX
axX1,axY1,axY2,axX2=joystick:getAxes()
love.graphics.print(joystick:getName(),-190+i*200,10)
love.graphics.setColor(127,127,127)
--represents the joysticks
love.graphics.circle("fill",100+axX1*20+i*200-230,100+axY1*20,15,100)
love.graphics.circle("fill",100+axX2*20+i*200-150,100+axY2*20,15,100)
--BUTTONS TEST--
total = 0
for j=0 , 12, 1 do
test = joystick:isDown(j) and 1 or 0
total = total + test
end
love.graphics.print("buttons down: "..total,-190+i*200,30)
--HAT TEST--
if joystick:getHatCount() ~= 0 then
love.graphics.print("hat direction: "..joystick:getHat(1),-190+i*200,45)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment