[英]How to make up and down motion in phaser js without gravity
新手:我正在关注本教程
我尝试添加上下运动也像:
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;
它仍然掉下来或飞起来。 左右移动是完美的,上下移动时我需要类似的行为。
我想问题是您没有像这样在update
函数中清除velocity.y
:
function update() {
player.body.velocity.x = 0;
player.body.velocity.y = 0;
// below is your code from the question
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.