这可能是一个简单的问题,但我无法找到它。我确实希望有人能带领我走向正确的道路。我的应用程序的设计分辨率为800x480。为了在更高分辨率的设备上保持正确的长宽比,我遵循this post,并设法在更大的屏幕(nexus 7)两侧获得“黑条”(我用蓝色进行测试)。不过,舞台似乎没有扩大到覆盖屏幕。请参阅屏幕截图波纹管,蓝色是Gdx.gl.glClearColor(0.5f,1,1,1);黑色矩形(800x480)是实际的雪碧。需要关于Libgdx Scaling的建议
我不知道我哪里错了。任何帮助深表感谢。代码如下:
private SpriteBatch batch;
private Texture splashTexture;
private Sprite splashSp;
TextureRegion splashTr;
Stage stage;
@Override
public void create() {
stage = new Stage();
batch = new SpriteBatch();
splashTexture = new Texture(Gdx.files.internal("img/splashTexture.png"));
splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion splashTr = new TextureRegion(splashTexture, 0, 0, 800, 480);
splashSp = new Sprite(splashTr);
Gdx.app.log("myapp", "Creating game");
}
@Override
public void render() {
Gdx.gl.glClearColor(0.5f, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
stage.draw();
batch.begin();
batch.draw(splashSp, 0, 0);
batch.end();
}
@Override
public void resize(int width, int height) {
Gdx.app.log("myapp", "width:" + width + " height:" + height);
Vector2 size = Scaling.fit.apply(800, 480, width, height);
int viewportX = (int)(width - size.x)/2;
int viewportY = (int)(height - size.y)/2;
int viewportWidth = (int)size.x;
int viewportHeight = (int)size.y;
Gdx.app.log("myapp", "viewportWidth:" + viewportWidth + " viewportHeight:" + viewportHeight);
Gdx.app.log("myapp", "viewportX:" + viewportX + " viewportY:" + viewportY);
Gdx.gl.glViewport(viewportX, viewportY, viewportWidth, viewportHeight);
stage.setViewport(800, 480, true);
Gdx.app.log("myapp", "Resizing game");
}
您的'Stage'完全独立于精灵的渲染,实际上在这里什么都不做。将'Sprite'作为'Actor'添加到'Stage',或者删除'Stage'并使用'Camera'作为您的视口并使用'SpriteBatch.setProjectionMatrix(camera.combined)'。 – noone