Correction: I said I was using love 11.4 by mistake. I'm using 11.3 (Ubuntu / Mint 20.2).
Thank you for the reply and the link. This is helpful. I did not come across that link in the wiki. Mostly hopping back and forth between various methods of love.joystick. And anything I find in google points me to methods that have been removed in love 11.
The problem joystick is returning false to isGamepad, and I could not find it "
by name" in the link you provided. The guid can be found as "Precision Controller".
I'll copy the code i have. I've been basically trying something, then deleting. What I will the object bound to 'JOY1' moves the way it should and 'JOY2' does nothing for all buttons and inputs; and it's the same code that i loop through for both.
Code: Select all
Registering "Mad Catz Wired Xbox 360 Controller"" as "JOY1"
Registering "PS3/USB Cordless Gamepad"" as "JOY2"
{
['JOY2'] = {
['gamePad'] = false,
['device'] = 'Joystick: 0x55afe35ded30',
['guid'] = '030000006d040000d2ca000011010000', <------ Precision Controller
['description'] = 'PS3/USB Cordless Gamepad'
},
['JOY1'] = {
['gamePad'] = true,
['device'] = 'Joystick: 0x55afe35f8450',
['guid'] = '03000000380700001647000031220000',
['description'] = 'Mad Catz Wired Xbox 360 Controller'
},
['KEY1'] = {
['description'] = 'Keyboard, Using Up, Down, Left, Right keys'
},
['KEY2'] = {
['description'] = 'Keyboard: Using W, A, S, D keys'
}
}
Code: Select all
require("helper") --TODO delete me
Input = {}
inputSources = {}
-- KEY1 and 2 will be the same keyboard, just using different keys
inputSources['KEY1'] = { description = "Keyboard, Using Up, Down, Left, Right keys" }
inputSources['KEY2'] = { description = "Keyboard: Using W, A, S, D keys" }
-- Detect Joysticks
local joys = love.joystick.getJoysticks()
for i, js in ipairs(joys) do
inputSources['JOY' .. tostring(i)] = { description = js:getName(), device = js, guid = js:getGUID(), gamePad = js:isGamepad() }
print('Registering "' .. js:getName() .. '"" as "JOY' .. i .. '"')
end
print_table(inputSources) -- TODO: delete me
--love.event.quit()
Unrelated but in case you're wondering, speedAdjustment is basically just dt with some other variables factored in.
Code: Select all
function Input:update(speedAdjustment)
Input:keyboardUpdate(speedAdjustment)
Input:joystickUpdate(speedAdjustment)
end
function inputEvent(inputSource, what, speedAdjustment)
if what == 'UP' then
if Settings.PlayerLeftInput == inputSource then Player1:moveUp(speedAdjustment)
elseif Settings.PlayerRightInput == inputSource then PlayerRight:moveUp(speedAdjustment) end
end
if what == 'DOWN' then
if Settings.PlayerLeftInput == inputSource then Player1:moveDown(speedAdjustment)
elseif Settings.PlayerRightInput == inputSource then PlayerRight:moveDown(speedAdjustment) end
end
if what == 'LEFT' then
if Settings.PlayerLeftInput == inputSource then Player1:moveLeft(speedAdjustment)
elseif Settings.PlayerRightInput == inputSource then PlayerRight:moveLeft(speedAdjustment) end
end
if what == 'RIGHT' then
if Settings.PlayerLeftInput == inputSource then Player1:moveRight(speedAdjustment)
elseif Settings.PlayerRightInput == inputSource then PlayerRight:moveRight(speedAdjustment) end
end
end
function Input:keyboardUpdate(speedAdjustment)
-- Inputs
-- TODO - implement key states to avoid flickering
if love.keyboard.isDown("q") then
love.event.quit(0)
elseif love.keyboard.isDown("f1") then
Settings.debug = not Settings.debug
end
-- KEY id to represent match an inputSource
local id
-- ------- InputSource KEY1 : UDLR ----------------------------
id = 'KEY1'
if love.keyboard.isDown("up") then
inputEvent(id, "UP", speedAdjustment)
end
if love.keyboard.isDown("down") then
inputEvent(id, "DOWN", speedAdjustment)
end
if love.keyboard.isDown("left") then
inputEvent(id, "LEFT", speedAdjustment)
end
if love.keyboard.isDown("right") then
inputEvent(id, "RIGHT", speedAdjustment)
end
-- ------- inputSource KEY2 : WASD ----------------------------
id = 'KEY2'
if love.keyboard.isDown("w") then
inputEvent(id, "UP", speedAdjustment)
end
if love.keyboard.isDown("s") then
inputEvent(id, "DOWN", speedAdjustment)
end
if love.keyboard.isDown("a") then
inputEvent(id, "LEFT", speedAdjustment)
end
if love.keyboard.isDown("d") then
inputEvent(id, "RIGHT", speedAdjustment)
end
end
function Input:joystickUpdate(speedAdjustment)
--local k -- KEY id for inputSources
-- ------- inputSource JOY1 : inputSources['JOY*''].device ----------------------------
--k = 'JOY1'
local id
-- inputtype, inputindex, hatdirection = inputSources['JOY1'].device:getGamepadMapping( 'leftx')
-- print('MAP: ', inputtype, inputindex, hatdirection)
-- guid = inputSources['JOY1'].device:getGUID()
-- success = inputSources['JOY1'].device.setGamepadMapping( guid, 'dpup', 'button', 5, nil)
-- print(success)
--print('LEFT_STICK_X: ' .. inputSources['JOY1'].device:getGamepadAxis('leftx'))
--print('LEFT_STICK_Y: ' .. inputSources['JOY1'].device:getGamepadAxis('lefty'))
for thisKey,_ in pairs(inputSources) do
id = tostring(thisKey)
if thisKey:sub(1,3) == 'JOY' then
-- For this game, we don't want fine grained control from the sticks. So we will treat them like a dpad
if inputSources[id].device:getGamepadAxis('lefty') < -0.2 or inputSources[id].device:isGamepadDown('dpup') then
inputEvent(id, "UP", speedAdjustment)
end
if inputSources[id].device:getGamepadAxis('lefty') > 0.2 or inputSources[id].device:isGamepadDown('dpdown') then
inputEvent(id, "DOWN", speedAdjustment)
end
if inputSources[id].device:getGamepadAxis('leftx') < -0.2 or inputSources[id].device:isGamepadDown('dpleft') then
inputEvent(id, "LEFT", speedAdjustment)
end
if inputSources[id].device:getGamepadAxis('leftx') > 0.2 or inputSources[id].device:isGamepadDown('dpright') then
inputEvent(id, "RIGHT", speedAdjustment)
end
end
end
end