Почему камера в сцене не обязательно должна быть в центре libgdx - PullRequest
0 голосов
/ 15 января 2019

Как сценическая камера может видеть полный вид сцены, если (0,0) камеры по умолчанию находится на (0,0) сцены. если метод обновления для окна просмотра не вызывается, и не вызывается метод установки положения камеры.

1 Ответ

0 голосов
/ 15 января 2019

Если вы посмотрите на конструктор сцены:

public Stage (Viewport viewport, Batch batch) {
    if (viewport == null) throw new IllegalArgumentException("viewport cannot be null.");
    if (batch == null) throw new IllegalArgumentException("batch cannot be null.");
    this.viewport = viewport;
    this.batch = batch;

    root = new Group();
    root.setStage(this);

    viewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
}

В последней строке мы видим viewport.update () с параметрами width, height и true. Давайте посмотрим на этот метод viewport.update ():

public void update (int screenWidth, int screenHeight, boolean centerCamera) {
    apply(centerCamera);
}

Теперь давайте посмотрим на метод apply (). Мы знаем, что centerCamera это правда:

public void apply (boolean centerCamera) {
    HdpiUtils.glViewport(screenX, screenY, screenWidth, screenHeight);
    camera.viewportWidth = worldWidth;
    camera.viewportHeight = worldHeight;
    if (centerCamera) camera.position.set(worldWidth / 2, worldHeight / 2, 0);
    camera.update();
}

И здесь мы находим ответ: if (centerCamera) camera.position.set(worldWidth / 2, worldHeight / 2, 0);

Сцена сама по себе центрировала положение камеры.

...