Marius Boepple Marius Boepple - 25 days ago 7
Android Question

LibGDX - Table - Scale Image to Cell

This is my first LibGDX project.

I have my start screen with my logo and some buttons. But I want my logo to scale down with its proportions. On the pictures you can see, that it's a bit narrowed (taken on my smartphone).

That's my code:

public StartScreen(int lastScore, InputListener inputListener) {
super();
this.listener = inputListener;
stage = new Stage();
Gdx.input.setInputProcessor(stage);

Table table = new Table();
table.setFillParent(true);
table.setBackground(new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("background.png")))));

Image imageLogo = new Image();
imageLogo.setDrawable(new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("title.png")))));

//Here's my problem:

table.add(imageLogo).center().colspan(2); //the image is not scaled right...
table.row();

//create Buttons

table.add(button1).colspan(2).padBottom(30);
table.row();
table.add(button2).padBottom(30);
table.add(button3).padBottom(30);
table.row();
table.add(button4).colspan(2);

stage.addActor(table);

//table.debug();
}


Here's the screen and the original logo (look at proportions ;) :

Google Drive Links:
start screen,
original logo

Answer

I found out that you can use this with images - works fine!

imageLogo.setScaling(Scaling.fit);