Quantcast
Channel: Question and Answer » libgdx
Viewing all articles
Browse latest Browse all 434

resize images in libgdx

$
0
0

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 1920×1080 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();
    }

Viewing all articles
Browse latest Browse all 434

Trending Articles