Open Dukemz opened 4 months ago
What version of p5play are you using?
3.22.11, forgot to include in the post my bad
Thanks for reporting the issue but I don't know why it occurs.
Take a look at the _Contros._onConnect
function:
The indexes of controllers in p5play's contros
array differ from the HTML5 navigator.gamepads
array because I wanted reconnected controllers to be at the same index in the contros
array and new controllers should be added to the next available slot in the controllers array (if previous controllers were removed).
If contros[0]
already exists it shouldn't be possible to overwrite it. Can you try to set breakpoints in p5play.js to see why index is still 0 when the second controller is added?
The second time the _onConnect function is called it seems that this
is an array with just 1 object
which as a result causes index to be 0.
Looking at the MDZN documentation, it says that controllers that are disconnected will be replaced in the array returned by navigator.getGamepads()
with null, but will remain in the same index.
I'm still not entirely sure what's going on but I'll reply again when I've figured out some more details.
This seems to be the most reliable fix. The index should stay the same between disconnects/reconnects. Edit: see below comment
Bug still present in 3.23. Putting what Quinton said on the p5play discord server here for anyone not in the server.
@Dukemz I will take another look at this soon.
If two controllers/gamepads of the same type/ID are connected, p5play treats them as the same (in the attached screenshot, they are both considered to be contros[0]).
I'm not completely sure why this happens? Possibly because gamepad index isn't taken into account?