Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Sprite gets stuck on other sprites


Mechanize
 Share

Recommended Posts

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

 Share

  • Recently Browsing   0 members

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