【问题标题】:libGdx - image backgroundlibGdx - 图像背景
【发布时间】:2013-07-12 20:18:57
【问题描述】:

我在 libGdx 中的背景有问题。 我尝试用这个解决我的问题:

“在你的 create() 方法中,创建一个引用你的 image.png 的新纹理,然后使用你现有的 SpriteBatch 在 render() 循环中渲染它。在你的 GL.clear() 调用之后,立即执行你的批处理.draw(backgroundTexture, 0. 0) 并确保您的相机处于正交投影模式。”

我这样做:

    public void render() {
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        camera.update();
        batch.setProjectionMatrix(camera.combined);
        batch.begin();

        batch.draw(image, 250, 200);
        batch.draw(backGroundImage, 0, 0);

        batch.end();

“image”是我的普通纹理(它是简单的图像),“backGround”是ofc。我的背景。 我在我的 create() 方法中应用了“背景”。我的摄像头在 camera = new OrthographicCamera();。 这是我看到的: ...我需要 10 点声望来添加图像:<... href="https://stackoverflow.com/questions/9384662/libgdx-and-android-application-image-as-background" target="_blank" rel="nofollow">a link!还有一个指向 [a panda][1] Shinzul 的参考风格链接说了一些关于 render() 中循环的内容,也许这是我的问题,但我不知道如何解决这个问题。 请帮忙。

【问题讨论】:

    标签: java android libgdx


    【解决方案1】:

    我认为你应该先画出你的背景图像。

    此外,我认为您应该看一些教程,例如https://github.com/libgdx/libgdx/wiki/Spritebatch%2C-Textureregions%2C-and-Sprites。它解释了 libgdx 的相同基本概念。

    【讨论】:

      【解决方案2】:
          public static Texture backgroundTexture;
          public static Sprite backgroundSprite;
          private SpriteBatch spriteBatch;
      
          private void loadTextures() {
              backgroundTexture = new Texture("images/background.png");
              backgroundSprite =new Sprite(backgroundTexture);
              .
              .
          }
      
          public void renderBackground() {
              backgroundSprite.draw(spriteBatch);
          }
      
          public void render() {
              spriteBatch.begin();
                  renderBackground(); //In first place!!!!
                  drawStuff();
                  drawMoreStuff();
                  drawMoreMoreStuff();
              spriteBatch.end();
          }
      

      我找到了this online resource,并帮助我开始了 libgdx 的世界。 希望对您有所帮助。

      【讨论】:

        【解决方案3】:

        您只需使用 Gdx 设置设备 hightwidth,对我有帮助

         batch.draw(mTextureBg, 0 , 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        

        【讨论】:

          【解决方案4】:

          我不知道这是否是最好的方法,但它对我有用。

          sprite.scale(2);
          sprite.setCenter(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
          

          您可以更改 (int) 中的比例,直到它覆盖整个屏幕。

          【讨论】:

            猜你喜欢
            • 2021-05-14
            • 2016-08-19
            • 2018-04-18
            • 1970-01-01
            • 2014-10-17
            • 1970-01-01
            • 2014-03-04
            • 1970-01-01
            • 2021-02-07
            相关资源
            最近更新 更多