Jump to content

Shoot while running


przemoo83
 Share

Recommended Posts

Hi

I'm developing a simple game based on one of the tutorials. I came accross a problem. If the player is runnin (arrow pressed) and I press fire he always stops. I want him to keep running while shooting Is there any easy way to fix this? My code for controlling ther player

update: function() {	this.game.physics.arcade.collide(ground, player);	player.body.velocity.x = 0;	if (grygiel.game.input.activePointer.isDown)        {            //fire            fireBullet();	player.animations.play('throw');        }	else if (cursors.left.isDown)    {        //  Move to the left        player.body.velocity.x = -450;        player.animations.play('left');    }    else if (cursors.right.isDown)    {        //  Move to the right        player.body.velocity.x = 450;        player.animations.play('right');    }    else    {        //  Stand still        player.animations.stop();        player.frame = 8;    }        //  Allow the player to jump if they are touching the ground.    if (cursors.up.isDown && player.body.touching.down)    {        player.body.velocity.y = -350;		player.frame = 9;    }		//follow the player		this.game.camera.follow(player);  },};
Link to comment
Share on other sites

You're nearly there, you've got an extra else

update: function() {	this.game.physics.arcade.collide(ground, player);	player.body.velocity.x = 0;	if (grygiel.game.input.activePointer.isDown)        {            //fire            fireBullet();	player.animations.play('throw');        }	// removed else here!! if (cursors.left.isDown)    {        //  Move to the left        player.body.velocity.x = -450;        player.animations.play('left');    }    else if (cursors.right.isDown)    {        //  Move to the right        player.body.velocity.x = 450;        player.animations.play('right');    }    else    {        //  Stand still        player.animations.stop();        player.frame = 8;    }        //  Allow the player to jump if they are touching the ground.    if (cursors.up.isDown && player.body.touching.down)    {        player.body.velocity.y = -350;		player.frame = 9;    }		//follow the player		this.game.camera.follow(player);  },};
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...