在我的create()方法中,我创建了一个表并插入了一些按钮,如下图所示。按下按钮前的设置位置Libgdx
http://www2.pic-upload.de/thumb/29190899/Unbenannt.png
用户每次按下按钮,一个新的拖累,能够质地应该出现他的手指/按钮位置下方。
我试过如下:
sourceImage.addListener(controller);
testbutton.get(2).addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
sourceImage.setVisible(true);
sourceImage.setPosition(vec.x, vec.y);
return super.touchDown(event, x, y, pointer, button);
}
});
这个工作不错,但我想让它使用户得到了他的手指上的纹理,而不必在其上再次按下拖动。
因此,我试图在触摸开始之前将图像放到按钮上。
问题是,我不能得到表按钮的位置,因为表将在应用程序启动后呈现,而不是在create()中,如果我错了,就纠正我。
它返回0,0,当我试图让在实际的表中的位置我创建()
我发现在论坛的解决方案: Getting Stage coordinates of Actor in Table in libGDX
public static Vector2 getStageLocation(Actor actor) {
return actor.localToStageCoordinates(new Vector2(0, 0));
}
,并在我的渲染()
vec = getStageLocation(testbutton.get(2));
它给我在我的表中的按钮的正确位置,但我不知道何时何地我必须设置的位置按钮按下之前的纹理?