Android libgdx big screen resolution

前端 未结 2 1145
醉梦人生
醉梦人生 2021-02-06 15:57

How can I support (make an algorithm) for libgdx for supporting multiple screen resolution? I made my app work on HTC Tattoo using if statments with parameters like:

         


        
2条回答
  •  面向向阳花
    2021-02-06 16:07

    It's pretty easy. You basically build your entire program for your native resolution, but in everything dealing with positioning and texture sizing have something like this:

    private void resize()
    {
        float x = Gdx.graphics.getWidth();
        float y = Gdx.graphics.getHeight();
    
        float changeX = x / assumeX; //being your screen size that you're developing with
        float changeY = y / assumeY;
    
        position = new Vector2(position.x * changeX, position.y * changeY);
        width = startWidth * changeX;
        height = startHeight * changeY;
        bounds = new Vector2 (position.x, (Gdx.graphics.getHeight() - position.y) - height);
    
    }
    

    Basically what you're doing is taking every object generated and running it through something that increases/decreases depending on the change in the x/y values in your resolution. The further it is from the native, the bigger it will be. When checking of something is somewhere or putting something somewhere, always code it as your desired resolution but run it through a resize function before displaying it or letting it interact with the rest of your program.

提交回复
热议问题