Jump to content

Problems init Gamepad


Jendrik
 Share

Recommended Posts

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 my

console.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 ;-)

Link to comment
Share on other sites

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 ;-)

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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