我正在尝试创建一个之前已经做过的项目,但是这一次我将使用一台从学校免费得到的PlayStation 1遥控器。问题在于当我将摇杆向上或向下移动时,它显示相同的坐标(如果您不明白我的意思,请看下面的图片)。我也不确定需要在if语句中放入什么来检查摇杆是否向上或向下。我也很难想象如何检查摇杆是否没有方向。我已经尝试使用if语句,其中如果摇杆的数字大于某个数并且小于另一个数(第一个数字在摇杆的顶部半部分,另一个数字表示它在摇杆的底部半部分),它将向下移动。当前的if语句没有出现任何错误,但是不起作用。我尝试了一个if语句来检查它是否在中间,但我对此不太确定。
实际结果是,当操纵杆向下移动时,精灵不会移动。 操纵杆轴
joystick_count = pygame.joystick.get_count()
if joystick_count == 0:
# No joysticks!
print("Error, I didn't find any joysticks.")
else:
# Use joystick #0 and initialize it
joystick = pygame.joystick.Joystick(0)
joystick.init()
if pygame.joystick.Joystick(0).get_axis(0) >= -0.0 and pygame.joystick.Joystick(0).get_axis(0) <= 0.0:
player_one.speed_y = 5
elif pygame.joystick.Joystick(0).get_axis(0) > -0.1 and pygame.joystick.Joystick(0).get_axis(0) < -0.9:
player_one.speed_y = -5
elif pygame.joystick(0).get_axis(0) == 0.0:
player_one.speed_y = -5
#The first if statement checks if the joystick is up and the second one
#checks if the joystick is downwards
# the middle one checks if the if statement is in the middle (not too sure)
#player one and two speed is what gets added on each time
实际结果是,当操纵杆向下移动时,精灵不会移动。 操纵杆轴