Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Pixelbox

Create 2D games in JavaScript, made easier · By Cedric Stoquer

Gamepad documentation

A topic by IgorMoreno created Apr 16, 2020 Views: 225 Replies: 2
Viewing posts 1 to 3
(2 edits)

Hey there! I've been enjoying this tool so far, and plan to use it for some projects. :)

However I find that the way the gamepad module is explained on the GitHub page is a little misleading. It took me some time to figure out why my code was not working.

The functions getGamepads(), getGamepad(id) and getAnyGamepad() demonstrated are not exposed, being handled automatically by the module's update function. The example also uses gamepad as the variable name, however the module already has both gamepad and gamepads defined internally, which causes an error. These two objects are accessible and contain all the gamepad data, which would be even easier to explain in the documentation, save axes information when using gamepad, which is a merge of all connected pads. I quickly implemented axes support for this situation, though, since it was necessary for a game concept I'm developing: https://github.com/MorenoIgor/Pixelbox-Multiple-Gamepads-Axes

Overall I'm basically in love with Pixelbox! :D

I also struggled for a while to figure out how to use the gamepad module. I’ve been accessing gamepad state with “window.gamepad”. You do not need to import the module yourself.

Eg.

    /* User Input */
    if (window.gamepad.btn.right) character.x += 1;
    if (window.gamepad.btn.left) character.x -= 1;
    if (window.gamepad.btn.up) character.y -= 1;
    if (window.gamepad.btn.down) character.y += 1;

Thanks for the feedback. I have updated the documentation.