xboxlove - Xbox360 Controller module

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Walz.
Prole
Posts: 13
Joined: Mon May 06, 2013 2:42 pm

xboxlove - Xbox360 Controller module

Post 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
Attachments
xboxlove.lua
0.21
(9.75 KiB) Downloaded 395 times
demo.love
(23.21 KiB) Downloaded 429 times
Last edited by Walz. on Sat Aug 03, 2013 10:48 am, edited 12 times in total.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: xboxlove - Use xbox controller in your games

Post 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!!!
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Walz.
Prole
Posts: 13
Joined: Mon May 06, 2013 2:42 pm

Re: xboxlove - Use xbox controller in your games

Post 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.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: xboxlove - Use xbox controller in your games

Post by Eamonn »

Well still, that's so awesome! :D It's a great module!
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
Walz.
Prole
Posts: 13
Joined: Mon May 06, 2013 2:42 pm

Re: xboxlove - Use xbox controller in your games

Post by Walz. »

Thanks !
User avatar
Ensayia
Party member
Posts: 399
Joined: Sat Jun 12, 2010 7:57 pm

Re: xboxlove - Xbox360 Controller module

Post 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: xboxlove - Xbox360 Controller module

Post 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
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: xboxlove - Xbox360 Controller module

Post 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: xboxlove - Xbox360 Controller module

Post 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.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: xboxlove - Xbox360 Controller module

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 58 guests