9

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?

Daahrien
  • 10,190
  • 6
  • 39
  • 71
Aliaaa
  • 1,590
  • 2
  • 16
  • 37

1 Answers1

16

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);
Aliaaa
  • 1,590
  • 2
  • 16
  • 37
  • 2
    In the latest version of the library (0.9.8) `setTransform` seems to be missing, but you can instead call `setClip(true)` which enables transforming as a side effect. – Nick Mar 10 '13 at 12:58
  • 1
    @Nick - setTransform is still there under 0.9.8. It is a method of `Group` http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/Group.html#setTransform%28boolean%29 – Pool Aug 29 '13 at 20:48
  • Setting setTransform(true) fixed a scale on a table for me. The docs lie! They said it is true by default, but it wasn't for me :) – Russ Wheeler Feb 06 '17 at 16:07