0
我正在爲libgdx中的android製作遊戲,並一直致力於實現視口。我在舞臺上有一個作爲演員的libgdx觸控板,只要我將FitViewport應用到舞臺上,觸控板旋鈕不會正確調整大小,並在所有其他元素正確調整大小時填充屏幕。如何讓觸摸板旋鈕與其他元素一起調整大小?Libgdx觸控板旋鈕無法正確調整大小
這裏是我的代碼:
private Touchpad touchpad;
private Touchpad.TouchpadStyle touchpadStyle;
private Skin touchpadSkin;
private Drawable touchBackground;
private Drawable touchKnob;
public PlayState(GameStateManager gsm) {
super(gsm);
touchpadSkin = new Skin();
//Set background image
touchpadSkin.add("touchBackground", new Texture("joystick_base.png"));
//Set knob image
touchpadSkin.add("touchKnob", new Texture("joystick_64.png"));
//Create TouchPad Style
touchpadStyle = new Touchpad.TouchpadStyle();
//Create Drawable's from TouchPad skin
touchBackground = touchpadSkin.getDrawable("touchBackground");
touchKnob = touchpadSkin.getDrawable("touchKnob");
touchpadStyle.background = touchBackground;
touchpadStyle.knob = touchKnob;
//Create new TouchPad with the created style
touchpad = new Touchpad(10, touchpadStyle);
//setBounds(x,y,width,height)
touchpad.setBounds(0.5f,0.5f,WORLD_WIDTH/7,WORLD_HEIGHT/5);
stage = new Stage(new FitViewport(WORLD_WIDTH,WORLD_HEIGHT));
stage.addActor(touchpad);
Gdx.input.setInputProcessor(stage);
protected void render(SpriteBatch sb) {
touchpad.draw(sb, 1);
}
如何重寫調整大小的方法? –
如果您使用intellij想法,請右鍵單擊代碼,然後按生成...並觸摸覆蓋方法。如果不是,只需鍵入public void resize(float width,float higth){} – danielleontiev
此代碼位於PlayState類中,它擴展了State,因此我無法覆蓋resize方法。 –