Libgdx恢复后调整大小

4

我正在使用Libgdx开发一款Android游戏应用程序。由于我非常新手,所以在渲染/调整屏幕大小后恢复时遇到了问题。 无法在暂停后调整大小

虽然调整大小后屏幕效果良好,但并非总是如此。有时它会将屏幕调整到几乎一半的大小。 有时我也会遇到这个错误

我无法找出问题所在。我已经在Google上搜索过,找到了一些解决方案,但它们并没有帮助我。

 //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

尝试在您的渲染函数中调用 spriteBatch.setProjectionMatrix(camera.projection)

如需更多信息,请查看这些测试

同时,请勿注释掉Screen中的resize函数。


我在渲染函数中添加了这行代码,但它并没有起作用。 - Abdullah Tellioglu

-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

谢谢您的回答,但问题仍然存在。 - Abdullah Tellioglu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接