Sign in to follow this  
pterodactyl

How to replace arrow keys with wasd movement?

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.