Is there a way to receive inputs from xbox controller triggers, in pygame?

左心房为你撑大大i 提交于 2020-01-16 12:03:09

问题


A while back I started to control a game I am working on in pygame, with two xbox one controllers. I was doing so on a mac operating system and the controllers were being connected to my computer via the usb to micro usb cables, or specifically, not through Bluetooth. Pygame was able to read each input, with the two triggers being identified as their own axis, so when I returned x = joytsick1.get_numaxes(), print(x) I got 6. However with the recent update to Catalina, and the support for wireless connections, I can no longer receive inputs from the two triggers. Now when I return x = joystick1.get_numaxes(), print(x), I get 4. I see that the inputs are there when I print event in pygame.event.get(), however, in this method, there is no distinction between the two controllers I am using. How am I able to properly receive inputs from the triggers, or distinguish from the two controllers inputs?

import pygame

pygame.init()
pygame.joystick.init()

width = 600
height = 600

screen = pygame.display.set_mode((width, height))
running = True

joystick1 = pygame.joystick.Joystick(0)
joystick1.init()
joystick2 = pygame.joystick.Joystick(1)
joystick2.init()

while running:
    pygame.display.flip()

    for event in pygame.event.get():
        print(event)

        if event.type == pygame.QUIT:
            running = False
            pygame.quit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                running = False
                pygame.quit()


来源:https://stackoverflow.com/questions/59604049/is-there-a-way-to-receive-inputs-from-xbox-controller-triggers-in-pygame

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!