任何人都可以告诉我如何让攻击动画恢复正常,即使按住按钮也是如此? (p5.js)

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

我正在做一个项目,你必须通过 p5.js 框架设计一个游戏。我有这个功能,旨在根据角色的方向和按下的按钮显示特定的踢或拳动画。我打算让它做的是切换到正常动画

("goku_copy")
,即使按键仍然被按住也是如此。但相反,它只是让动画停留在最后一帧,直到释放键为止。有谁知道我该如何解决这个问题?

function controls() {
    // check if x key is pressed
    if (keyWentDown("x")) {
        // set velocity to 0
        goku.velocityX = 0;
        // display left or right punch animation based on which direction the player is facing
        if (isFacingLeft) {
            goku.setAnimation("goku_punch_left");
        } else {
            goku.setAnimation("goku_punch_right");
        }
        punching = true; // player is punching
    } else if (keyWentUp("x")) {
        punching = false; // reset punching when x key is released
        goku.setAnimation("goku_copy");
    }

    // check if z key is pressed
    if (keyWentDown("z")) {
        // set velocity to 0
        goku.velocityX = 0;
        // display left or right kick animation based on which direction the player is facing
        if (isFacingLeft) {
            goku.setAnimation("goku_kick_left");
        } else {
            goku.setAnimation("goku_kick_right");
        }
        kicking = true; // player is kicking
    }  else if (keyWentUp("z")) {
        kicking = false; // reset kicking when z key is released
        goku.setAnimation("goku_copy");
    }

    if (!punching && !kicking && goku.velocityX !== 0) { // check if player is running
        goku.setAnimation(isFacingLeft ? "goku_run_left" : "goku_run_right");
    }
}
javascript p5.js
© www.soinside.com 2019 - 2024. All rights reserved.