Jendrik Posted June 3, 2015 Share Posted June 3, 2015 hi everybody.I´m trying to get my gamepad on work. I´ve tested it in the examples from phasers main page. So I´m really sure, that it works in the framework.But myconsole.log("Gamepad connected", this.game.input.gamepad.pad1.connected)always says: "false"(Keyboard input works fine in a different state) I can´t find the reason. Maybe anybody could help me? this code is in my create:this.game.input.gamepad.start();this.pad = this.game.input.gamepad.pad1;in update: if (this.pad.isDown(Phaser.Gamepad.XBOX360_DPAD_LEFT) || this.pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_X) < -0.1) { this.player.x--; } if (this.game.input.gamepad.isDown(Phaser.Gamepad.XBOX360_DPAD_RIGHT)) { this.player.x++; } if (this.pad.isDown(Phaser.Gamepad.XBOX360_DPAD_UP) || this.pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_Y) < -0.1) { this.player.y--; } if (this.pad.isDown(Phaser.Gamepad.XBOX360_DPAD_DOWN) || this.pad.axis(Phaser.Gamepad.XBOX360_STICK_LEFT_Y) > 0.1) { this.player.y++; } if (this.game.input.gamepad.isDown(Phaser.Gamepad.XBOX360_A)) { this.fireBean(); } if (this.pad.justReleased(Phaser.Gamepad.XBOX360_) { this.player.scale.x += 0.01; this.player.scale.y = sprite.scale.x; }after trying with "pad.isDown" I tried also "game.input.gamepad...". Thats the reason for my "code-mix". Thanks for your help by noobing me arround ;-) Quote Link to comment Share on other sites More sharing options...
Jendrik Posted June 5, 2015 Author Share Posted June 5, 2015 nobody an idea? Quote Link to comment Share on other sites More sharing options...
wayfinder Posted June 5, 2015 Share Posted June 5, 2015 Some gamepads only register as connected after you press a button. Quote Link to comment Share on other sites More sharing options...
Jendrik Posted June 8, 2015 Author Share Posted June 8, 2015 hi wayfinder,true, but same gamepad works in the examples from the Phaser page :-( Quote Link to comment Share on other sites More sharing options...
Jendrik Posted June 8, 2015 Author Share Posted June 8, 2015 I´ve found another way to use gamepad (everything in "update")if (navigator.getGamepads) { this.gamepads = navigator.getGamepads(); if(this.gamepads) { this.gamepad = this.gamepads[0]; }and this (example) for movement:if (this.gamepad) { if (this.gamepad.buttons[15].pressed) {//walk right this.player.body.velocity.x = +250; }...}could be better but it works. So what ;-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.