2 gamepad issue
Posted: Thu Nov 28, 2019 9:25 pm
I am having an issue while trying to use 2 gamepads for my local multiplayer game (2 players).
Only 1 controller works fine, everything works as it should, but when I connect my 2nd controller it just doesn't work. It is recognized and it is a gamepad but none of its inputs work.
Am I doing something wrong with the assignment of its index? below I show some simple code that I was using to test it.
Thank you!
Only 1 controller works fine, everything works as it should, but when I connect my 2nd controller it just doesn't work. It is recognized and it is a gamepad but none of its inputs work.
Am I doing something wrong with the assignment of its index? below I show some simple code that I was using to test it.
Thank you!
Code: Select all
function love.load()
joysticks = love.joystick.getJoysticks()
joystick1 = joysticks[1]
joystick2 = joysticks[2]
position = {x = 400, y = 300}
speed = 300
end
function love.update(dt)
if not joystick1 then return end
if joystick2:isGamepadDown("dpleft") then
position.x = position.x - speed * dt
elseif joystick2:isGamepadDown("dpright") then
position.x = position.x + speed * dt
end
if joystick1:isGamepadDown("dpup") then
position.y = position.y - speed * dt
elseif joystick1:isGamepadDown("dpdown") then
position.y = position.y + speed * dt
end
end
function love.draw()
directionx = joystick1:getGamepadAxis("leftx")
directiony = joystick1:getGamepadAxis("lefty")
love.graphics.circle("fill", position.x, position.y, 50)
love.graphics.print(tostring(directionx), 100,100)
love.graphics.print(tostring(directiony), 100,150)
end<e>