Created
June 28, 2020 23:09
-
-
Save tonetheman/436f5c88a004cf3a4d14e324397fb5e4 to your computer and use it in GitHub Desktop.
joystick love2d testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function love.load() | |
--backgroundImage = love.graphics.newImage("bg2.png") | |
--mainFont = love.graphics.newFont("m7.ttf", 20) | |
--love.graphics.setFont(mainFont) | |
local font = love.graphics.newFont(24) | |
love.graphics.setFont(font) | |
screenWidth = love.graphics.getWidth() | |
screenHeight = love.graphics.getHeight() | |
internalWidth = 1600 | |
internalHeight = 1200 | |
end | |
function love.draw() | |
screenWidth = love.graphics.getWidth() | |
screenHeight = love.graphics.getHeight() | |
local ratio = math.max(screenWidth/internalWidth, screenHeight/internalHeight) | |
love.graphics.scale(ratio,ratio) | |
-- love.graphics.draw(backgroundImage, 0, 0) | |
local joysticks = love.joystick.getJoysticks() | |
joysticks[1]:setVibration(0,0) | |
local joystickcount = love.joystick.getJoystickCount( ) | |
local axes = joysticks[1]:getAxisCount() | |
local buttoncount = joysticks[1]:getButtonCount() | |
local controlGUID = joysticks[1]:getGUID() | |
local controlID = joysticks[1]:getID() | |
local vibSupport = joysticks[1]:isVibrationSupported() | |
local isGamepad = joysticks[1]:isGamepad() | |
local isConnected = joysticks[1]:isConnected() | |
local countMyHats = joysticks[1]:getHatCount() | |
local hatPosWhere = joysticks[1]:getHat(1) | |
local howsMyVibBroL, howsMyVibBroR = joysticks[1]:getVibration() | |
local axisDir1, axisDir2, axisDir3, axisDir4 = joysticks[1]:getAxes( ) | |
local button1down = joysticks[1]:isDown(1) | |
local button2down = joysticks[1]:isDown(2) | |
local button3down = joysticks[1]:isDown(3) | |
local button4down = joysticks[1]:isDown(4) | |
local button5down = joysticks[1]:isDown(5) | |
local button6down = joysticks[1]:isDown(6) | |
local button7down = joysticks[1]:isDown(7) | |
local button8down = joysticks[1]:isDown(8) | |
local button9down = joysticks[1]:isDown(9) | |
local button10down = joysticks[1]:isDown(10) | |
local button11down = joysticks[1]:isDown(11) | |
local button12down = joysticks[1]:isDown(12) | |
love.graphics.setColor(0,255,0) | |
for i, joystick in ipairs(joysticks) do | |
love.graphics.print("JOYSTICK NAME:"..joystick:getName(), 370, i * 160) | |
end | |
love.graphics.print("JOYSTICK GUID:"..controlGUID, 370, 200 ) | |
love.graphics.print("JOYSTICK ID:"..controlID, 370, 240 ) | |
love.graphics.print("JOYSTICK COUNT:"..joystickcount, 370, 280 ) | |
love.graphics.print("JOYSTICK AXIS COUNT:"..axes, 370, 320 ) | |
love.graphics.print("JOYSTICK BUTTON COUNT:"..buttoncount, 370, 360 ) | |
love.graphics.print("VIBRATION SUPPORTED?:"..tostring(vibSupport), 370, 400 ) | |
love.graphics.print("IS A GAMEPAD?:"..tostring(isGamepad), 370, 440) | |
love.graphics.print("IS CONNECTED?:"..tostring(isConnected), 370, 480) | |
love.graphics.print("JOYSTICK HATS COUNT:"..countMyHats, 370, 520) | |
love.graphics.print("VIBRATION LEVEL LEFT:"..howsMyVibBroL.." VIBRATION LEVEL RIGHT:"..howsMyVibBroR, 370, 560) | |
love.graphics.print("AXIS 1 = "..axisDir1, 950,240) | |
love.graphics.print("AXIS 2 = "..axisDir2, 950,280) | |
love.graphics.print("AXIS 3 = "..axisDir3, 950,320) | |
love.graphics.print("AXIS 4 = "..axisDir4, 950,360) | |
love.graphics.print("B01 DOWN?:"..tostring(button1down), 370, 600) | |
love.graphics.print("B02 DOWN?:"..tostring(button2down), 570, 600) | |
love.graphics.print("B03 DOWN?:"..tostring(button3down), 770, 600) | |
love.graphics.print("B04 DOWN?:"..tostring(button4down), 970, 600) | |
love.graphics.print("B05 DOWN?:"..tostring(button5down), 370, 640) | |
love.graphics.print("B06 DOWN?:"..tostring(button6down), 570, 640) | |
love.graphics.print("B07 DOWN?:"..tostring(button7down), 770, 640) | |
love.graphics.print("B08 DOWN?:"..tostring(button8down), 970, 640) | |
love.graphics.print("B09 DOWN?:"..tostring(button9down), 370, 680) | |
love.graphics.print("B010 DOWN?:"..tostring(button10down), 570, 680) | |
love.graphics.print("B011 DOWN?:"..tostring(button11down), 770, 680) | |
love.graphics.print("B012 DOWN?:"..tostring(button12down), 970, 680) | |
love.graphics.print("HAT POSITION?:"..hatPosWhere, 570, 240) | |
love.graphics.setColor(255,255,255) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment