What am I doing wrong here?

this is my first day in phaser and in js, I’m trying to make my player move but I don’t even see the image, this is the code:

	var config = {
	type: Phaser.AUTO,
	width: 800,
	height: 600,
	scene: {
		preload: preload,
		create: create,
		update: update
	}
};

	var game = new Phaser.Game(config);

	function preload ()
	{
		this.load.image('player', 'player.png');
	}

	function create ()
	{player = this.add.image(52, 35, 'player');
	}

	function update ()
	{cursors = this.input.keyboard.createCursorKeys();
		if (cursors.left.isDown)
	{
		player.setVelocityX(-160);
	}
	else if (cursors.right.isDown)
	{
		player.setVelocityX(160);
	}
	else
	{
		player.setVelocityX(0);
	}
		}

THANKS

How are you running your game? Are you running it on a live server? What errors are in the console?

yeah, I’m running it on a server, this is the error: Uncaught TypeError: player.setVelocityX is not a function
at initialize.update (index.html:48)

You skipped some bits of the tutorial, you need to add physics: arcade to your config.

If you’re following this, it’s in part3 where they talk about adding physics.

2 Likes

thanks, that worked