Skip to content
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

About the constant value of gamepad-related #577

Open
shiromofufactory opened this issue Oct 31, 2024 · 7 comments
Open

About the constant value of gamepad-related #577

shiromofufactory opened this issue Oct 31, 2024 · 7 comments

Comments

@shiromofufactory
Copy link

I have a question about the gamepad related inputs defined in 'pyxel/python/pyxel/init.pyi'.
What input does each of the following variables correspond to?

GAMEPAD1_AXIS_LEFTX: int
GAMEPAD1_AXIS_LEFTY: int
GAMEPAD1_AXIS_RIGHTX: int
GAMEPAD1_AXIS_RIGHTY: int
GAMEPAD1_AXIS_TRIGGERLEFT: int
GAMEPAD1_AXIS_TRIGGERRIGHT: int
GAMEPAD1_BUTTON_LEFTSTICK: int
GAMEPAD1_BUTTON_RIGHTSTICK: int

I am using a stock XBOX controller to check the response of the controller and each variable, and the input of the gamepad analog sticks (there are two, left and right) had no effect on any of the variables, including DPAD_xx.
Also, pressing the RB and LB buttons responded to GAMEPAD1_BUTTON_RIGHTSHOULDER and GAMEPAD1_BUTTON_LEFTSHOULDER, but the RT and LT buttons did not seem to affect any of the variables in any way, as did the analog sticks.

@shiromofufactory
Copy link
Author

The results were almost identical for the Nintendo Switch joycon. The 8 variables listed in the previous message did not change no matter what button was pressed, while GAMEPAD1_BUTTON_RIGHTSHOULDER and GAMEPAD1_BUTTON_LEFTSHOULDER responded to the R and L buttons.
The controller is connected to a Mac.

@shiromofufactory
Copy link
Author

Postscript.
I wrote that I tested on Mac, but the result was the same when I tested on Window 11.

@kitao
Copy link
Owner

kitao commented Nov 25, 2024

Because I don't have many gamepads and there are various kinds of gamepad, Pyxel just uses the SDL2's definitions and event parameters.

https://github.com/kitao/pyxel/blob/main/rust/pyxel-platform/src/gamepad.rs#L187-L206

@shiromofufactory
Copy link
Author

Thanks for the reply.

As a point of interest after a little research, SDL_CONTROLLER_AXIS_LEFTX is not a Boolean type, but a number from 0~8000.

https://wiki.libsdl.org/SDL2/SDL_GameControllerAxis

However, I have found that if I use pyxel.btn(pyxel.GAMEPAD1_AXIS_LEFTX)
in pyxel, the result is returned as a Boolean, so there seems to be a difference between the SDL2 output and the pyxel output with respect to AXIS.

Has it been confirmed that SDL_CONTROLLER_AXIS_LEFTX etc. works on some kind of gamepad?

@kitao
Copy link
Owner

kitao commented Nov 25, 2024

Now I see the situation.
Pyxel treated analog keys in a different way.
https://github.com/kitao/pyxel/blob/main/rust/pyxel-platform/src/gamepad.rs#L175-L185

So when you would like to obtain those values, you need to use pyxel.btnv. And I've checked it works.
I think the problem is that btn doesn't cause an error when it gets unsupported key definitions.

@shiromofufactory
Copy link
Author

Thank you very much!
I can confirm that I can get the values with pyxel.btnv
Maybe the existence of pyxel.btnv is not well known to users.

@kitao
Copy link
Owner

kitao commented Nov 25, 2024

Yes. I agree with you.
I should update the documents at least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants