Libgdx FitViewport显示黑屏 - Android

时间:2015-06-19 01:01:34

标签: android libgdx

我在Android上遇到libgdx视口系统问题。我想在我的相机上设置FitViewport,而我得到的只是一个黑屏。我试着只用相机,没有视口,它正在工作。我无法设法在视口上正确使用它。

这是我的代码:

变量声明:

private Texture texture;
private Sprite sprite;
private OrthographicCamera camera;
private float virtualWidth, virtualHeight;
private float aspectRatio;
private SpriteBatch batch;
private Viewport viewport;

初​​始化

virtualWidth = 200;
virtualHeight = 200;
aspectRatio = Gdx.graphics.getHeight() / Gdx.graphics.getWidth();
texture = new Texture(Gdx.files.internal("mapa.jpg"));
sprite = new Sprite(texture);
camera = new OrthographicCamera();
viewport = new StretchViewport(virtualWidth * aspectRatio, virtualHeight, camera);
viewport.apply();
camera.position.set(virtualWidth / 2, virtualHeight / 2, 0);
batch = new SpriteBatch();

我的渲染方法:

Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
sprite.draw(batch);
batch.end();

最后,调整大小方法:

viewport.update(width, height);

Plz你能指出我的代码有什么问题吗?

0 个答案:

没有答案