これはどこかで対処されている簡単な質問かもしれませんが、見つかりません。誰かが私を正しい道に導いてくれることを願っています。私のアプリケーションのデザイン解像度は 800x480 です。より高い解像度のデバイスで正しい縦横比を維持するために、この投稿に従って、大きな画面 (nexus 7) の両側に「黒いバー」(テスト用に青を使用) を表示することに成功しました。ただし、ステージは画面を覆うようにスケーリングされていないようです。以下のスクリーン ショットを参照してください。青色は Gdx.gl.glClearColor(0.5f, 1, 1, 1); です。黒い長方形 (800x480) が実際のスプライトです。
どこで間違ったのかわかりません。どんな助けでも大歓迎です。以下のコード:
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");
}