Jump to content

[Phaser / Isometric Plugin] Sprites glitch around during animation, and creep upward


Kamon241
 Share

Recommended Posts

Hey Guys,

I've started 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, and 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 Initialization and Movement functions, but if anything else is needed please feel free to ask.

Cheers.

Player Init:

player = game.add.isoSprite(300, 300, 0, 'player', 0, characterGroup);
    player.anchor.set(0.5);
    player.scale.set(1.2);
    
    player.speed = 150;

    game.physics.isoArcade.enable(player);
    player.body.collideWorldBounds = true;
    
    game.camera.follow(player);
    
    player.animations.add('walk-down', Phaser.Animation.generateFrameNames('walk/down/', 1, 8, '', 1), 10, true);
     
    player.animations.add('walk-up', Phaser.Animation.generateFrameNames('walk/up/', 1, 8, '', 1), 10, true);
    
    player.animations.add('walk-right', Phaser.Animation.generateFrameNames('walk/right/', 1, 8, '', 1), 10, true);
    
    player.animations.add('walk-left', Phaser.Animation.generateFrameNames('walk/left/', 1, 8, '', 1), 10, true);
    
    
    player.animations.add('slash-up', Phaser.Animation.generateFrameNames('slash/up/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this);
    
    player.animations.add('slash-right', Phaser.Animation.generateFrameNames('slash/right/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this);
    
    player.animations.add('slash-left', Phaser.Animation.generateFrameNames('slash/left/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this);
    
    player.animations.add('slash-down', Phaser.Animation.generateFrameNames('slash/down/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this);
    

Player Movement:

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.x = 0;
            player.body.velocity.y = 0;
            player.animations.stop(true);
            player.frameName = 'walk/' + playerDir + '/0';
            _moving = false;
            break;
    }
}

 

2016-04-25 15_34_35-127.0.0.1_55168.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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