新手:我正在关注这个 教程
我尝试添加上下运动也喜欢:
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;
它仍然掉下来或飞起来。左右运动是完美的,向上或向下移动时我需要类似的行为。