pete796 Posted November 4, 2016 Share Posted November 4, 2016 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 More sharing options...
ionprodan Posted November 4, 2016 Share Posted November 4, 2016 In update method, in the first line, you have to set this.player.body.velocity.x = 0 Link to comment Share on other sites More sharing options...
carlosnufe Posted November 5, 2016 Share Posted November 5, 2016 Just @ionprodan. Look at your code, when a key is pressed you are setting the velocity but when you release don't anything. Nothing Magic happens, just it need to set again the velocity. Link to comment Share on other sites More sharing options...
pete796 Posted November 6, 2016 Author Share Posted November 6, 2016 thanks both Link to comment Share on other sites More sharing options...
Recommended Posts