【发布时间】:2021-11-22 19:58:10
【问题描述】:
基本上,当球击中顶墙时。我想让它制作一些雷击动画,但动画只持续大约 1 秒。
if(ball.getY() + ball.getHeight() > topWall.getY()) {
game.getBatch().draw(animation.getKeyFrame(timepassed, false), ball.getX(), ball.getY() + ball.getHeight(), 0, 0, leftWall.getWidth(), leftWall.getHeight() * -1, 1, 1, 0f);
LightingStrikeRectArrayList.add(new Rectangle(ball.getX(), Apm.HEIGHT - ball.getY() + ball.getHeight() / 2, topWall.getWidth(), topWall.getHeight()));
for (Rectangle rect : LightingStrikeRectArrayList) {
if (rect.overlaps(playerHitbox)) {
this.game.setScreen(new GameScreen(this.game));
}
}
if(!(LightingStrikeRectArrayList.isEmpty() && animation.isAnimationFinished(timepassed))) {
LightingStrikeRectArrayList.remove(0);
}
ball.reverseDirectionY();
}
【问题讨论】:
-
只有当球仍在顶壁时才绘制异常,因为它在 if 块中。由于
ball.reverseDirectionY(),我会假设球向下移动并且不再绘制动画,因为跳过了 if 块。 -
是的,我需要球在碰撞时反转,因为球会在墙上反弹。
-
将闪电绘图代码移出if-block。
标签: libgdx