-
-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selector and Joystick #422
Comments
I think this is related to the calibration of the menu events. Check out the following lines: pygame-menu/pygame_menu/menu.py Lines 2569 to 2580 in da197b7
When you move the joystick to left or right it generates a lot of events that have to be "delayed" because if not one single movement of the axis would trigger 300 "move left" events. How many repeats and delay is configured in pygame-menu/pygame_menu/controls.py Lines 47 to 58 in da197b7
Maybe tuning these parameters will solve your issue. You can change these values by modifying the new_ctrl = ctrl.Controller()
new_ctrl.joy_delay = 200 # ms
menu.set_controller(new_ctrl) |
Today I updated the library to v4.3.0 which introduces this new |
Thanks it's working! Another tricky thing, I want to change the confirm key of a game selector and set a button (not keyboard). In the program, I have the event var so I can check if event.button == 8 and do something. But how can I found the equivalent of K_SPACE but for buttons. |
Sure, as explained in the documentation, you can create a custom controller object which now has all the instructions regarding how a widget responds to pygame-menu/pygame_menu/controls.py Lines 84 to 92 in a0c5976
As you can see, the controller receives the event and widget, thus, any kind of new event can be created. In your case, you must create a new controller (or retrieve the one from the widget, as each instance of the widget has its own object) and apply it to the widget: import pygame_menu.controls as ctrl
new_ctrl = ctrl.Controller()
def custom_widget_apply(event, widget) -> bool:
return event.key == pygame.K_SPACE or event.button == 8
new_ctrl.apply = custom_widget_apply
mywidget.set_controller(new_ctrl) Since Let me know if this solves your issue. |
|
Nice to ear, better to update everything this way ^^ Also before that, the function custom_widget_apply said one arg is missing, I tried to add self as first arg, I don't have the bellow error with this, but still first error. TypeError: Launcher.custom_widget_apply() takes 2 positional arguments but 3 were given |
I think you should use def custom_widget_apply(event, _) -> bool:
return event.key == pygame.K_SPACE
def custom_joy_apply(event, _) -> bool:
return event.button == 8
new_ctrl_sel = ctrl.Controller()
new_ctrl_sel.apply = custom_widget_apply
new_ctrl_sel.joy_select = custom_joy_apply
selector = menu.add.selector('select', ['a', 'b', 'c'])
selector.set_controller(new_ctrl_sel) I can confirm this works. See updated tests: pygame-menu/test/test_controls.py Lines 104 to 140 in 4f18a57
Regarding |
Weird, as old tests had the same format, see https://github.com/ppizarror/pygame-menu/tree/e75441d5ab425404406ef6c9bd473fad3973868f and https://github.com/ppizarror/pygame-menu/actions/runs/3630490971. The test was the same. Which python version are you using?. Today I changed that class using class MyCustomController(Controller):
... That approach should solve that issue. |
python was not up to date, everything is working fine. thanks a lot |
Hey, me again, sorry for the delay, we had taken a break on our project.
To come back to our problem, here is a video that will be more telling of the problem with our joystick. When we go left and then return to the center, it goes to the left and then to the right and not left and nothing. Do you have any idea?
https://streamable.com/l75kqh
The text was updated successfully, but these errors were encountered: