0
我在我的相機中使用虛擬屏幕分辨率,固定的放大比率。初始化看起來是這樣的:在固定寬高比的虛擬屏幕上處理輸入
this.cam = new OrthographicCamera(Config.VIRTUAL_VIEW_WIDTH,
Config.VIRTUAL_VIEW_HEIGHT);
this.cam.setToOrtho(false, Config.VIRTUAL_VIEW_WIDTH,
Config.VIRTUAL_VIEW_HEIGHT);
// create our stage
this.stage = new Stage(0, 0, true);
this.stage.clear(); // always clear the stage too to not get double
// stuff in a stage
stage.setCamera(cam);
//some more stuff
@Override
public void resize(int width, int height) {
// this.cam.setToOrtho(false, width, height);
// calculate new viewport
float aspectRatio = (float) width/(float) height;
float scale = 1f;
Vector2 crop = new Vector2(0f, 0f);
if (aspectRatio > Config.ASPECT_RATIO) {
scale = (float) height/(float) Config.VIRTUAL_VIEW_HEIGHT;
crop.x = (width - Config.VIRTUAL_VIEW_WIDTH * scale)/2f;
} else if (aspectRatio < Config.ASPECT_RATIO) {
scale = (float) width/(float) Config.VIRTUAL_VIEW_WIDTH;
crop.y = (height - Config.VIRTUAL_VIEW_HEIGHT * scale)/2f;
} else {
scale = (float) width/(float) Config.VIRTUAL_VIEW_WIDTH;
}
float w = (float) Config.VIRTUAL_VIEW_WIDTH * scale;
float h = (float) Config.VIRTUAL_VIEW_HEIGHT * scale;
viewport = new Rectangle(crop.x, crop.y, w, h);
}
渲染本身是短暫的:
@Override
public void render(float delta) {
cam.update();
// setting the viewport
Gdx.gl.glViewport((int) viewport.x, (int) viewport.y,
(int) viewport.width, (int) viewport.height);
// the following code clears the screen with the given RGB color (black)
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// update and draw the stage actors
stage.act(delta);
stage.draw();
這工作真的很好,我可以用我的虛擬解決方案的工作。但我遇到了觸摸板的問題。我只是初始化它像這樣:
Gdx.input.setInputProcessor(stage);
skin = new Skin();
skin.add("knob", new Texture("touchpad/touchKnob.png"));
skin.add("background", new Texture("touchpad/touchBackground.png"));
style = new TouchpadStyle();
// skin.add
style.knob = skin.getDrawable("knob");
style.background = skin.getDrawable("background");
pad = new Touchpad(10, style);
pad.setBounds(0, Config.VIRTUAL_VIEW_HEIGHT - 150, 150, 150);
this.stage.addActor(pad);
如果屏幕沒有安裝到虛擬屏幕它不上的觸摸正確或者甚至不反應,因爲墊將在左上邊緣的反應,但在虛擬凸輪在reallity。
任何建議如何解決?
這是一張照片。你看到的區域永遠不會改變,所以你總能看到整個地圖。我爲觸摸板「所在」區域着色。 Menü的按鈕也遇到了同樣的問題。