我使用Maven快照存储库中的最新libGDX版本。
我的主菜单屏幕类如下。请注意由于最新的libGDX快照中的API更改而必须注释掉的代码。
public class MainMenuScreen implements Screen {
@Override
public void resize(int width, int height) {
stage.setViewport(new ScreenViewport(cam));
// stage.setViewport(width, height, true); <- Method signature changed
}
@Override
public void show() {
batch = new SpriteBatch();
stage = new Stage();
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2, 0);
cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
// stage.setCamera(cam); <- Method no longer exists
Gdx.input.setInputProcessor(stage);
// Button is an Actor subclass.
final Button playButton = new Button(Assets.getPlayButtonTexture(), positions.playOut);
stage.addActor(playButton);
playButton.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
// This event no longer fires when I tap playButton!
}
});
}
// ...
private Stage stage;
private SpriteBatch batch;
private OrthographicCamera cam;
}
正如您在touchDown
中的评论中所看到的那样,该事件不再被解雇。
我需要更改代码的哪一部分以允许playButton
actor在最近的libGDX更改之前接收touchDown
个事件?
答案 0 :(得分:1)
解决方案:
stage = new Stage();
stage.setCamera(cam);
变为
stage = new Stage(new ScreenViewport(cam));
和
stage.setViewport(width, height, true);
变为
stage.getViewport().update(width, height, true);