xboxlove - Xbox360 Controller module

Showcase your libraries, tools and other projects that help your fellow love users.
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: xboxlove - Xbox360 Controller module

Post by jjmafiae »

nope this library doesn't work with 0.9.0 tried multiple times, it could also been made a bit more user friendly.
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 »

You should use the new Gamepad functionality instead, if you use 0.9.0: [wiki]Joystick:isGamepad[/wiki], [wiki]Joystick:getGamepadAxis[/wiki], [wiki]Joystick:isGamepadDown[/wiki], [wiki]love.gamepadpressed[/wiki], etc.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: xboxlove - Xbox360 Controller module

Post by Jasoco »

I couldn't figure out how to get it to work right. There's way too many buttons and sticks, I just wanted some easy to use library where I can say "if my left stick's X axis is < 0" or "if my A button is pressed" or "if the right trigger is > 0.5 pressed in" in the same way I say "if my F key is pressed" or "when my spacebar is down" or "when I release the right mouse button".

Maybe a little help with that stuff?
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: xboxlove - Xbox360 Controller module

Post by Kingdaro »

Jasoco wrote:I couldn't figure out how to get it to work right. There's way too many buttons and sticks, I just wanted some easy to use library where I can say "if my left stick's X axis is < 0" or "if my A button is pressed" or "if the right trigger is > 0.5 pressed in" in the same way I say "if my F key is pressed" or "when my spacebar is down" or "when I release the right mouse button".

Maybe a little help with that stuff?
There are actually libraries available (specifically TLBind and Common Organization of Controls Kit) that do just that, and I've written my own for a project I have using logic from both of these. (I'm not releasing it since it was made specifically for moonscript, and only has all of the features I actually need in said project.)

The logic of these kinds of modules is based around "actions", and mapping certain actions to different keyboard / gamepad controls. It works in a way similar to this:

Code: Select all

local controls = some.func(returning(a_control "bind").object)

function love.load()
   controls:bind("left", { key = "left" }, { joyAxis = 1, -1 }, { gamepadAxis = "leftx", -1 })
   controls:bind("right", { key = "right"}, { joyAxis = 1, 1}, { gamepadAxis = "leftx", 1 })
   controls:bind("jump", { key = " " }, { joyButton = 1 }, { gamepadButton = "a" })
end

function love.update(dt)
   controls:update(dt) -- usually doesn't require dt, since it's a bunch of state checks

   if controls.held.left then
      movePlayerLeft()
   end
   if controls.held.right then
      movePlayerRight()
   end
   if controls.pressed.jump then
      playerJump()
   end
end
(The syntax is horrible, I know :P ) You would use a command, specify an action, then bind a number of possible keyboard / gamepad input commands that will change the state of said action. In this example, when checking for the state of these actions in love.update, checking the action of the "held" property in the object checks if that action is currently being triggered by any of our specified commands (if the key is held down, if the button is held down, if the axis values we specify and on the controller match up). Checking "pressed" checks if that action was just starting to be triggered, and "released" (not shown here) checks if the action stopped being triggered.

If you understand moonscript (it's Lua but with a few added / changed constructs, e.g. colons are used for tables instead of equal signs like in JavaScript), you can see the code I used for this logic in particular here: https://github.com/Kingdaro/fb-moonscri ... olmap.moon

You can also look into the two libraries I mentioned earlier, since I borrowed logic from both of them.
mchaza
Prole
Posts: 1
Joined: Thu Jan 23, 2014 2:00 pm

Re: xboxlove - Xbox360 Controller module

Post by mchaza »

So I spent a few hours updating xboxlove to 0.9, I have tested it on windows 7 and mac osx and everything seems to be working (don't take my word on it).

You can download it here : https://github.com/hazagame/xboxlove

You need to pass the joystick object you get from love.joystick.getJoysticks(), if you pass nil or not a joystick object or you already passed that joystick it will return nil (change it for how you want it to work). Other than that it functions the same as original. Added xboxlove.connected to check if the controller is connected and getJoystick() returns the joystick object.

Why update when 0.9 has much better joystick controls, well I didn't like the fact you still needed the codes so this is still useful.
Post Reply

Who is online

Users browsing this forum: No registered users and 236 guests