Gamepad DPAD cant press up or left

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kbmonkey
Party member
Posts: 139
Joined: Tue Sep 01, 2015 12:19 pm
Location: Sydney
Contact:

Gamepad DPAD cant press up or left

Post by kbmonkey »

greetings

So I have gone through all other gamepad related posts on the forum and found that by calling loadGamepadMappings("gamecontrollerdb.txt") it detects my Super Famicom NES-like Controller correctly.

The problem: The DPAD does not work out the box, and I call setGamepadMapping() to foolishly attempt configuring the DPAD. The Down and Right directions seem to work, but Up and Left do not. I suspect because it reports AxisCount of 2, any mappings beyond that are simply ignored.

I am a fan of restrictions when developing games to inspire creativity, but making all my games with only Right & Down movement is a bit absurd. Any tips to point out my mistake is welcome, please!

Pertinent Details:
OS: Windows (10)
Löve version: 11.3
Gamepad purchased from: https://raspberry.piaustralia.com.au/co ... controller
gamepad.jpg
gamepad.jpg (4.53 KiB) Viewed 2744 times

Code: Select all

function love.load()
    -- https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt
    love.joystick.loadGamepadMappings("gamecontrollerdb.txt")
end

function love.update(dt)

end

function love.keypressed(key)
    love.event.quit()
end

function love.joystickadded(joystick)
    print("Name", joystick:getName())
    print("ID", joystick:getID())
    print("GUID", joystick:getGUID())
    print("ButtonCount", joystick:getButtonCount())
    print("Info", joystick:getDeviceInfo())
    print("AxisCount", joystick:getAxisCount())
    print("isGamepad", joystick:isGamepad())

    -- map right dpad - works
    print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpright", "axis", 1))

    -- map down dpad - works
    print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpdown", "axis", 2))

    -- no error, no input -- obviously limited to AxisCount. How to map rest of DPAD?
    print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpleft", "axis", 3))
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpleft", "axis", 4))
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpleft", "axis", 5))
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpleft", "axis", .. all through including 10))

    -- attempt using hat input with a gamepad clearly without a hat -- no error, no input
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "dpup", "hat", 1, "u"))

    -- map a, b, x, y - works without loadGamepadMappings(), redundant with loadGamepadMappings().
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "a", "button", 2))
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "b", "button", 3))
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "x", "button", 1))
    --print(love.joystick.setGamepadMapping(joystick:getGUID(), "y", "button", 4))
end

function love.gamepadpressed(joystick, button)
    print(joystick:getName(), button)
end

function love.joystickremoved(joystick)
    print("removed", joystick:getName())
end
Output:

Code: Select all

Name    USB gamepad
ID      1       1
GUID    030000001f08000001e4000000000000
ButtonCount     10
Info    2079    58369   0
AxisCount       2
isGamepad       true
true
true
USB gamepad             dpdown
USB gamepad             dpdown
USB gamepad             dpdown
USB gamepad             dpdown
USB gamepad             dpdown
USB gamepad             dpright
USB gamepad             dpright
USB gamepad             dpright
USB gamepad             dpright
Attachments
gamepadtest.gif
gamepadtest.gif (12.95 KiB) Viewed 2744 times
MrFariator
Party member
Posts: 559
Joined: Wed Oct 05, 2016 11:53 am

Re: Gamepad DPAD cant press up or left

Post by MrFariator »

I ran into issues with the USB MegaDrive controller that came with Sega's MegaDrive Mini from some years back. In order to make the dpad work, I mapped those directions into leftx and lefty, as opposed to dpleft, dpright, etc. So something like:

Code: Select all

-- if megadrive mini controller is detected
local axes = joystick:getAxisCount()
love.joystick.setGamepadMapping(guid, "leftx", "axis",  axes-1 )
love.joystick.setGamepadMapping(guid, "lefty", "axis",  axes   )
And then you'd use LÖVE's love.gamepadaxis callback to check for inputs.

Judging by what your Windows controller test shows, I imagine you similarly need to treat the dpad as axes.
User avatar
kbmonkey
Party member
Posts: 139
Joined: Tue Sep 01, 2015 12:19 pm
Location: Sydney
Contact:

Re: Gamepad DPAD cant press up or left

Post by kbmonkey »

Thanks! I will try this out.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 7 guests