سؤال

I am developing a game in libgdx. I was searching on the Internet and I just didn't find anything.

Does android by default scale my png images in the assets folder so that they render at the appropriate physical size on each device? And if not, how can I do that? Just put them in mdpi/hdpi folders?

For example:

My stage which renderred the Life bar and all the UI things: (And it just not resizing itself, in my phone it all OK but in for exmaple nexus 5 all is small):

This is my resize method: it don't work at all.

    @Override
public void resize(int width, int height) {

    this.height = height;
    this.width = width;




    camera.viewportHeight = height / 1.4f;
    camera.viewportWidth = width / 1.5f;

    stage.setViewport(width, height, true);
    //  stage.getCamera().position.set(Gdx.graphics.getWidth()/2,           Gdx.graphics.getHeight()/2, 0);

      //All the Tables
        table.invalidateHierarchy();
        table.setSize(width, height);
        table2.invalidateHierarchy();
        table2.setSize(width, height);
        table3.invalidateHierarchy();
        table3.setSize(width, height);



            table4.invalidateHierarchy();
            table4.setSize(width, height);


}
هل كانت مفيدة؟

المحلول

Everything that is in assets folder is ignored by compiler, images are not rescaled or any other special logic is applied. That is the case if you are developing with LibGDX or a standart android application. You access assets folder like any other folder.

If you have problem with supporting different screen sizes, check out this LibGDX tutorial. Take a look how the banner texture is rendered across different screen sizes.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top