LibGDX - 如何正确添加ExtendViewports?

时间:2014-09-08 22:48:12

标签: libgdx viewport

我是LibGDX的新手,我试图在进入实际游戏之前先设​​置我的屏幕分辨率大小。在我添加extendViewport之前,我有一个正交摄影机和一个显示的图像。但当我摆脱了正交相机并添加了Viewport时,图像就消失了。这是我对屏幕的代码。

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()方法?我不能完全确定一切意味着什么如果有人可以向我解释这将是伟大的!

0 个答案:

没有答案