我測試我的精靈,有遊戲標題,在我的摩托羅拉Moto G第二代精靈的尺寸看起來不錯,但我也測試我的母親電話,一部三星GT-S5830i,精靈的高度看起來很平坦。 我也試圖理解Viewport的概念(我正在使用StretchViewport),但我不知道我是否正確。我的遊戲是爲移動設備而非桌面設計的。根據不同的屏幕分辨率在Libdx不適合的精靈
我這樣做是爲了我的閃屏:
this.gameTitle = new Sprite(new Texture(Gdx.files.internal("images/GameTitle.png")));
this.gameTitle.setSize(Configuration.DEVICE_WIDTH - 50, this.gameTitle.getHeight() * Configuration.DEVICE_HEIGHT/Configuration.DEVICE_WIDTH);
的DEVICE_HEIGTH和DEVICE_WIDTH是關於屏幕的尺寸常量。並且「-50」是精靈的邊緣
在我的視口中,我使用屏幕的實際尺寸作爲尺寸,還是應該使用虛擬尺寸?但它是如何工作的?
這是我的主要課程的一部分,我可以改變什麼?
// Create the Orthografic camera
this.orthoCamera = new OrthographicCamera(Configuration.DEVICE_WIDTH, Configuration.DEVICE_HEIGHT);
this.orthoCamera.setToOrtho(false, Configuration.VIRTUAL_GAME_WIDTH, Configuration.VIRTUAL_GAME_HEIGHT);
this.orthoCamera.position.set(this.orthoCamera.viewportWidth/2f, this.orthoCamera.viewportHeight/2f, 0);
this.orthoCamera.update();
// Combine SpriteBatch with the camera
this.spriteBatch.setTransformMatrix(this.orthoCamera.combined);
// Create the ViewPort
this.viewPort = new ExtendViewport(Configuration.DEVICE_WIDTH, Configuration.DEVICE_HEIGHT);
我更新了我的視口到ExtendViewport,如你所說。
主要類渲染方法:
public void render() {
super.render();
// Update Orthographic camera
this.orthoCamera.update();
// Combine SpriteBatch with the camera
this.spriteBatch.setTransformMatrix(this.orthoCamera.combined);
}
Screen類渲染方法:
@Override
public void render(float delta) {
// OpenGL clear screen
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(Gdx.gl.GL_COLOR_BUFFER_BIT | Gdx.gl.GL_DEPTH_BUFFER_BIT);
// SpriteBatch begins
this.game.spriteBatch.begin();
// Display the ClimbUp logo
this.gameTitle.draw(this.game.spriteBatch);
this.character.draw(this.game.spriteBatch);
// SpriteBatch ends
this.game.spriteBatch.end();
}
它不會使設備的寬度感,高度是Android上的常量。 – Tenfour04 2015-02-12 20:43:38