如何在没有重力的情况下在移相器中进行上下运动

时间:2014-08-09 19:18:55

标签: javascript phaser-framework

新手:我正在关注此tutorial

我尝试添加上下运动也像:

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.up.isDown) {
   // Move to the top
   player.body.velocity.y = -50;
   player.animations.play(‘top’);
} else if (cursors.down.isDown) {
   // Move to the bottom
   player.body.velocity.y = 50;
   player.animations.play(‘bottom’);
}

角色正在移动,但是当我们按下箭头键时,玩家将一直到游戏屏幕的顶部,当按下向下箭头时,它将从顶部落下。我尝试设置player.body.gravity.y = 0;但它仍然会掉落或飞起来。轻快和正确的动作是完美的,我在向上或向下移动时需要类似的行为。

1 个答案:

答案 0 :(得分:2)

我想问题是你没有在velocity.y函数中清除update,如下所示:

function update() {
    player.body.velocity.x = 0;
    player.body.velocity.y = 0;
    // below is your code from the question
}