Sign in to follow this  
NUGA

Jump animation while the character is jumping

Recommended Posts

I'm trying to make a Mario styled platformer, and i'm running into a problem where the jumping animation is overridden by the walking animation when pressing the up and right(or left) arrow keys together. Here's what i have in regards of the update and playing the animations. The character sprite is loaded as a spritesheet if it makes a difference.

        if(this.cursors.right.isDown){
            this.mario.play('walk', true);
            this.mario.flipX = false;
            this.mario.body.setVelocityX(500);
        }
        else if(this.cursors.left.isDown){
            this.mario.play('walk', true);
            this.mario.flipX = true;
            this.mario.body.setVelocityX(-500);
        }
        else{
            if(this.mario.body.onFloor()){
                this.mario.play('stand');
            }else {
                this.mario.play('jumping');
            }
            this.mario.body.setVelocityX(0);
        }

        if(this.cursors.up.isDown && this.mario.body.onFloor()){
            //this.mario.play('jumping');
            this.mario.body.setVelocityY(-600);
        }

 

Share this post


Link to post
Share on other sites

If you change your walking animation to include a check to see if the sprite is on the floor then it should work

 

this.mario.body.onFloor() && this.mario.play('walk', true);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.