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
|
return True
|
||||||
joystick = self.joystick
|
joystick = self.joystick
|
||||||
joy_map = self.joy_button_map
|
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
|
return True
|
||||||
if command == "up":
|
if command == "up":
|
||||||
return joystick.is_direction_pressed(Joystick.up)
|
return joystick.is_direction_pressed(Joystick.up)
|
||||||
|
@ -241,18 +241,18 @@ class Joystick:
|
||||||
js.init()
|
js.init()
|
||||||
self.js = js
|
self.js = js
|
||||||
|
|
||||||
def is_direction_pressed(self, direction):
|
def is_direction_pressed(self, direction, margin=0.01):
|
||||||
js = self.js
|
js = self.js
|
||||||
if not js or direction > 4:
|
if not js or direction > 4:
|
||||||
return False
|
return False
|
||||||
if direction == 0:
|
if direction == 0:
|
||||||
return js.get_axis(1) < 0
|
return js.get_axis(1) < 0 - margin
|
||||||
elif direction == 1:
|
elif direction == 1:
|
||||||
return js.get_axis(0) > 0
|
return js.get_axis(0) > 0 + margin
|
||||||
elif direction == 2:
|
elif direction == 2:
|
||||||
return js.get_axis(1) > 0
|
return js.get_axis(1) > 0 + margin
|
||||||
elif direction == 3:
|
elif direction == 3:
|
||||||
return js.get_axis(0) < 0
|
return js.get_axis(0) < 0 - margin
|
||||||
|
|
||||||
def get_button(self, id):
|
def get_button(self, id):
|
||||||
if self.js:
|
if self.js:
|
||||||
|
|
Loading…
Reference in New Issue