新手:我正在关注这个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’);
}
Angular 色正在移动,但是当我们按下向上箭头键时,玩家将到达游戏屏幕的顶部,而当按下向下箭头时,它将从顶部掉落。我尝试设置player.body.gravity.y = 0;
它仍然会掉下来或飞起来。左右运动是完美的,向上或向下移动时我需要类似的行为。
最佳答案
我猜问题是您没有在 update
函数中清除 velocity.y
,如下所示:
function update() {
player.body.velocity.x = 0;
player.body.velocity.y = 0;
// below is your code from the question
}
关于javascript - 如何在无重力的情况下在phaser js中进行上下运动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25222143/