Why Libgdx's Table does not accept scale action?
Asked Answered
L

1

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?

Luminous answered 2/11, 2012 at 19:1 Comment(0)
L
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);
Luminous answered 10/11, 2012 at 10:35 Comment(3)
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.Fluorescein
@Nick - setTransform is still there under 0.9.8. It is a method of Group libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/…Rothenberg
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 :)Udine

© 2022 - 2024 — McMap. All rights reserved.