Libgdx在恢复后重新调整大小

时间:2015-08-30 02:06:12

标签: java android libgdx

我正在Libgdx开发一个Android游戏应用程序。我是Libgdx游戏引擎的新手,我在恢复屏幕后出现渲染/调整大小的问题。 Can't resize after pause

调整屏幕大小后效果很好。但不总是。有时它会调整几乎一半的屏幕。 Sometimes i get this error as well

我无法弄清楚问题。我确实谷歌了,发现了一些解决方案,但他们也没有帮助我。

 //This is my manifest in the project.
 <activity
        android:name="com.tll.game.android.AndroidLauncher"
        android:label="@string/app_name" 
        android:screenOrientation="landscape"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

 //Resize function in Game class
  @Override
public void resize(int width, int height) {
    viewport.update(width, height, true);
    camera.update();
}
//i commented the resize function in Screen class, but it didn't work
  @Override
public void resize(int width, int height) {
    //viewPort.update(width, height, true);
    //camera.update();
}
//EDIT: ViewPort And Camera 
protected static final int VIRTUAL_WIDTH = 800, VIRTUAL_HEIGHT = 480;
protected Camera camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
protected Viewport viewPort = new ScalingViewport(Scaling.fill,VIRTUAL_WIDTH, VIRTUAL_HEIGHT, camera);

2 个答案:

答案 0 :(得分:0)

尝试在渲染功能中调用spriteBatch.setProjectionMatrix(camera.projection)

有关详细信息,请查看these tests

此外,请勿在屏幕中注释掉调整大小功能。

答案 1 :(得分:-1)

尝试以下方法:

确保已将视口设置为舞台视口;例如:

stage = new Stage(new StretchViewport(800, 480));

在resize方法中,像这样更新

stage.getViewport().update(width, height, true);

我建议在你的情况下使用拉伸视口。此外,camera.update()属于render方法,或者至少属于我所拥有的方法。 有关视图端口的更多信息:https://github.com/libgdx/libgdx/wiki/Viewports