OakTreePeter

Running and jumping right works but running and jumping left doesn't... Why?! (Possible Phaser bug)

Recommended Posts

Hey guys :)

I'm making a platformer and I've managed to get my character running and jumping at the same time... to one side only - the right!

I have NO ideia why running and jumping to the left is proving impossible but I'm hoping you can help me out.

runKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); // The running key, in the create method

// Fast forward to my update method (...)

// Horizontal movement

		player.body.velocity.x = 0;	// Resets our character's horizontal movement.

		if (cursors.left.isDown)	// If the 'left' key on our keyboard is pressed ...
		{
			player.scale.x = -1;	// ... we horizontally flip our character to face the left ...

			player.body.velocity.x = -200;	// ... we move him to the left ...

			player.animations.play('walk');	// ... play the 'walk' animation ...

			player_walk.play('', 0, 1, false, false);	// ... and finally play the 'player_walk' sound effect.

			if (runKey.isDown)					// If the 'run' key on our keyboard is being pressed while we are walking to the left...
			{
				player.body.velocity.x = -350;	// ... we allow our character run to the left.
			}
		}
		else if (cursors.right.isDown)	// If the 'right' key on our keyboard is pressed ...
		{
			player.scale.x = 1;			// ... we horizontally flip our character to face the right ...

			player.body.velocity.x = 200;	// ... we move our character to the right ...

			player.animations.play('walk');	// ... play the 'walk' animation ...

			player_walk.play('', 0, 1, false, false);	// ... and finally play the 'player_walk' sound effect.

			if (runKey.isDown)					// If the 'run' key on our keyboard is being pressed while we are walking to the right...
			{
				player.body.velocity.x = 350;	// ... we allow our character run to the right.
			}
		}
		else	// If no key on our keyboard is pressed ...
		{
			player.animations.play('idle');	// ... play the 'idle' animation ...
		}

		// Vertical movement

		if (cursors.up.isDown && (player.body.blocked.down || player.body.touching.down))	// If the 'up' key on our keyboard is pressed and our character is touching a surface ...
		{
			if (runKey.isDown && player.body.velocity.x < 0)
			{
				player.body.velocity.x = -350;

				player.body.velocity.y = -700;

				player_jump.play('', 0, 1, false, false);

				jumpCounter = 1;
			}
			else if (runKey.isDown && player.body.velocity.x > 0)
			{
				player.body.velocity.x = 350;

				player.body.velocity.y = -700;

				player_jump.play('', 0, 1, false, false);

				jumpCounter = 1;
			}

			player.body.velocity.y = -700;

			player_jump.play('', 0, 1, false, false);

			jumpCounter = 1;
		}
		else if (player.body.velocity.y < 0)
		{
			if (runKey.isDown && player.body.velocity.x < 0)
			{
				player.body.velocity.x = -350;

				player.animations.play('jump');

				player_walk.pause();
			}
			else if (runKey.isDown && player.body.velocity.x > 0)
			{
				player.body.velocity.x = 350;

				player.animations.play('jump');

				player_walk.pause();
			}

			player.animations.play('jump');

			player_walk.pause();
		}
		else if (player.body.velocity.y >= 0 && !(player.body.blocked.down || player.body.touching.down))
		{
			if (runKey.isDown && player.body.velocity.x < 0)
			{
				player.body.velocity.x = -350;

				player.animations.play('fall');

				player_walk.pause();
			}
			else if (runKey.isDown && player.body.velocity.x > 0)
			{
				player.body.velocity.x = 350;

				player.animations.play('fall');

				player_walk.pause();
			}

			player.animations.play('fall');

			player_walk.pause();
		}
		else
		{
			jumpCounter = 0;
		}

I really don't understand what's wrong :(

Thanks in advance!

Share this post


Link to post
Share on other sites

I was halfway trough your code, good that you spotted your problem. Here is a reproduction of the case, if it might be a bug, do you have an idea @samme , maybe @rich knows why this is happening? (shift key is commented below spacebar) :

UPDATE:  Problem was keyboard ghosting.
Edited by samid737
ghosting

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...

  • Recently Browsing   0 members

    No registered users viewing this page.