pterodactyl Posted October 12, 2018 Share Posted October 12, 2018 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 More sharing options...
prob Posted October 12, 2018 Share Posted October 12, 2018 this.input.keyboard.on('keydown_W', function (event) { // W key down }); or this.input.keyboard.on('keydown', function (event) { // Any key down, check event }); Link to comment Share on other sites More sharing options...
cornstipated Posted October 12, 2018 Share Posted October 12, 2018 this.cursors = this.input.keyboard.addKeys( {up:Phaser.Input.Keyboard.KeyCodes.W, down:Phaser.Input.Keyboard.KeyCodes.S, left:Phaser.Input.Keyboard.KeyCodes.A, right:Phaser.Input.Keyboard.KeyCodes.D}); Link to comment Share on other sites More sharing options...
pterodactyl Posted October 12, 2018 Author Share Posted October 12, 2018 7 minutes ago, cornstipated said: this.cursors = this.input.keyboard.addKeys({up:KeyCodes.W,down:KeyCodes.S,left:KeyCodes.A,right:KeyCodes.S}); Uncaught ReferenceError: KeyCodes is not defined Sorry I am new. Link to comment Share on other sites More sharing options...
pterodactyl Posted October 12, 2018 Author Share Posted October 12, 2018 Ok, it worked. Is there a better way to implement basic controls? I can't find tutorial about this for Phraser 3. Everywhere arrow keys. Link to comment Share on other sites More sharing options...
pterodactyl Posted October 12, 2018 Author Share Posted October 12, 2018 Also documentation doesn't have examples https://photonstorm.github.io/phaser3-docs/Phaser.Input.Keyboard.KeyboardPlugin.html Link to comment Share on other sites More sharing options...
robmuh Posted December 1, 2018 Share Posted December 1, 2018 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. Link to comment Share on other sites More sharing options...
samme Posted December 1, 2018 Share Posted December 1, 2018 It does have examples. https://photonstorm.github.io/phaser3-docs/Phaser.Input.Keyboard.KeyboardPlugin.html#addKeys__anchor Link to comment Share on other sites More sharing options...
Babsobar Posted December 4, 2018 Share Posted December 4, 2018 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 More sharing options...
Recommended Posts