gpt4 book ai didi

javascript - JS中触摸后 Angular 色不会跳跃

转载 作者:行者123 更新时间:2023-12-02 22:30:28 25 4
gpt4 key购买 nike

我正在用 JS 为平台游戏编写碰撞检测。由于某种原因,当我的 Angular 色顶部接触地面时,它不会再次跳跃。这是我的代码:

if (isCollideY(platforms[i].getBoundingClientRect(), document.getElementById('spriteNotReal').getBoundingClientRect()) == true) {
if (falling == true && (jumping == false)) {
moveY = platforms[i].getBoundingClientRect().y + 3;
momentumY = 0;
onSolidGround = true;
}
}
if (event.code == 'KeyW' && (moveY <= 300)) { 
moveY += 1;
move (moveX, moveY);
momentumY = momentumY + 20;
onSolidGround = false;
falling = false;
jumping = true;
}
else if (onSolidGround == false) {
if (momentumY < 0) {
falling = true;
}
else if (momentumY > 0) {
jumping = true;
}
else {
jumping = false;
}
moveX += momentumX / 3 + 1;
document.getElementById("spriteNotReal").src = "jumpmain.gif";
}

最佳答案

我的问题有点愚蠢。检查输入代码后,我意识到跳转没有发生,因为它只会在我设置测试的“平台”上跳转,而不是在实际在平台上时跳转。这是改进后的代码:

if (event.code == 'KeyW' && (onSolidGround == true)) { 
moveY += 1;
move (moveX, moveY);
momentumY = momentumY + 20;
onSolidGround = false;
falling = false;
jumping = true;
}

关于javascript - JS中触摸后 Angular 色不会跳跃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58922597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com