這可能是一個簡單的問題,但我無法找到它。我確實希望有人能帶領我走向正確的道路。我的應用程序的設計分辨率爲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