W3cubDocs

/LÖVE

Joystick:getGamepadAxis

Available since LÖVE 0.9.0
This function is not supported in earlier versions.

Gets the direction of a virtual gamepad axis. If the Joystick isn't recognized as a gamepad or isn't connected, this function will always return 0.

Function

Synopsis

direction = Joystick:getGamepadAxis( axis )

Arguments

GamepadAxis axis
The virtual axis to be checked.

Returns

number direction
Current value of the axis.

Examples

Move x and y values based on a gamepad thumbstick

function love.load()
    x = 0
    y = 0
    p1joystick = nil
end
 
function love.joystickadded(joystick)
    p1joystick = joystick
end
 
function love.update(dt)
    -- Check if joystick connected
    if p1joystick ~= nil then
        -- getGamepadAxis returns a value between -1 and 1.
        -- It returns 0 when it is at rest
 
        x = x + p1joystick:getGamepadAxis("leftx")
        y = y + p1joystick:getGamepadAxis("lefty")
    end
end

See Also

© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/Joystick:getGamepadAxis