我正在从事这个基于 p5.js 框架的项目,我们必须在其中设计游戏。我有一个单独的出拳和踢腿动画,出拳效果很好。问题出在踢动动画上,因为它只显示了它的第一帧。有谁知道问题出在哪里?谢谢!
var isFacingLeft = false; // set initial value to false
var punching = false; // set initial value to false
var kicking = false;
function controls() {
// check if x key is pressed
if (keyDown("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
}
// check if z key is pressed
else if (keyDown("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 (goku.velocityX !== 0) { // check if player is running
goku.setAnimation(isFacingLeft ? "goku_run_left" : "goku_run_right");
} else {
punching = false; // player is not punching
kicking = false; // player is not kicking
goku.setAnimation("goku_copy");
}
// reset animation to idle if punch or kick animation is finished
if (goku.getAnimationLabel() === "goku_punch_left" || goku.getAnimationLabel() === "goku_punch_right" || goku.getAnimationLabel() === "goku_kick_left" || goku.getAnimationLabel() === "goku_kick_right") {
if (goku.animation.getFrame() === goku.getAnimationLabel().length - 1) {
goku.setAnimation("goku_copy");
}
}
}
它的目的是无论玩家是在奔跑,面向左还是向右等,都显示踢球动画