为什么Libgdx的表格不接受缩放动作? [英] Why Libgdx's Table does not accept scale action?

查看:114
本文介绍了为什么Libgdx的表格不接受缩放动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用libgdx库中的scene2d在游戏中创建一些UI.

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.

当我使用诸如Group之类的任何其他"Actor"类型并为其执行缩放操作时,它可以工作,但不能使用Table.

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

这是我的表定义:

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

在我的touchDown事件中,我给它一个缩放动作:

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

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

在touchUp中,我给它另一个操作以获取原始比例:

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

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

正如我所说,此代码适用于其他类型的Actor,例如Image和Group. 为什么不适合Table的任何想法?

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

推荐答案

回答我自己的问题:

为了设置libGdx的文档(https://code.google.com/p/libgdx/wiki/scene2dui#Rotation_and_scale)表,如果设置了背景,则不支持缩放和旋转.

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

这篇关于为什么Libgdx的表格不接受缩放动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆