在Pygame中启动控制器会导致脚本停止
我尝试了一些与控制器一起使用的pygame的示例,它们似乎都遇到了同样的问题,我无法弄清楚我是否尚未正确安装Pygame或我是否在做其他错误。
import pygame
pygame.joystick.init()
for index in range(pygame.joystick.get_count()):
joystick = pygame.joystick.Joystick(index)
print(joystick) # <- does actually return a controller
while True:
pass # <- runs a few times and then stops
I've tried a few examples of pygame being used with controllers and they all seem to encounter the same issue, I can't figure out if I haven't installed pygame correctly or if im doing something else wrong.
import pygame
pygame.joystick.init()
for index in range(pygame.joystick.get_count()):
joystick = pygame.joystick.Joystick(index)
print(joystick) # <- does actually return a controller
while True:
pass # <- runs a few times and then stops
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参见 pygame窗口不响应。 >。您必须处理应用程序循环中的事件。参见 分别分别 () :
例如:
或
See PyGame window not responding after a few seconds. You have to handle the events in the application loop. See
pygame.event.get()
respectivelypygame.event.pump()
:e.g.:
or
遇到同样的问题。
我的操纵杆是Havit Twin USB控制器。
每次我启动Joystick.joystick(DeviceID)时,循环立即关闭。
我记得我在PC中安装了一个Twin USB驱动程序,该驱动器配置了控制器,轴速度,振动。
卸载Twinusb驱动程序/程序可以解决我的问题。
现在,我可以和我的操纵杆一起测试Pygame。
Encounter the same problem.
My joystick is Havit Twin USB Controller.
Everytime I init the joystick.Joystick(deviceID), the loop closes immediately.
I remembered i installed a Twin USB driver in my PC which configs the controller, axis speed, vibration.
Uninstalling the TwinUSB Driver/Program solves my problem.
Now I can test pygame along with my joystick.