Jump to content

Player keeps moving if key release


pete796
 Share

Recommended Posts

Hi,

When the cursor keys are pressed the player moves in the correct direction, however, it keeps moving even if the key is released.

Can anyone help?

 

createPlayer: function() { 
    this.player = new ZPlat.Player(this, 100, 100);  
    this.dude = this.add.group();  
    this.dude.add(this.player);
  },


  update: function() {  
    if(this.cursors.left.isDown) {
      this.player.body.velocity.x = -this.RUNNING_SPEED;
      this.player.scale.setTo(1, 1);
      this.player.play('walking');
    }
  
    else if(this.cursors.right.isDown) {
      this.player.body.velocity.x =this.RUNNING_SPEED;
      this.player.scale.setTo(-1, 1);
      this.player.play('walking');
    }
  
    else {
      this.player.frame = 2;
      this.player.animations.stop();
    }

     if(this.cursors.up.isDown) {
      this.player.body.velocity.y = -this.JUMPING_SPEED;
    }
  
    if(this.player.body.y > this.game.world.height) {
        this.gameOver();
    }
  },
 

 

 

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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