Why Libgdx's Table does not accept scale action?

送分小仙女□ 提交于 2020-01-03 08:54:09

问题


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?


回答1:


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);


来源:https://stackoverflow.com/questions/13201462/why-libgdxs-table-does-not-accept-scale-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!