Is love.joystick consistent? And other miscellaneous ?'s.

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
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Is love.joystick consistent? And other miscellaneous ?'s.

Post by Jasoco »

I'm playing around with love.joystick and it's pretty nice and easy, but I'm a little confused at the best way to return if a certain button is down. It seems I need to refer to them as numbers. Sure I can use the love.gamepadpressed() and love.gamepadreleased() functions but I want to use them like I would normal keys. But it seems I need to check them by button number. Is this consistent? Will the numbers always be the same even across OS'? Is there an easy way to figure out which number corresponds to which button? Am I missing something? Right now the numbers starting with 0 correspond to the following buttons in order:

A, B, X, Y, LB, RB, LS, RS, Start, Back, Guide, Up, Down, Left, Right

Which seems pretty normal and not random. So can I use this order as a guide for each number where A will always be 0, B is always 1, Start is always 8, etc and so on?

Also, is it just me, or are the sticks on the 360 controller always so loose? My axes are always off by a small decimal amount and jiggle when I press any buttons. So I guess I'd need to account for a middle dead zone or something. (If the axis is in between -0.02 and 0.02 or something ignore it.

Also, is there any case in which Hats will actually be used? I get that they probably refer to D-Pads on some controllers, but for me the D-Pad returns as separate L/R/U/D buttons instead of one button with 5-9 possible states.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by Jasoco »

I never double post, so understand when I say really? No answers? No one knows how best to use Joystick? I'd love to get a dialog going about how to properly use it and how it will work on other OS'.
User avatar
JovialFeline
Prole
Posts: 28
Joined: Wed Jan 08, 2014 2:32 pm

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by JovialFeline »

I'd like to help but I haven't had a working gamepad in forever. I'd like to test stuff out and not just talk out of my bum. :P
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by micha »

In 0.8.0 the buttons hat do be accessed by numbers, and - at least in my case - these were not uniquely assigned to certain buttons. I compared an xbox-controler and a PS-controler-imitation. Already the first four buttons (A,B,X,Y) were assigned to the number 1-4 in different order.

In 0.9.0 it seems you can first use Joystick:isGamepad and then have a unique mapping via isGamepadDown, also see GamepadButton. Haven't tried that, though.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by bartbes »

As far as I know the mapping are the same for every device with the same GUID, and that's about all that's defined.
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by OmarShehata »

Jasoco wrote:Is there an easy way to figure out which number corresponds to which button? Am I missing something? Right now the numbers starting with 0 correspond to the following buttons in order:

A, B, X, Y, LB, RB, LS, RS, Start, Back, Guide, Up, Down, Left, Right

Which seems pretty normal and not random. So can I use this order as a guide for each number where A will always be 0, B is always 1, Start is always 8, etc and so on?
As bartbes mentioned, the same device should give you the same number->button values across all OS's. You could store a table with the number values corresponding to the button names so you don't have to remember the numbers. (So Buttons["A"] would be equal to 0 and so on)
Jasoco wrote: Also, is it just me, or are the sticks on the 360 controller always so loose? My axes are always off by a small decimal amount and jiggle when I press any buttons. So I guess I'd need to account for a middle dead zone or something. (If the axis is in between -0.02 and 0.02 or something ignore it.
That's actually what we do in Concerned Joe. Otherwise, you could probably blow on the stick and Joe would move. The minimum value at which Joe starts moving is around .2 and reaches his maximum speed at around .7, and values are normalized between that.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by Jasoco »

Thanks for all the info. I'm going to try and write my own controller library for myself. If I get something good enough I'll put up the code and we'll see if we can expand it. I only have a 360 controller so I can't test anything with a PlayStation or other controller though. So I don't know how they would work. Or a non-controller style joystick. (Do those even exist anymore?)

Since PS3 controllers have pretty much the same buttons as a 360 controller, does the Joystick library return the same values? Would the A, B, X, Y buttons all correspond to the same shape buttons in the same locations on the PS3? As well as the Guide and Back/Start? Or does this not really support the PS3? (Or does anyone even use PS3 controllers on PC/Macs? It seems that the 360 controller has become the defacto standard for using a controller on a computer.)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by bartbes »

The [wiki]GamepadButton[/wiki] values should map automatically for a couple of common gamepads. Otherwise, if your game is launched via steam, it will also use the mappings made in steam's big picture mode. And lastly, you could of course just have a menu thing to do the mapping in there.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Is love.joystick consistent? And other miscellaneous ?'s

Post by slime »

I think there might be some misinformation in this thread. Lets start from the basics:

The basic Joystick API ([wiki]Joystick:getAxis[/wiki], [wiki]Joystick:isDown[/wiki], [wiki]love.joystickpressed[/wiki], etc.) uses numeric button, hat, and axis indices that the joystick's driver gives. The numbers represent different physical buttons for different types of joysticks (e.g. an Xbox controller versus a PS3 controller) - so you cannot rely on button 1 being the button that people will normally press as a 'jump' action. It could be mapped to a 'back' button on the controller.

The same holds true for the same physical controller used on different operating systems, because the driver is different. The Xbox 360 controller's numeric buttons correspond to completely different physical buttons on Windows compared to on OS X.

Some drivers treat the d-pad of a game controller as a joystick Hat. Others don't. This is normally what a Hat is on a non-gamepad joystick: http://marsxplr.com/_upl/aviatorlogitechjse-orig.jpg

LOVE has additional APIs ([wiki]Joystick:isGamepad[/wiki], [wiki]Joystick:isGamepadDown[/wiki], [wiki]love.gamepadpressed[/wiki], etc.) built on top of the basic Joystick API to easily use gamepad buttons and axes consistently across different operating systems and across different but similar gamepads.

If [wiki]Joystick:isGamepad[/wiki] returns true for a particular Joystick object, then if the user presses the left bumper button on their gamepad, [wiki]love.gamepadpressed[/wiki](Joystick, "leftshoulder") will be called, and Joystick:isGamepadDown("leftshoulder") will return true - even though the numeric button being pressed (via [wiki]love.joystickpressed[/wiki] etc.) could be completely different for different users.

Although you usually won't need it, you can determine the numeric button (or hat or axis) value that corresponds to a Gamepad button or axis constant for a particular model of joystick on a particular driver+OS combination, with [wiki]love.joystick.getGamepadMapping[/wiki]. This uses a Joystick's GUID string (see [wiki]Joystick:getGUID[/wiki]), which will only be the same for the same model of Joystick on the same OS+driver.

If you want to change the Gamepad button/axis mappings or if you want to make a gamepad which isn't in love's database work as one for a particular model of joystick on a particular OS, you can use [wiki]love.joystick.setGamepadMapping[/wiki] (again, using the GUID string.)

If you use Steam's Big Picture mode and configure your gamepad's button mappings through there, and then you launch a love game through BIg Picture, the modified button mappings will be used by the Gamepad API. Steam also saves the mappings as a string in a file somewhere, and you can convert that for use with love.joystick.setGamepadMapping.
Post Reply

Who is online

Users browsing this forum: glass2d, MrFariator and 73 guests