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

When pressing the up and right keys


Gammerr
 Share

Recommended Posts

I'm following this game example:

https://phaser.io/examples/v2/games/starstruck

When the character jump to the right or left you can see that the legs are still animated

I want to change the animation if the user press up+left / up+right

so basically I need to show only one keyframe, I tried something like that:

( see the lines where I set the keyframe to be 1 and another line I set it to be 6 )

I will appreciate your help

function update() {

    //  Collide the player and the stars with the platforms
    var hitPlatform = game.physics.arcade.collide(player, platforms);
    game.physics.arcade.collide(stars, platforms);

    //  Checks to see if the player overlaps with any of the stars, if he does call the collectStar function
    game.physics.arcade.overlap(player, stars, collectStar, null, this);

    //  Reset the players velocity (movement)
    player.body.velocity.x = 0;

    if (cursors.left.isDown)
    {
        //  Move to the left
        player.body.velocity.x = -150;        

        player.animations.play('left');
    }
    else if (cursors.right.isDown)
    {
        //  Move to the right
        player.body.velocity.x = 150;

        player.animations.play('right');
    }
    else if (cursors.left.isDown && cursors.up.isDown) {
        player.frame = 1;
    }
    else if (cursors.right.isDown && cursors.up.isDown) {
        player.frame = 6;
    }
    else
    {
        //  Stand still
        player.animations.stop();
        player.frame = 4;
    }
    
    //  Allow the player to jump if they are touching the ground.
    if (cursors.up.isDown && player.body.touching.down && hitPlatform)
    {
        player.body.velocity.y = -300;        
        
    }

}

 

Link to comment
Share on other sites

Thank you for the reply!

The problem is when the characters lands to the ground and the user is still holding the left key it's not going back to the walking animation.

Can you help me with that too? I want to stop this single-frame when it's landing and animate the walking again, this is the walking animation that I have 

player.animations.add('left', [0, 1, 2, 3], 10, true);
player.animations.add('right', [5, 6, 7, 8], 10, true);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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