【问题标题】:Python Pygame Joystick won't updatePython Pygame 操纵杆不会更新
【发布时间】:2016-09-02 04:58:59
【问题描述】:

我无法用它来更新操纵杆轴以打印当前值。尝试了 pygame 操纵杆测试,并且有效,所以这不是操纵杆问题。

谢谢

import pygame

pygame.init()
clock = pygame.time.Clock()

class JoyStick():

    def __init__(self):
        pass

    def update(self):
        joystickOne = pygame.joystick.Joystick(0)
        joystickOne.init()
        self.axisOne = joystickOne.get_axis(1)

OP = JoyStick()

while True:
    OP.update()
    print(OP.axisOne)
    clock.tick(10)

输出保持 0.0:

0.0
0.0
...

【问题讨论】:

    标签: python python-3.x while-loop pygame


    【解决方案1】:

    解决了!忘记事件处理程序。

    while done==False:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                done=True
    

    【讨论】:

    • 不用写while done == False,你可以写while not done
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多