0
\$\begingroup\$

I know how to set Image width and height using pixel coords. Is there a way to set relative coords? I want to deal with multiple screens.

For example i have 1920x1080 screen size. And i have relative coords width (-100,100) and height = 200*1080/1920=112.5, height(-56.25, 56.25)

Can i use this relative coords to set width and height? and how to do it? Is there any best practices to handle different screens ratio, handle orientation change correctly?

thanks in advance.

here is how i'm using it in my app:

create()

    public void create() {
         stage = new Stage();
            Gdx.input.setInputProcessor(stage);

            camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            camera.update();

Skin skinBackground = new Skin();
        skinBackground.add("background", new Texture(Gdx.files.absolute(FilePathSlicer.preparePath(taskSheet.background.getPicUrl()))));
        background=new Image(skinBackground,"background");

        if(background!=null) {
            background.setWidth(width);
            background.setHeight(height);
            stage.addActor(background);
        }
    }

render

public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        Gdx.gl.glClearColor(255/255f, 255/255f, 255/255f, 1);
        stage.getBatch().setProjectionMatrix(camera.combined);
        stage.act(Gdx.graphics.getDeltaTime());
        stage.draw();
    }
\$\endgroup\$
  • \$\begingroup\$ I am a little confused. Are you asking how to make the image width and height the same in all screen sizes? \$\endgroup\$ – JDSweetBeat Sep 18 '15 at 15:05
  • \$\begingroup\$ Yes, it's what I want. And also to support all screen orientation \$\endgroup\$ – Jenya Kirmiza Sep 29 '15 at 21:37
0
\$\begingroup\$

you are probably looking for LibGDX ViewPorts regarding your screen ratio issue. Viewports allow you to apply screen indipendent rules. I hope this helps, even though the question is not recent.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.