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

时间:2016-03-02 21:18:41

标签: java android libgdx bpm

您好我正在开发Android上的LibGDX节奏游戏。在游戏中,你必须在" shape"在黑色方块。我需要将相机速度与音乐同步。我在60/61 FPS上计时相机速度,但是当帧速率下降音乐错位时。

My Game

每个"形状"具有速度变量,当"形状"存储在 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计算它,但我不知道该怎么做。使用MixMeister BPM Analyzer分析BPM。

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

1 个答案:

答案 0 :(得分:0)

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

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

如果您想独立移动对象:

currentVelocity = shapes.get(currentShapeIndex).getVelocity() * Gdx.graphics.getDeltaTime
相关问题