가로 모드에서 내 앱을 실행할 때 libGDX의 훌륭한 scene2d UI 라이브러리에 문제가 있습니다. 내 프로그램은 안드로이드 시뮬레이터와 데스크탑 환경 모두에서 예상대로 작동하지만, iOS 시뮬레이터 나 실제 장치에서 실행할 때 주 메뉴는 전화기가 세로 방향으로있는 것처럼 그려지고 가로보기에 적합합니다. 처음에는 내가 아직 아파치를 배웠다 고 가정했지만, 앱은 안드로이드에서 예상대로 작동합니다. iOS 및 Android에서 가로 모드로 실행되도록 게임을 구성했습니다.libgdx - iOS landscape가 scene2d와 올바르게 작동하지 않습니다.
안드로이드 시뮬레이터에서 메뉴가 예상대로 작동합니다. 시뮬레이터는 가로 방향이며 메뉴가 제대로 표시됩니다.
iOS의 경우 메뉴가 중앙에서 벗어나고 클릭 할 수 없습니다.
모든 것이 세로 방향으로 잘 작동하기 때문에이 문제는 가로 모드와 관련이 있습니다. ScreenAdapter를 확장 한 MainMenuScreen에 대한 코드는 다음과 같습니다.
package bakpakin.techgame;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
/**
* Created by Calvin on 9/25/14.
*/
public class MainMenuScreen extends ScreenAdapter {
private TechGame game;
private Stage stage;
private Skin skin;
private Table table;
public MainMenuScreen(TechGame game) {
this.game = game;
}
@Override
public void show() {
this.stage = new Stage();
this.skin = new Skin();
skin.add("default", Assets.superScript48);
skin.add("title", Assets.superScript128);
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.font = skin.getFont("default");
textButtonStyle.pressedOffsetY = 4;
skin.add("default", textButtonStyle);
Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = skin.getFont("title");
labelStyle.fontColor = Color.CYAN;
skin.add("default", labelStyle);
// Create a table that fills the screen. Everything else will go inside this table.
table = new Table();
table.setFillParent(true);
stage.addActor(table);
final TextButton play = new TextButton("Play", skin);
final TextButton about = new TextButton("About", skin);
final TextButton quit = new TextButton("Quit", skin);
play.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Assets.button1Sound.play(1, 1, 0);
}
});
about.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Assets.button1Sound.play(1, 1, 0);
}
});
quit.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Assets.button1Sound.play(1, 1, 0);
Gdx.app.exit();
}
});
final Label title = new Label("My Game", skin);
VerticalGroup vg = new VerticalGroup();
vg.pad(60);
table.add(title);
table.row();
table.add(vg);
vg.addActor(play);
vg.addActor(about);
vg.addActor(quit);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
GL20 gl = Gdx.gl;
gl.glClearColor(0, 0, 0, 1);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
@Override
public void dispose() {
stage.dispose();
skin.dispose();
}
}
iOS 8.0 (550.1) –