【发布时间】:2017-04-01 15:33:50
【问题描述】:
假设我有一个演员foo 和一个演员bar,这是foo 演员的更大版本。如何在foo 被点击时在foo 旁边显示bar,然后在不再点击foo 时让它消失(有点像工具提示)? Foo 在 stage2d 表中。
如何在点击时显示更大、更完整的演员版本?
大致了解我想要什么:
Actor foo = new Actor();
foo.addListener(new ActorGestureListener() {
public void touchDown (InputEvent event, float x, float y, int pointer, int button) {
// show bar next to foo (like a tooltip)
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
// make bar dissapear
}
});
这样的代码可以满足我的需求:
在这种情况下,toolTipCard 是我在触摸来自selectedDeck 的字符串之一时想要显示的演员。
Stage collectionStage;
List<String> selectedDeck;
TestCard tooltipCard;
Vector3 touch = new Vector3();
selectedDeck.addListener(new ActorGestureListener() {
public void touchDown(InputEvent event, float x, float y, int count, int button) {
if (selectedDeck.getItems().size > 0) {
tooltipCard = new TestCard(game.cardFont, cardNameToCard.get(selectedDeck.getSelected()));
tooltipCard.setWidth(Gdx.graphics.getWidth() / (7 * scale));
tooltipCard.setHeight(Gdx.graphics.getHeight() / (3.3f * scale));
touch = viewport.unproject(touch.set(Gdx.input.getX(), Gdx.input.getY(), 0));
tooltipCard.setPosition(touch.x - tooltipCard.getWidth(), touch.y - tooltipCard.getHeight());
collectionStage.addActor(tooltipCard);
}
}
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
tooltipCard.remove();
}
});
【问题讨论】:
-
创建自己的 Image(foo),覆盖该 Image 的 draw 方法并使用标志绘制条(纹理或标签)。在 touchDown 方法上更改平面值。
-
获取被点击的演员 (
foo) 的位置,然后将另一个演员 (bar) 添加到舞台上转换为大小的那个位置不是更好的主意吗被窃听的演员 (foo)? -
不需要再创建一个actor,只有一个actor foo,bar只是foo的一部分,就像你的actor的数据成员一样。