Libgdx scene2d 触摸板在设置边界太小时'inverted'



我正在用Java和Libgdx scene2d制作一款游戏。下面是构造函数中的代码:

atlas = new TextureAtlas("gfx/button.pack");
skin = new Skin(atlas);
TouchpadStyle touchpadStyle = new TouchpadStyle();
touchpadStyle.background = skin.getDrawable("button.up");
touchpadStyle.knob = skin.getDrawable("button.down");
touchpadStyle.knob.setLeftWidth(20);
touchpadStyle.knob.setRightWidth(20);
touchpadStyle.knob.setBottomHeight(20);
touchpadStyle.knob.setTopHeight(20);
controller = new Touchpad(1f, touchpadStyle);
addActor(controller);

然后在resize()中执行如下操作:

public void resize(float width, float height) {
    setViewport(width, height, true);
    //TODO setting the bounds too small breaks the touchpad?
    controller.setBounds( width*1f/16, height*1f/9, width/7f, width/7f); 
}

问题是,当我调整屏幕大小(我运行的是桌面版本)到一个足够小的宽度时,触摸板不知何故"倒"了。当我触摸触摸板时,背景似乎在上面,并且在移动。而且,它给出的方向(percentX, percent)是它应该是负的。

为什么会发生这种情况,我该如何预防?

如果你想让控制器始终占屏幕的1/7,为什么你要使用像素完美的舞台?在你的resize方法中,为什么不这样做:

    virtualStage.setViewport(MyGame.VIRTUAL_WIDTH, MyGame.VIRTUAL_HEIGHT, true);
    virtualStage.getCamera().translate(-virtualStage.getGutterWidth(),-virtualStage.getGutterHeight(), 0);
    Camera c = virtualStage.getCamera();
    c.update();

如果您愿意,可以省略翻译(取决于您在右侧显示的内容)。我想知道如果改变控制器的边界在调整大小是什么搞乱了它。

最新更新