问题在图片中可见。使用800x600分辨率程序,一切看起来都很正常但是有必要部署程序,按钮很大(大)!如果按下Screen_2按钮(有相同的屏幕)按钮减少(小)!如何在应用时同时部署窗口,而不是在按下按钮时?一般来说,一周或我可以用它做什么。谷歌也没有帮助。那决定写在这里也许有人能够提供帮助。传播屏幕和所有代码:
主要课程的分辨率为800x600:
public class RunGame extends Game {
public SpriteBatch batch;
public BitmapFont font;
TestCamera camera1;
TestCamera2 camera2;
@Override
public void create() {
batch = new SpriteBatch();
font = new BitmapFont();
camera2 = new TestCamera2(this);
setScreen(camera1 = new TestCamera(this));
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void render() {
super.render();
}
}
Class first Screen_1:
public class TestCamera implements Screen {
final RunGame runGameTest;
private Texture backText;
private Skin skin;
private Stage stage;
private OrthographicCamera camera;
private TextButton buttonNewGame;
private TextButton buttonOptions;
private TextButton buttonExit;
public TestCamera(final RunGame runGameTest) {
this.runGameTest = runGameTest;
camera = new OrthographicCamera();
}
@Override
public void show() {
backText = new Texture(Gdx.files.internal("menu/menuScreen/background.jpg"));
skin = new Skin(Gdx.files.internal("fonts/uiskin.json"));
stage = new Stage();
buttonNewGame = new TextButton("--------", skin, "default");
buttonOptions = new TextButton("Screen_2", skin, "default");
buttonExit = new TextButton("--------", skin, "default");
buttonNewGame.setWidth(200f);
buttonNewGame.setHeight(50f);
buttonNewGame.setPosition(50, 240);
buttonOptions.setWidth(200f);
buttonOptions.setHeight(50f);
buttonOptions.setPosition(50, 300f);
buttonExit.setWidth(200f);
buttonExit.setHeight(50f);
buttonExit.setPosition(50, 360f);
buttonNewGame.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
}
});
buttonOptions.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
((Game)Gdx.app.getApplicationListener()).setScreen(runGameTest.camera2);
}
});
buttonExit.addListener(new ClickListener(){
@Override
public void clicked(InputEvent event, float x, float y){
Gdx.app.exit();
}
});
stage.addActor(buttonNewGame);
stage.addActor(buttonOptions);
stage.addActor(buttonExit);
Gdx.input.setInputProcessor(stage);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.0f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
runGameTest.batch.setProjectionMatrix(camera.combined);
camera.update();
runGameTest.batch.begin();
runGameTest.batch.draw(backText, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
runGameTest.font.draw(runGameTest.batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), Gdx.graphics.getWidth()-76, Gdx.graphics.getHeight()-20);
runGameTest.font.draw(runGameTest.batch, "FULL SCREEN: F4 ", Gdx.graphics.getWidth()-150, Gdx.graphics.getHeight()-40);
runGameTest.batch.end();
stage.act();
stage.draw();
}
@Override
public void resize(int width, int height) {
camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
camera.update();
}
@Override
public void dispose() {
Gdx.input.setInputProcessor(null);
backText.dispose();
stage.dispose();
skin.dispose();
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
}
第二个Screen_2与第一个相同!请帮助任何人遇到这个问题。
答案 0 :(得分:0)
我的问题已解决 - stage = new Stage(new ScreenViewport());
并且camera
必须转移到主类!
感谢所有