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

  • <small id='DQPRV'></small><noframes id='DQPRV'>

        • <bdo id='DQPRV'></bdo><ul id='DQPRV'></ul>
        <tfoot id='DQPRV'></tfoot>
      1. 如何在 Libgdx 中调整精灵的大小?

        时间:2023-05-20

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

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

        • <bdo id='yEu11'></bdo><ul id='yEu11'></ul>
          <tfoot id='yEu11'></tfoot>
              <tbody id='yEu11'></tbody>

                • <legend id='yEu11'><style id='yEu11'><dir id='yEu11'><q id='yEu11'></q></dir></style></legend>
                  本文介绍了如何在 Libgdx 中调整精灵的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我对 Libgdx 中的方法 sprite.setSize(float x, float y) 有问题.它不会影响精灵的大小或维度.无论我传递给 setSize() 方法,它们都保持不变.

                  I have a problem with the method sprite.setSize(float x, float y) in Libgdx. It does not affect the size or the dimensions of the sprite. They remains fixed whatever I pass to the setSize() method.

                  这是我的代码:

                  public class GameScreen implements Screen {
                  
                      OrthographicCamera camera;
                  
                      SpriteBatch batch;
                      Texture carTexture;
                      Sprite carSprite;
                  
                      public GameScreen()
                      {
                      }
                  
                      @Override
                      public void render(float delta) {
                          // TODO Auto-generated method stub
                          Gdx.gl.glClearColor(0,0,0,0);
                          Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
                          batch.begin();
                              carSprite.setSize(16, 32);
                              batch.draw(carSprite, 0 , 0);
                          batch.end();
                          camera.update();    
                  }
                  
                      @Override
                      public void resize(int width, int height) {
                          // TODO Auto-generated method stub
                          camera.viewportWidth=width;
                          camera.viewportHeight=height;
                          camera.update();
                      }
                  
                      @Override
                      public void show() {
                          // TODO Auto-generated method stub
                          camera = new OrthographicCamera();
                          batch = new SpriteBatch();
                  
                          carTexture = new Texture(Gdx.files.internal("NetRace.png"));
                          carTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
                  
                          carSprite = new Sprite(carTexture);
                      }
                  
                      @Override
                      public void hide() {
                          // TODO Auto-generated method stub
                      }
                  
                      @Override
                      public void pause() {
                          // TODO Auto-generated method stub
                      }
                  
                      @Override
                      public void resume() {
                          // TODO Auto-generated method stub
                      }
                  
                      @Override
                      public void dispose() {
                          // TODO Auto-generated method stub
                      }
                  }
                  

                  你能找出我的错误吗?

                  推荐答案

                  问题解决了.

                  我不得不使用 sprite.draw(batch); 而不是使用 Batch.draw(Sprite sp, float x, float y); 因为 Batch.draw(...) 方法从传入的精灵中获取纹理,并在绘制过程中使用具有固定宽度和固定高度的纹理.

                  I had to use sprite.draw(batch); instead of using Batch.draw(Sprite sp, float x, float y); since the Batch.draw(...) method takes the texture from the passed sprite and uses the texture in the drawing process which has a fixed width and a fixed height.

                  解决这个问题的另一种方法是使用SpriteBatch中的batch.draw(Sprite, float x, float y, float width, float height);方法类.

                  Another way to solve this problem is to use the batch.draw(Sprite, float x, float y, float width, float height); method in the SpriteBatch class.

                  这篇关于如何在 Libgdx 中调整精灵的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 libGDX 使用键盘键移动精灵? 下一篇:我怎么能每秒都做某事?[LibGDX]

                  相关文章

                  最新文章

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

                    • <bdo id='RiIfr'></bdo><ul id='RiIfr'></ul>
                      <legend id='RiIfr'><style id='RiIfr'><dir id='RiIfr'><q id='RiIfr'></q></dir></style></legend>

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

                    1. <tfoot id='RiIfr'></tfoot>