Issues with character moving. What's wrong with my setup?

Hi guys, I’ve just gotten started using Phaser, and I’m having a really elementary issue that seems to stem from a larger issue that I don’t have the experience to figure out.

So I’m making a Galaga/Space Invaders type of game with a partner, and I was working on making the player’s ship move. For some reason, when I use the arrow keys to move the character, it continues moving after I press the associated arrow key. If the player is going right, the left arrow key will always override it, but after the player starts going left, it can never go right again.

I’m pretty sure this is an issue with my setup because when I gave my partner the code, she said that it works fine on her computer. Also, when I tried the basic tutorial from https://phaser.io/tutorials/making-your-first-phaser-3-game/part10 I had the same issue with movement. I’ve also copy and pasted many different pieces of code from completed projects, and they all yield the same result.

At first I was using a basic python http server, so I switched to a free Chrome extension called “Web Server for Chrome,” because I thought that the server might be the issue, but nothing has changed. I’m not really sure what else could be wrong, so if anyone has any places to start finding issues, please let me know!

Here is the code in case it is the issue. This movePlayer() method is called in update()

movePlayer(){
	
	if(this.cursors.left.isDown == true){
		this.player.body.setVelocityX(-200);
		//this.player.body.velocity.x = -200; //tried but didn't work
	}
	else if(this.cursors.right.isDown == true){
		this.player.body.setVelocityX(200);
		//this.player.body.velocity.x = 200; //tried but didn't work
	}
	else {
		this.player.body.setVelocityX(0)
	}

}

I’ve noticed this too on my Chrome although not when I try any other phaser games or examples online. (I should try some phaser examples locally…)

It also isn’t a problem when I use Firefox. So it is a mystery that I have not taken too much time to investigate. For now, I’ve simply switched to Firefox so that I can continue working.

1 Like

Using Firefox made it finally work. Thanks!

You can try turning off any Chrome extensions.

1 Like

I agree that it sounds like an issue with an extension. Some browser extensions can move the focused element on a page. And by “focus” I mean like how you can press the Tab key to cycle focus through different elements on a web page. Your game has to have the user’s focus to capture key presses. It sounds like your game canvas has focus, you press right to start moving right but then something is grabbing the focus so your game doesn’t capture that the right key stopped being pressed. If no one else can recreate the issue definitely try disabling all of your extensions and see if that fixes it. Password managers and a lot of web development tools can mess with your focus.

EDIT: Ahh, I see using Firefox fixed it. That definitely seems to point at a Chrome extension causing the issue.

2 Likes

I think @Jackolantern and @samme are right about the extensions :sob:

For me, when I disable the Evernote extension everything works as expected

1 Like

ohhh, I have the Evernote extension too, this makes so much sense now

1 Like

If I recall right, there is actually a right that you give the extensions that allows them to mess with your focus. I can’t remember if it is specifically spelled out (like “Allow this extension to control the focus on the webpage”) or if it bundled with the more general one that I know I have seen tons of times (“Allow this extension access to web pages you are browsing”). If the former doesn’t exist, as I can’t remember if it does, it is the second one that allows it to alter focus. And unfortunately that is a big issue with HTML5 games.