force joystick command to be read as int, add a margin to detecting joy axis
This commit is contained in:
parent
2bbdc9a702
commit
6adf4ec697
|
@ -170,7 +170,7 @@ class Input(GameChild):
|
|||
return True
|
||||
joystick = self.joystick
|
||||
joy_map = self.joy_button_map
|
||||
if command in joy_map and joystick.get_button(joy_map[command]):
|
||||
if command in joy_map and joystick.get_button(int(joy_map[command])):
|
||||
return True
|
||||
if command == "up":
|
||||
return joystick.is_direction_pressed(Joystick.up)
|
||||
|
@ -241,18 +241,18 @@ class Joystick:
|
|||
js.init()
|
||||
self.js = js
|
||||
|
||||
def is_direction_pressed(self, direction):
|
||||
def is_direction_pressed(self, direction, margin=0.01):
|
||||
js = self.js
|
||||
if not js or direction > 4:
|
||||
return False
|
||||
if direction == 0:
|
||||
return js.get_axis(1) < 0
|
||||
return js.get_axis(1) < 0 - margin
|
||||
elif direction == 1:
|
||||
return js.get_axis(0) > 0
|
||||
return js.get_axis(0) > 0 + margin
|
||||
elif direction == 2:
|
||||
return js.get_axis(1) > 0
|
||||
return js.get_axis(1) > 0 + margin
|
||||
elif direction == 3:
|
||||
return js.get_axis(0) < 0
|
||||
return js.get_axis(0) < 0 - margin
|
||||
|
||||
def get_button(self, id):
|
||||
if self.js:
|
||||
|
|
Loading…
Reference in New Issue