From 76361a11953a68f807275fd456667c7dcf0cbc97 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 4 Jun 2016 16:27:30 +0200 Subject: Gamepad support \o/ --- controller.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'controller.lua') diff --git a/controller.lua b/controller.lua index d6dcb6d..c52b4a8 100644 --- a/controller.lua +++ b/controller.lua @@ -58,6 +58,26 @@ function Controller:testControl(control) end end +-- Gamepad +function Controller:gamepadpressed(joystick, button) + if self.parent ~= nil and self.joystick == joystick then + local control = self:testControl(button) + if control ~= nil then + self.parent:controllerPressed(control, self) + end + end +end + +function Controller:gamepadreleased(joystick, button) + if self.parent ~= nil and self.joystick == joystick then + local control = self:testControl(button) + if control ~= nil then + self.parent:controllerReleased(control, self) + end + end +end + +-- Keyboard function Controller:keypressed(key, scancode) if self.parent ~= nil and self.joystick == nil then local control = self:testControl(key) @@ -76,10 +96,11 @@ function Controller:keyreleased(key, scancode) end end +-- isDown function Controller:isDown(control) if self.joystick == nil then return love.keyboard.isDown(self[control]) else - return self.joystick:isGamepadDown(self[control], self) + return self.joystick:isGamepadDown(self[control]) end end \ No newline at end of file -- cgit v1.1