Jump to content

How to replace arrow keys with wasd movement?


pterodactyl
 Share

Recommended Posts

Hello Im new to Phaser.

I'd like to replace arrow keys with wasd keys

This is my code:

	this.cursors = this.input.keyboard.createCursorKeys();
	 
	if (this.cursors.left.isDown) {
      this.ship.setAngularVelocity(-150);
    } else if (this.cursors.right.isDown) {
      this.ship.setAngularVelocity(150);
    } else {
      this.ship.setAngularVelocity(0);
    }
  
    if (this.cursors.up.isDown) {
      this.physics.velocityFromRotation(this.ship.rotation + 1.5, 100, this.ship.body.acceleration);
    } else {
      this.ship.setAcceleration(0);
    }
	

Link to comment
Share on other sites

  • 1 month later...
On 12/1/2018 at 5:54 PM, robmuh said:

Just a vote for `createWASDKeys()` to compliment `createCursorKeys()`. It is certainly easy enough to add them, but would make beginner tutorials just a bit more concise.

The problem with something like this is that it's only useful for QWERTY keyboards, so a broader approach, like setting keys for each needed input seems to me like a better solution, even though that's a little more work.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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