LibGDX 节奏游戏 - 将相机速度与音乐同步

LibGDX rhythm game - synchronize camera speed with music

您好,我正在 android 上开发 LibGDX 类节奏游戏。在游戏中,当 "shape" 为黑色方块时,您必须点击特定按钮。我需要将相机速度与音乐同步。我在 60/61 FPS 上计时相机速度,但当帧速率下降时音乐会错位。

My Game

每个"shape"都有速度变量,当"shape"靠近黑色方块时,速度变量存储在currentVelocity变量中。

移动方法:

switch (currentDirection) {
        case UP:
            camera.position.y += currentVelocity;
            for (Actor uiComponent : stage.getActors()) {
                if (!(uiComponent instanceof ShapeObject)) {
                    uiComponent.setY(uiComponent.getY() + currentVelocity);
                }
            }
            break;
        case DOWN:
            camera.position.y -= currentVelocity;
            for (Actor uiComponent : stage.getActors()) {
                if (!(uiComponent instanceof ShapeObject)) {
                    uiComponent.setY(uiComponent.getY() - currentVelocity);
                }
            }
            break;
        case RIGHT:
            camera.position.x += currentVelocity;
            for (Actor uiComponent : stage.getActors()) {
                if (!(uiComponent instanceof ShapeObject)) {
                    uiComponent.setX(uiComponent.getX() + currentVelocity);
                }
            }
            break;
        case LEFT:
            camera.position.x -= currentVelocity;
            for (Actor uiComponent : stage.getActors()) {
                if (!(uiComponent instanceof ShapeObject)) {
                    uiComponent.setX(uiComponent.getX() - currentVelocity);
                }
            }
            break;
    }

我知道你必须用BPM来计算,但我不知道该怎么做。为了分析 BPM,我使用 MixMeister BPM Analyzer。

我迷路了:)感谢您的回复。

我找到了解决方案,问题出在其他地方:

currentVelocity = shapes.get(currentShapeIndex).getVelocity() + Gdx.graphics.getDeltaTime

如果要独立移动对象:

currentVelocity = shapes.get(currentShapeIndex).getVelocity() * Gdx.graphics.getDeltaTime