Mechanize Posted January 5, 2017 Share Posted January 5, 2017 I am following the 2D platformer tutorial on lessmilk.com. They walk you through building a small platformer. When the game starts, the player spawns in the air and falls to the ground. The player can move left, right, and jump using the arrow keys. However, jumping no longer works once the player lands on the ground. It seems like it's stuck. Jumping works when you hit the key while still in the air. I've implemented jumping by setting the sprite body's velocity.y to a negative number. Here's the update function implementation: update: function() { if (this.cursor.left.isDown) { this.player.body.velocity.x = -200; } else if (this.cursor.right.isDown) { this.player.body.velocity.x = 200; } else { this.player.body.velocity.x = 0; } if (this.cursor.up.isDown) { this.player.body.velocity.y = -250; } game.physics.arcade.collide(this.player, this.walls); game.physics.arcade.overlap(this.player, this.coins, this.takeCoin, null, this); game.physics.arcade.overlap(this.player, this.enemies, this.restart, null, this); } I'm running on Phaser v2.6.2. I tried running the code against other versions but no luck. I have an example of the bug running on my site. I also created a sample repo on GitHub that reproduces the issue. Instructions for running the project are in the README. Let me know let what I'm doing wrong. Thanks! Link to comment Share on other sites More sharing options...
drhayes Posted January 5, 2017 Share Posted January 5, 2017 Just a guess, but try swapping the order of those groups of lines: put the collides ahead of the key checks. My guess is that the wall collision is setting the player body's velocity and overwriting yours. Link to comment Share on other sites More sharing options...
Mechanize Posted January 6, 2017 Author Share Posted January 6, 2017 Nice, that fixed it. I threw the physic calls up to the top of update() and ?, the player can jump. Thanks for the help! Link to comment Share on other sites More sharing options...
Recommended Posts