【问题标题】:Pygame, joystick detecting doesn't workPygame,操纵杆检测不起作用
【发布时间】:2012-07-08 10:15:48
【问题描述】:

我正在尝试使用 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 版本。) 感谢您提供的所有信息

【问题讨论】:

    标签: python pygame joystick


    【解决方案1】:

    我自己刚开始使用 Pygame。我首先使用pygame.joystick.init()。所以,我猜你会用p.joystick.init() 替换p.init()

    来自 Pygame 文档:(http://www.pygame.org/docs/ref/joystick.html)

    您可以调用 Joystick.get_name - 获取 Joystick 系统名称和 Joystick.get_id - 在不初始化的情况下获取操纵杆 ID 函数 操纵杆对象。

    我认为您还必须在其中写一行:

    stick.init()
    

    然后初始化棒并从中接收事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多