Page 1 of 1
XBOX 360 Controller returning 0 hats on Mac OSX
Posted: Sun Mar 02, 2014 2:58 pm
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).
Re: XBOX 360 Controller returning 0 hats on Mac OSX
Posted: Sun Mar 02, 2014 3:26 pm
by bartbes
The stick will be made up of two axes, the left stick is typically the first two.
Re: XBOX 360 Controller returning 0 hats on Mac OSX
Posted: Mon Mar 03, 2014 5:30 am
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'.
Re: XBOX 360 Controller returning 0 hats on Mac OSX
Posted: Mon Mar 03, 2014 6:03 am
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
Re: XBOX 360 Controller returning 0 hats on Mac OSX
Posted: Wed Mar 05, 2014 7:55 pm
by lrd.ars
Slime, thank you. Thank you VERY MUCH
This kind of information should be on the Wiki, as an example.
Best regards.