I'm making a game with Java and Libgdx scene2d. This is my code in the constructor:
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);
Then in resize() I do the following:
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);
}
The problem is that when I resize the screen (I'm running the desktop version) to a small enough width, the touchpad gets somehow 'inverted'. It seems like the background is on top and is moving when I touch the touchpad. Also the direction (percentX, percentY) it gives is the negative of what it should be.
Why does this happen and how can I prevent it?