Sign in to follow this  

Character movement & multiple keys issue

Recommended Posts


I'm currently working on a tile base RPG game using Phaser.

function create():

controls = { 
  up: game.input.keyboard.addKey(Phaser.Keyboard.Z),
  shift: game.input.keyboard.addKey(Phaser.Keyboard.SHIFT) };

If I press Z, my character needs to move and if I press SHIFT + Z, my character has to rotate towards the Z direction. 

function update() :

if (controls.shift.isDown) {
	if (controls.up.isDown){
else {
    if (controls.up.isDown){


Right now, when try to rotate my character using SHIFT + Z, it triggers the rotation AND the movement. If I press Z alone, the character moves as expected.

I've tried checking if my SHIFT key was up but it didn't change anything.

How can I achieve that?


Thanks, in advance.

Share this post

Link to post
Share on other sites

Thank you! 

I didn't mention that I was working on a multiplayer game and seeing your fiddle made think that my mistake wasn't on the controls but rather on how I render other players on the map... Original issue solved then!

Quick question :

Characters have to move 46px by 46px. The only way I found was this kind of "hack" :

if (controls.up.isDown){
	if (controls.up._justUp) {
		moveCharacter(); // Moves the character by 46px in the direction

I updated your fiddle here.

Is there a better way to do this? Also, if you spam the key, the tween restarts so the character might have moved more than 46px (edit: and I don't want that).

Edited by Zhob
Quick edit

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.

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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.