Joystick

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

Represents a physical joystick.

Constructors

love.joystick.getJoysticksGets a list of connected Joysticks.Added since 0.9.0

Functions

Joystick:getAxesGets the direction of each axis.Added since 0.9.0
Joystick:getAxisGets the direction of an axis.Added since 0.9.0
Joystick:getAxisCountGets the number of axes on the joystick.Added since 0.9.0
Joystick:getButtonCountGets the number of buttons on the joystick.Added since 0.9.0
Joystick:getGUIDGets a stable GUID unique to the type of the physical joystick.Added since 0.9.0
Joystick:getGamepadAxisGets the direction of a virtual gamepad axis.Added since 0.9.0
Joystick:getGamepadMappingGets the button, axis or hat that a virtual gamepad input is bound to.Added since 0.9.0
Joystick:getHatGets the direction of a hat.Added since 0.9.0
Joystick:getHatCountGets the number of hats on the joystick.Added since 0.9.0
Joystick:getIDGets the joystick's unique identifier.Added since 0.9.0
Joystick:getNameGets the name of the joystick.Added since 0.9.0
Joystick:getVibrationGets the current vibration motor strengths on a Joystick with rumble support.Added since 0.9.0
Joystick:isConnectedGets whether the Joystick is connected.Added since 0.9.0
Joystick:isDownChecks if a button on the Joystick is pressed.Added since 0.9.0
Joystick:isGamepadGets whether the Joystick is recognized as a gamepad.Added since 0.9.0
Joystick:isGamepadDownChecks if a virtual gamepad button on the Joystick is pressed.Added since 0.9.0
Joystick:isVibrationSupportedGets whether the Joystick supports vibration.Added since 0.9.0
Joystick:setVibrationSets the vibration motor speeds on a Joystick with rumble support.Added since 0.9.0
Object:typeGets the type of the object as a string.
Object:typeOfChecks whether an object is of a certain type.

Enums

GamepadAxisVirtual gamepad axes.Added since 0.9.0
GamepadButtonVirtual gamepad buttons.Added since 0.9.0
JoystickHatJoystick hat positions.
JoystickInputTypeTypes of Joystick inputs.Added since 0.9.0

Supertypes

Examples

Display the last button pressed of a controller on-screen

local lastbutton = "none"

function love.gamepadpressed(joystick, button)
    lastbutton = button
end

function love.draw()
    love.graphics.print("Last gamepad button pressed: "..lastbutton, 10, 10)
end

Move a circle with the d-pad of a controller

function love.load()
    local joysticks = love.joystick.getJoysticks()
    joystick = joysticks[1]

    position = {x = 400, y = 300}
    speed = 300
end

function love.update(dt)
    if not joystick then return end

    if joystick:isGamepadDown("dpleft") then
        position.x = position.x - speed * dt
    elseif joystick:isGamepadDown("dpright") then
        position.x = position.x + speed * dt
    end

    if joystick:isGamepadDown("dpup") then
        position.y = position.y - speed * dt
    elseif joystick:isGamepadDown("dpdown") then
        position.y = position.y + speed * dt
    end
end

function love.draw()
    love.graphics.circle("fill", position.x, position.y, 50)
end

See Also

Other Languages

Personal tools