我正在尝试使用 Pygame 检测 USB 操纵杆。 每次运行此代码时,程序都会崩溃并出现错误: 第 10 行中的“操纵杆未初始化”。
import pygame as p
p.init()
stick = p.joystick.Joystick(0)
#get init returns always False
print("initialized:",bool(stick.get_init()))
#getting the name works as it should
print(stick.get_name())
#says always "pygame.error: Joystick not initialized"
print("axis_0",stick.get_axis(0))
p.quit()
我做错了什么还是这是一个错误? (我在 Python 3.2 和 Windows 7 上使用最新的 pygame 版本。) 感谢您提供的每条信息
最佳答案
我自己刚刚开始使用 Pygame。我首先使用了 pygame.joystick.init() 。所以,我猜你会用 p.joystick.init()
替换 p.init()
。
来自 Pygame 文档:(http://www.pygame.org/docs/ref/joystick.html)
You can call the Joystick.get_name - get the Joystick system name and Joystick.get_id - get the Joystick ID functions without initializing the Joystick object.
我认为你还必须在其中添加一行内容:
stick.init()
然后初始化摇杆并从中接收事件。
关于python - Pygame,操纵杆检测不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11382335/