libGDX 中的对话框显示不正确

Dialog is displayed incorrectly in libGDX

我正在尝试制作一个对话框并执行了以下代码,但它无法在屏幕上正确显示。

batch = new SpriteBatch();
camera = new OrthographicCamera();
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Viewport view = new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
view.setCamera(camera);
stage=new Stage(view,batch);
Skin skin=new Skin();
FileHandle fileHandle = Gdx.files.internal("uiskin.json");
FileHandle atlasFile = fileHandle.sibling("uiskin.atlas");
skin.addRegions(new TextureAtlas(atlasFile));
skin.load(Gdx.files.internal("uiskin.json"));
card=new Card("Hello",skin );
Gdx.input.setInputProcessor(stage);
card.show(stage);

可能是什么问题?

根据您的回复,您希望对话框是水平的而不是垂直的。

LibGDX 项目默认在横向模式下 运行 创建,当您旋转 phone 或平板电脑时不会旋转。如果您没有更改它,那么这可能就是您的对话框横向显示的原因。我在我的项目中使用 fullUser 进行设备旋转。

编辑 android 项目中的 AndroidManifest.xml 文件并设置 screenOrientation 如下:

android:screenOrientation="fullUser"

您可以在此处查看所有可用选项:

https://developer.android.com/guide/topics/manifest/activity-element.html#screen