字符将在JS中进行全尺寸跳转之前进行一小段跳转

问题描述 投票:0回答:1

我正在用JavaScript构建平台游戏。出于某种原因,当我的角色降落在平台上时,角色将开始交替执行一次很小的跳跃,然后再进行全尺寸的跳跃。我希望它每次都执行完整大小的跳转。为什么这不起作用?这是我的代码:

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";
    }
javascript css game-physics game-development
1个回答
0
投票
onSolidGround = true; jumping = false; falling = false;

发生第一跳时。

© www.soinside.com 2019 - 2024. All rights reserved.