<legend id='crLxi'><style id='crLxi'><dir id='crLxi'><q id='crLxi'></q></dir></style></legend>

    <i id='crLxi'><tr id='crLxi'><dt id='crLxi'><q id='crLxi'><span id='crLxi'><b id='crLxi'><form id='crLxi'><ins id='crLxi'></ins><ul id='crLxi'></ul><sub id='crLxi'></sub></form><legend id='crLxi'></legend><bdo id='crLxi'><pre id='crLxi'><center id='crLxi'></center></pre></bdo></b><th id='crLxi'></th></span></q></dt></tr></i><div id='crLxi'><tfoot id='crLxi'></tfoot><dl id='crLxi'><fieldset id='crLxi'></fieldset></dl></div>

  • <tfoot id='crLxi'></tfoot>
      <bdo id='crLxi'></bdo><ul id='crLxi'></ul>
  • <small id='crLxi'></small><noframes id='crLxi'>

        LibGDX - 如何让我的菜单屏幕切换到游戏屏幕?

        时间:2023-05-18
      1. <tfoot id='TEED2'></tfoot>

          • <bdo id='TEED2'></bdo><ul id='TEED2'></ul>
              <tbody id='TEED2'></tbody>
          • <legend id='TEED2'><style id='TEED2'><dir id='TEED2'><q id='TEED2'></q></dir></style></legend>
              <i id='TEED2'><tr id='TEED2'><dt id='TEED2'><q id='TEED2'><span id='TEED2'><b id='TEED2'><form id='TEED2'><ins id='TEED2'></ins><ul id='TEED2'></ul><sub id='TEED2'></sub></form><legend id='TEED2'></legend><bdo id='TEED2'><pre id='TEED2'><center id='TEED2'></center></pre></bdo></b><th id='TEED2'></th></span></q></dt></tr></i><div id='TEED2'><tfoot id='TEED2'></tfoot><dl id='TEED2'><fieldset id='TEED2'></fieldset></dl></div>

              <small id='TEED2'></small><noframes id='TEED2'>

                  本文介绍了LibGDX - 如何让我的菜单屏幕切换到游戏屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  当我运行应用程序时,我的菜单屏幕显示,但是当我单击屏幕开始玩游戏时,游戏开始玩,但菜单屏幕仍然覆盖游戏.我知道这一点是因为游戏中有音乐播放.我将来还会添加一个启动画面,但我现在并不担心.我是新来的,所以请尽可能地解释事情.以下是用于实现此目的的 3 个类.

                  When I run the application my menu screen shows, but when I click the screen to begin playing the game the game begins playing but the menu screen is still their overlaying the game. I know this because the game has music playing. I'm also going to add a splash screen in the future but I'm not concerned about that right now. I'm new at this so please explain things as best as you can. Below are the 3 classes used to make this happen.

                  public class SlingshotSteve extends Game {
                  
                  public SpriteBatch batch;
                  public BitmapFont font;
                  
                  public void create() {
                  batch = new SpriteBatch();
                  //Use LibGDX's default Arial font.
                  font = new BitmapFont();
                  this.setScreen(new Menu(this));
                  }
                  
                  public void render() {
                  super.render(); //important!
                  }
                  
                  public void dispose() {
                  batch.dispose();
                  font.dispose();
                  }
                  
                  }
                  

                  这里是主菜单屏幕

                  public class Menu implements Screen {
                  
                  final SlingshotSteve game;
                  
                  OrthographicCamera camera;
                  
                  public Menu(final SlingshotSteve gam) {
                  game = gam;
                  
                  camera = new OrthographicCamera();
                  camera.setToOrtho(false, 800, 480);
                  }
                  
                  @Override
                  public void render(float delta) {
                  
                  Gdx.gl.glClearColor(0, 0, 0.2f, 1);
                  Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                  
                  camera.update();
                  game.batch.setProjectionMatrix(camera.combined);
                  
                  game.batch.begin();
                  game.font.draw(game.batch, "Welcome to Slingshot Steve!!! ", 100, 150);
                  game.font.draw(game.batch, "Tap anywhere to begin!", 100, 100);
                  game.batch.end();
                  
                  if (Gdx.input.isTouched()) {
                      game.setScreen((Screen) new GameScreen(game));
                      dispose();
                  }
                  }
                  

                  这是游戏画面

                  public class GameScreen implements Screen {
                  final SlingshotSteve game;   
                  
                  OrthographicCamera camera;
                  // Creates our 2D images
                  SpriteBatch batch;
                  TextureRegion backgroundTexture;
                  Texture texture;
                  
                  GameScreen(final SlingshotSteve gam) {
                      this.game = gam; 
                  
                  camera = new OrthographicCamera(1280, 720);
                  
                  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() {  
                  
                    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                  
                    camera.update();
                    batch.setProjectionMatrix(camera.combined);
                  
                    batch.begin();
                    batch.draw(backgroundTexture, 0, 0); 
                    batch.end();
                  
                  }
                  
                  @Override
                  public void resize(int width, int height) {
                  
                  }
                  
                  @Override
                  public void pause() {
                  
                  }
                  
                  @Override
                  public void resume() {
                  
                  }
                  
                  @Override
                  public void dispose() {
                     batch.dispose();
                     texture.dispose();
                  
                  }
                  

                  推荐答案

                  不确定,但我认为您在 GameScreen 上的 render() 方法没有被调用.您必须实现方法 render(float delta) 使用 delta time 作为参数.

                  Not sure but I think your render() method on GameScreen not called. you must implement method render(float delta) that use delta time for parameter.

                  替换

                  public void render() {
                      // your code
                  }
                  

                  public void render(float delta) {
                      // your code
                  }
                  

                  这篇关于LibGDX - 如何让我的菜单屏幕切换到游戏屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:LibGDX - 围绕它们的中心旋转一个 2d 精灵数组 下一篇:Box2D 中的链形

                  相关文章

                  最新文章

                  • <bdo id='AqsVS'></bdo><ul id='AqsVS'></ul>

                    <small id='AqsVS'></small><noframes id='AqsVS'>

                      <legend id='AqsVS'><style id='AqsVS'><dir id='AqsVS'><q id='AqsVS'></q></dir></style></legend>

                    1. <i id='AqsVS'><tr id='AqsVS'><dt id='AqsVS'><q id='AqsVS'><span id='AqsVS'><b id='AqsVS'><form id='AqsVS'><ins id='AqsVS'></ins><ul id='AqsVS'></ul><sub id='AqsVS'></sub></form><legend id='AqsVS'></legend><bdo id='AqsVS'><pre id='AqsVS'><center id='AqsVS'></center></pre></bdo></b><th id='AqsVS'></th></span></q></dt></tr></i><div id='AqsVS'><tfoot id='AqsVS'></tfoot><dl id='AqsVS'><fieldset id='AqsVS'></fieldset></dl></div>

                      <tfoot id='AqsVS'></tfoot>