【发布时间】:2017-03-03 21:04:29
【问题描述】:
我正在 libgdx 中为 android 制作游戏,并且一直致力于实现视口。我有一个 libgdx 触摸板作为舞台上的演员,一旦我将 FitViewport 应用到舞台上,触摸板旋钮不会正确调整大小并填满屏幕,而所有其他元素都会正确调整大小。如何让触摸板旋钮与其他元素一起调整大小?
这是我的代码:
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);
}
【问题讨论】: