我通过RoboVM在android中编写了一个带LibGDX的游戏。迁移到Multi-OS Engine后,除了在iOS版本中使用Touchpad
和firepad之外,一切正常,如果我一起触摸它们就会冻结它们。我认为主要问题是LibGDX在iOS版本中无法处理多点触控。通过在touchDown和touchUp覆盖方法中添加Gdx.app.log
,我发现如果我触摸两个触摸板,则touchUp方法永远不会调用,直到下次再次触摸它们。
我的代码是这样的:
Gdx.input.setInputProcessor(stage);
stage = new Stage();
private void initTouchPad() {
Touchpad.TouchpadStyle touchpadStyle;
Skin touchpadSkin;
Drawable touchBackground;
Drawable touchKnob;
touchpadSkin = new Skin();
//Set background image
touchpadSkin.add("touchBackground", new Texture("touchBackground.png"));
//Set knob image
touchpadSkin.add("touchKnob", new Texture("touchKnob.png"));
touchpadStyle = new Touchpad.TouchpadStyle();
//Create Drawable's from TouchPad skin
touchBackground = touchpadSkin.getDrawable("touchBackground");
touchKnob = touchpadSkin.getDrawable("touchKnob");
touchKnob.setMinWidth(Gdx.graphics.getWidth()/6/3);
touchKnob.setMinHeight(Gdx.graphics.getWidth()/6/3);
//Apply the Drawables to the TouchPad Style
touchpadStyle.background = touchBackground;
touchpadStyle.knob = touchKnob;
//Create new TouchPad with the created style
touchpad = new Touchpad(10, touchpadStyle);
//setBounds(x,y,width,height)
float touchPadSize = Gdx.graphics.getWidth() / 6;
if(MainGame.FireButton)
touchpad.setBounds(touchPadSize*5 , 15, touchPadSize, touchPadSize);
else
touchpad.setBounds(15, 15, Gdx.graphics.getWidth()/6, Gdx.graphics.getWidth()/6);
touchpad.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("toudhpad", "touch down");
touchPadTouched = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
touchPadTouched = false;
Gdx.app.log("toudhpad", "touch up");
}
});
stage.addActor(touchpad);
}
private void initFirePad() {
Touchpad.TouchpadStyle touchpadStyle;
Skin touchpadSkin;
Drawable touchBackground;
touchpadSkin = new Skin();
//Set background image
Texture fireTexture = new Texture("fire_button.png");
touchpadSkin.add("touchBackground", fireTexture);
touchpadStyle = new Touchpad.TouchpadStyle();
//Create Drawable's from TouchPad skin
touchBackground = touchpadSkin.getDrawable("touchBackground");
//Apply the Drawables to the TouchPad Style
touchpadStyle.background = touchBackground;
//Create new TouchPad with the created style
firePad = new Touchpad(10, touchpadStyle);
//setBounds(x,y,width,height)
float firePadSize = Gdx.graphics.getWidth() / 6;
if(MainGame.FireButton)
firePad.setBounds(15, 15, Gdx.graphics.getWidth()/6, Gdx.graphics.getWidth()/6);
else
firePad.setBounds(firePadSize*5 , 15, firePadSize, firePadSize);
firePad.addListener(new InputListener(){
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("firepad", "touch down");
firePadTouched = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log("firepad", "touch up");
firePadTouched = false;
}
});
stage.addActor(firePad);
}