Jump to content

Gamepad - Events between states and initialization


DjLeChuck
 Share

Recommended Posts

Hi,
 
I'm trying to implement gamepad in my game but some points are unclear...
 
I use states, so I have a Menu State and a Play State. I'm unable to dissociate button's events between my states.

When I use this code in my Menu State, the console.log will be execute in my Play State:

game.input.gamepad.start();this.pad = game.input.gamepad.pad1;var pauseButton = game.input.gamepad.pad1.getButton(Phaser.Gamepad.XBOX360_START);if (pauseButton) {    pauseButton.onDown.add(function() {        console.log("start");    }, this);}

For the moment the only way I find is to call pauseButton.onDown.dispose(); before my console.log but is it the solution ? I've tried some destroy() but I always have an error about Cannot read property 'time' of null...

 

Also, I saw two way for mapping keys. The way I'm using it as you can see above and with pad.addCallbacks(this, { onConnect: addButtons });.

I don't understand why in my code the addButtons method isn't call if my gamepad is already plug-in while on examples.phaser.io my gamepad is already connected and the code works without problems. I think of a scope error but I don't know wich.

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...