XBOX 360 Controller returning 0 hats on Mac OSX

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
lrd.ars
Prole
Posts: 2
Joined: Sun Mar 02, 2014 2:43 pm

XBOX 360 Controller returning 0 hats on Mac OSX

Post by lrd.ars »

Hello, guys.

I'm new on the forum and got in because i don't find a proper answer to my problem.

I'm using LOVE 0.9.0 on a Mac OSX (i've tryed on Windows 7 too) and i'm making a simple PONG game to my son. Until now, everything goes ok, menus, options menu and so on. But, when i started to do the joystick/gamepad support, boom! No joystick working.

Well, somethings worked out. The joystickadded() and josytickremoved() worked. I could get the name, id, and number of axis (LOVE returned 6). But when i try to get the number of hats (getHatCount()) to test the Left Stick and move my paddle, it returns me 0!

Despite the buttons and the rest, the controller became useless because i got no idea on how to check if the Left thumbstick is moving or not.

Somebody already got this kind of problem?

Thanks for any help.

(Sorry by my english. It's no my native language).
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: XBOX 360 Controller returning 0 hats on Mac OSX

Post by bartbes »

The stick will be made up of two axes, the left stick is typically the first two.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: XBOX 360 Controller returning 0 hats on Mac OSX

Post by Jasoco »

The OS X and Windows drivers for the 360 controller return controls differently.

OS X doesn't return hats, instead the D-Pad is 4 separate buttons. (Rather than L, R, U, D and Centered)

The sticks are returned as joysticks as are the L and R triggers.

We used to have a neat library under 0.8.0 that automatically did it for Mac and Windows but now 0.9.0 is completely different and no one seems to want to make an easy to use library that will make it easier to do between OS'.
User avatar
slime
Solid Snayke
Posts: 3163
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: XBOX 360 Controller returning 0 hats on Mac OSX

Post by slime »

Jasoco wrote:We used to have a neat library under 0.8.0 that automatically did it for Mac and Windows but now 0.9.0 is completely different and no one seems to want to make an easy to use library that will make it easier to do between OS'.
That's because you have a very simple and useful Gamepad API built into 0.9: [wiki]Joystick:isGamepad[/wiki], [wiki]Joystick:isGamepadDown[/wiki], [wiki]Joystick:getGamepadAxis[/wiki], [wiki]love.gamepadpressed[/wiki], etc.

Here's some example usage of the new LÖVE 0.9 functionality with the d-pad of a gamepad. It will work the same on Windows, Mac, and Linux for any popular gamepad without any modification at all.

Code: Select all

function love.load()
    joystick = love.joystick.getJoysticks()[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
Or the same thing using the left analog stick instead:

Code: Select all

function love.load()
    joystick = love.joystick.getJoysticks()[1]
    position = {x = 400, y = 300}
    speed = 300
end

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

    local xval = joystick:getGamepadAxis("leftx")
    if math.abs(xval) > 0.2 then -- a deadzone
        position.x = position.x + speed * xval * dt
    end

    local yval = joystick:getGamepadAxis("lefty")
    if math.abs(yval) > 0.2 then -- a deadzone
        position.y = position.y + speed * yval * dt
    end
end

function love.draw()
    love.graphics.circle("fill", position.x, position.y, 50)
end
lrd.ars
Prole
Posts: 2
Joined: Sun Mar 02, 2014 2:43 pm

Re: XBOX 360 Controller returning 0 hats on Mac OSX

Post by lrd.ars »

Slime, thank you. Thank you VERY MUCH :)

This kind of information should be on the Wiki, as an example.

Best regards.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests