Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Libgdx's Table does not accept scale action?

I'm using scene2d in libgdx library for creating some UI in my game.

I used a Table and I want to take some scaling action when user touches to make a button touching sense.

When I used any other "Actor" types like Group and giving it a scale action it works but not Table.

this is my Table definition:

Table table = new Table();
table.setSize(width, height);
table.setPosition(x, y);
table.setOrigin(width/2, height/2);
table.add(new Label(...));
table.row();
...

And in my touchDown event I give it a scale action:

table.addAction(Actions.scaleTo(0.8f, 0.8f, 0.1f));

And in touchUp I give it another action to get original scale:

table.addAction(Actions.scaleTo(1f, 1f, 0.1f));

As I said this code works for another types of Actors like Image and Group. Any Ideas that why don't works for Table?

like image 327
Aliaaa Avatar asked Nov 02 '12 19:11

Aliaaa


1 Answers

Answering to my own question:

In order to the libGdx's documentation (https://code.google.com/p/libgdx/wiki/scene2dui#Rotation_and_scale) table does not supports scaling and rotating if it's background was set.

If we want to scale and/or rotate the table we have to behave like the code below:

TextButton button = new TextButton("Text Button", skin);
Table wrapper = new Table();
wrapper.add(button);
wrapper.setTransform(true);
wrapper.setOrigin(wrapper.getPrefWidth() / 2, wrapper.getPrefHeight() / 2);
wrapper.setRotation(45);
wrapper.setScaleX(1.5f);
like image 159
Aliaaa Avatar answered Oct 13 '22 06:10

Aliaaa