LibGDX-如何正确添加ExtendViewports?
我是LibGDX新手,我正在尝试在进入实际游戏之前先设置屏幕分辨率大小。在添加extendViewport之前,我有一个正交相机和一个显示的图像。但是,当我摆脱了正交摄影机并添加视口时,图像消失了。这是我的屏幕代码LibGDX-如何正确添加ExtendViewports?,libgdx,viewport,Libgdx,Viewport,我是LibGDX新手,我正在尝试在进入实际游戏之前先设置屏幕分辨率大小。在添加extendViewport之前,我有一个正交相机和一个显示的图像。但是,当我摆脱了正交摄影机并添加视口时,图像消失了。这是我的屏幕代码 public class GameScreen implements Screen { SlingshotSteve game; private ExtendViewport viewport; PerspectiveCamera camera; pub
public class GameScreen implements Screen {
SlingshotSteve game;
private ExtendViewport viewport;
PerspectiveCamera camera;
public void Menu(SlingshotSteve game){
this.game = game;
}
SpriteBatch batch;
TextureRegion backgroundTexture;
Texture texture;
GameScreen(final SlingshotSteve gam) {
this.game = gam;
batch = new SpriteBatch();
Texture texture = new Texture(Gdx.files.internal("background.jpg"));
backgroundTexture = new TextureRegion(texture, 0, 0, 500, 500);
Music mp3Sound = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));
mp3Sound.setLooping(true);
mp3Sound.play();
}
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
batch.setProjectionMatrix(camera.combined);
batch.begin();
batch.draw(backgroundTexture, 0, 0, SlingshotSteve.WIDTH, SlingshotSteve.HEIGHT);
batch.end();
}
@Override
public void resize(int width, int height) {
viewport.update(width, height);
}
@Override
public void dispose() {
batch.dispose();
texture.dispose();
}
@Override
public void show() {
camera = new PerspectiveCamera();
viewport = new ExtendViewport(800, 480, camera);
}
}
我的另一个问题是,这个屏幕是游戏的主屏幕,在那里会出现1级。由于我添加了一个主菜单,我不得不从“应用程序侦听器”切换到“实现屏幕”。这是正确的,还是必须返回应用程序侦听器才能获得Create()方法?我不完全确定这一切意味着什么,所以如果有人能向我解释一下,那就太好了