Page 1 of 5

xboxlove - Xbox360 Controller module

Posted: Sun Jul 28, 2013 8:02 pm
by Walz.
Hello,

So, xboxlove facilitates the implementation of the xbox360 controller, on Windows and OSX.
You will be able to access, via friendly named constants, the value of each sticks/triggers/buttons of the xbox360 controller.

Left Stick :
xboxlove.Axes.LeftX (>= -1 and <= 1)
xboxlove.Axes.LeftY (>= -1 and <= 1)
xboxlove.Axes.LeftAngle (> -pi and <= pi)

Right Stick :
xboxlove.Axes.RightX (>= -1 and <= 1)
xboxlove.Axes.RightY (>= -1 and <= 1)
xboxlove.Axes.LeftAngle (> -pi and <= pi)

Triggers : (On windows, you can't use both triggers at the same time)
xboxlove.Axes.Triggers (>= -1 and <= 1)
or
xboxlove.Axes.LeftTrigger (>= 0 and <= 1)
xboxlove.Axes.RightTrigger (>= 0 and <= 1)

Dpad : (booleans except Direction)
xboxlove.Dpad.Direction
xboxlove.Dpad.Centered
xboxlove.Dpad.Up
xboxlove.Dpad.Down
xboxlove.Dpad.Right
xboxlove.Dpad.Left

Buttons : (booleans)
xboxlove.Buttons.A
xboxlove.Buttons.B
xboxlove.Buttons.X
xboxlove.Buttons.Y
xboxlove.Buttons.LT
xboxlove.Buttons.RT
xboxlove.Buttons.LB
xboxlove.Buttons.RB
xboxlove.Buttons.Back
xboxlove.Buttons.Start
xboxlove.Buttons.LeftStick
xboxlove.Buttons.RightStick


Methods :
xboxlove:update(dt) (Need to be in love.update)

xboxlove:setJoystick(joystick) (return a boolean)
xboxlove:getJoystick()
xboxlove:setDeadzone(axes,deadzone) (Set a deadzone for one or more axes. (axes(str) can contain "LX","LY","TRIG","TLEFT","TRIGHT","RX","RY" or just "ALL") )
xboxlove:isDown(button) (Use a friendly string ("A","Start",etc) to know if a button is down)

Constructor : xboxlove.create(joystick) (Return a xboxlove object and set the joystick (if omit joystick = 1 and if the joystick doesn't exit or is unplugged return nil) )


Edit :
(Jul 30) I added xboxlove:bind
(Aug 01) Work on OSX ! (with this driver)
(Aug 03) Now the value of the sticks stay between 0 and 1 even with a dead zone, so the angles value is more precise

Re: xboxlove - Use xbox controller in your games

Posted: Sun Jul 28, 2013 8:51 pm
by Eamonn
I don't own an Xbox, but if this does what I think it does(add Xbox controller support to LÖVE wirelessly), then this will be awesome!!!

Re: xboxlove - Use xbox controller in your games

Posted: Sun Jul 28, 2013 9:01 pm
by Walz.
I don't own a Xbox neither but I have usb controller.
Love already support xbox controller with love.joystick.
With my code, it's just easier.

Re: xboxlove - Use xbox controller in your games

Posted: Sun Jul 28, 2013 9:04 pm
by Eamonn
Well still, that's so awesome! :D It's a great module!

Re: xboxlove - Use xbox controller in your games

Posted: Sun Jul 28, 2013 9:08 pm
by Walz.
Thanks !

Re: xboxlove - Xbox360 Controller module

Posted: Mon Jul 29, 2013 2:59 am
by Ensayia
You can't have wireless support without Microsoft's own wireless dongle for PC. The wired USB controllers work well, however, and make very nice gamepads.

Re: xboxlove - Xbox360 Controller module

Posted: Mon Jul 29, 2013 4:06 am
by raidho36
From the title I thought you came up with a way to overcome default driver and actually utilize controller's full capabilities (separate axis for triggers, axis for battery status and a key for "home" button), but it turned out to be just a simple wrapper. I don't even need to look at the source.

Code: Select all

function xboxlove.isDown ( self, button )
    return love.joystick.isDown ( self.joystick, button ) and true or false
end

Re: xboxlove - Xbox360 Controller module

Posted: Mon Jul 29, 2013 4:39 am
by slime
raidho36 wrote:I don't even need to look at the source.

Code: Select all

function xboxlove.isDown ( self, button )
    return love.joystick.isDown ( self.joystick, button ) and true or false
end
No. Re-read the OP. :)

Keep in mind that drivers used in other operating systems map the Xbox controller inputs to different values, so this will likely only work in Windows.

Re: xboxlove - Xbox360 Controller module

Posted: Mon Jul 29, 2013 4:44 am
by raidho36
Curse you, slime! I actually dig into the source, and just you check this out:

Code: Select all

function xboxlove:isDown(button)
	for k,v in pairs(self.Buttons) do
		if k == button then return v end
	end
	return false
end
This is the worst case of all, but still half thing is quite sub-optimal in one way or another.

Re: xboxlove - Xbox360 Controller module

Posted: Mon Jul 29, 2013 5:37 am
by slime
raidho36 wrote:Curse you, slime! I actually dig into the source, and just you check this out:

Code: Select all

function xboxlove:isDown(button)
	for k,v in pairs(self.Buttons) do
		if k == button then return v end
	end
	return false
end
This is the worst case of all, but still half thing is quite sub-optimal in one way or another.
I was actually referring to the fact that the buttons are friendly strings ("A", "B", "X", "Y", etc.) instead of the normal unintuitive joystick button numbers.