Jump to content

Sprite Problem with Animation & (specifically) Upward Movement


Kamon241
 Share

Recommended Posts

I've recently started work on a new game, experimenting with the Rotates Isometric plugin and its mostly going great. I'm using the LPC base assets for my prototyping art because they are widely available and nicely animated (picture attached), but then the bugs started appearing.

Every time the character moves in a direction I play the walking animation for that direction. All directions are fine, other than the upwards movement. After the upwards animation finishes (when the player and let go of the key) the sprite continues to float slowly up (-y) at a rate of about 5px/sec, until the player puts in another movement control, at which point everything is fine and the sprite flies back to where it was before it started to float away. The game registers both the x + y velocities as 0 while floating, as they should be, and I've run out of options to try.

My other, more game breaking, problem is that when the player attacks the sprite plays the animation, but flies up (again -y) almost exactly 50px. Again the game logs the velocity of the sprite as 0 while this is happening, nevermind what direction the player attacked the sprite always flies up (-y).  I threw both of these problems into the same question because I thought there were many similarities between the two, and perhaps they are related.

Below I'll put in the Player Movement function, but if anything else is needed please feel free to ask. Not meaning to bed but I desperately need a hand with this, my boss loves what I've produced so far and is pressuring me to produce something concrete with it.

 

function movePlayer(direction){    
    switch(direction){
        case 'up':
            player.body.velocity.x = -player.speed;
            player.body.velocity.y = -player.speed;
            player.animations.play('walk-' + direction);
            playerDir = direction;
            _moving = true;
            break;
            
        case 'down':
            player.body.velocity.x = player.speed;
            player.body.velocity.y = player.speed;
            player.animations.play('walk-' + direction);
            playerDir = direction;
            _moving = true;
            break;
            
        case 'left':
            player.body.velocity.x = -player.speed;
            player.body.velocity.y = player.speed;
            player.animations.play('walk-' + direction);
            playerDir = direction;
            _moving = true;
            break;
            
        case 'right':
            player.body.velocity.x = player.speed;
            player.body.velocity.y = -player.speed;
            player.animations.play('walk-' + direction);
            playerDir = direction;
            _moving = true;
            break;
            
        default:
            player.body.velocity.y = 0;
            player.body.velocity.x = 0;
            player.animations.stop(true);
            player.frameName = 'walk/' + playerDir + '/0';
            _moving = false;
            break;
    }
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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