简体   繁体   English

如何在Android中为libGDX设置屏幕大小

[英]how to set screen size in android for libGDX

I am working on libGDX project. 我正在研究libGDX项目。 I want to set the screen size to 480x800. 我想将屏幕尺寸设置为480x800。 In desktop version we can use 在桌面版本中,我们可以使用

config.Width() = 480;
config.Height() = 800;

in DesktopLauncher class. 在DesktopLauncher类中。 It works on desktop, but not on android. 它适用于台式机,但不适用于android。 I want to set the screen at 480x800 so it will work on android device as well. 我想将屏幕设置为480x800,以便它也可以在android设备上使用。 Right now my screen looks like following. 现在,我的屏幕如下图所示。 在此处输入图片说明

How can I solve this issue? 我该如何解决这个问题? Note: I have already used following code 注意:我已经使用了以下代码

    OrthographicCamera camera; 
camera = new OrthographicCamera();
 camera.setToOrtho(false, GameInfo.SCREEN_WIDTH, GameInfo.SCREEN_HEIGHT);
game.getBatch().setProjectionMatrix(game.getCamera().combined);

It works, but it's not a permanant solution. 它可以工作,但不是永久解决方案。 Because, if I want to move the screen I need to set up another orthographicCamera and that doesn't work out at all. 因为,如果我想移动屏幕,则需要设置另一个orthographicCamera,但这根本无法解决。 Is there any command like there is in DesktopLauncher class? 是否有类似DesktopLauncher类中的命令?

If you want to move screen, you can change the position of your camera. 如果要移动屏幕,可以更改相机的位置。

Sprite man;

private void render(float delta){

    //...
    camera.translate(man.getX(),man.getY());
    camera.update();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM