Mar-10-2023, 10:07 PM
I'm using pygame-menu and I want to use buttons on my controller to navigate it. I can't figure it out at all. There's no example available online. Also, I'm using a USB NES controller which does not have it's own mapping. I am not sure what the issue is. I've tried many things but nothing seems to help. The menu can be navigated using the keyboard arrow buttons, but not the controller. The documentation is a little confusing on this.
here is code where I tried to make the controller work. It looked a lot different when I started, but I kept changing things and I could never get it to work. So don't use this as an example for your own code, it's likely way off. I also added a function to be run with the player higs the down button on the menu, but I can't get this working either. Help!
here is code where I tried to make the controller work. It looked a lot different when I started, but I kept changing things and I could never get it to work. So don't use this as an example for your own code, it's likely way off. I also added a function to be run with the player higs the down button on the menu, but I can't get this working either. Help!
import pygame
import pygame_menu
from pygame_menu import themes
from pygame_menu.controls import Controller
pygame.init()
pygame.joystick.init()
pygame_menu.controls.KEY_BACK = Controller.back
pygame_menu.controls.KEY_APPLY = Controller.apply
pygame_menu.controls.KEY_MOVE_DOWN = Controller.joy_up
pygame_menu.controls.KEY_MOVE_UP = pygame_menu.controls.Controller.joy_up
def goDown():
print('go Down')
pygame_menu.controls.KEY_MOVE_DOWN = 1
while True:
surface = pygame.display.set_mode((600, 400))
def set_difficulty(value, difficulty):
print('breakpoint!')
# Do the job here !
pass
def start_the_game():
menu._down
print('breakpoint!')
# Do the job here !
pass
# pygame_menu.controls.Controller.joy_axis_x_left()
menu = pygame_menu.Menu('Welcome', 400, 300,
theme=pygame_menu.themes.THEME_BLUE)
menu.add.text_input('Name :', default='John Doe')
menu.add.selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add.button('Play', start_the_game)
menu.add.button('Go Down', goDown)
menu.add.button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
