• <bdo id='34Dui'></bdo><ul id='34Dui'></ul>

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

    <small id='34Dui'></small><noframes id='34Dui'>

        gdx.input.getY 被翻转

        时间:2023-05-18
        <legend id='RdU75'><style id='RdU75'><dir id='RdU75'><q id='RdU75'></q></dir></style></legend>
          <tbody id='RdU75'></tbody>

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

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

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

                  <bdo id='RdU75'></bdo><ul id='RdU75'></ul>

                • 本文介绍了gdx.input.getY 被翻转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在 LibGDX 中有一个问题,当我调用 Gdx.input.getY() 时,它会选择相对于屏幕中心位于应用程序另一侧的像素.

                  I have an issue in LibGDX where when i call upon Gdx.input.getY(), it selects a pixel that's on the other side of the application relative to the center of the screen.

                  public class Main extends ApplicationAdapter {
                  private SpriteBatch batch;
                  private Texture img;
                  private OrthographicCamera camera;
                  int xPos;
                  int yPos;
                  private Vector3 tp = new Vector3();
                  BitmapFont font;
                  
                  @Override
                  public void create () {
                      batch = new SpriteBatch();
                      img = new Texture("crosshair.png");
                      camera = new OrthographicCamera();
                      camera.setToOrtho(false, 1280, 720);
                      font = new BitmapFont();
                  
                  }
                  
                  @Override
                  public void render () {
                      yPos = Gdx.input.getY();
                      xPos = Gdx.input.getX();
                      Gdx.gl.glClearColor(0, 0, 0, 1);
                      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                      camera.unproject(tp.set(xPos, yPos, 0));
                      batch.begin();
                      font.draw(batch,xPos + " , " + yPos, Gdx.input.getX() - 25, Gdx.input.getY() - 5);
                      batch.draw(img, xPos, yPos);
                      batch.end();
                  }
                  
                  @Override
                  public void dispose () {
                      batch.dispose();
                      img.dispose();
                  }
                  

                  推荐答案

                  用触摸位置减去视口高度是行不通的,因为那会用触摸坐标减去世界坐标.(即使对于像素完美投影,它也是 height - 1 - y).而是使用 unproject 方法将触摸坐标转换为世界坐标.

                  Subtracting the viewport height with the touch location won't work, because that would be subtracting world coordinates with touch coordinates. (and even for a pixel perfect projection it would be height - 1 - y). Instead use the unproject method to convert touch coordinates to world coordinates.

                  你的代码有两个问题:

                  • 您永远不会设置批量投影矩阵.
                  • 即使您使用 unproject 方法,您也永远不会使用它的结果.
                  • You are never setting the batch projection matrix.
                  • Even though you are using the unproject method, you are never using its result.

                  所以改为使用以下内容:

                  So instead use the following:

                  @Override
                  public void render () {
                      Gdx.gl.glClearColor(0, 0, 0, 1);
                      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
                      batch.setProjectionMatrix(camera.combined);
                      batch.begin();
                      camera.unproject(tp.set(Gdx.input.getX(), Gdx.input.getY(), 0));
                      font.draw(batch,tp.x+ " , " + tp.y, tp.x - 25, tp.y - 5);
                      batch.draw(img, tp.x, tp.y);
                      batch.end();
                  }
                  

                  我建议阅读以下页面,其中详细描述了这一点及其背后的原因:

                  I would suggest to read the following pages, which describe this and the reasoning behind it in detail:

                  • https://github.com/libgdx/libgdx/wiki/Coordinate-systems
                  • https://xoppa.github.io/blog/pixels/李>
                  • https://github.com/libgdx/libgdx/wiki/Viewports

                  这篇关于gdx.input.getY 被翻转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:矩形内的 libgdx 动画 - 碰撞检测 - 矩形 下一篇:Libgdx 视锥体剔除在 actor.draw() 中

                  相关文章

                  最新文章

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

                    <bdo id='4vM2j'></bdo><ul id='4vM2j'></ul>

                    <legend id='4vM2j'><style id='4vM2j'><dir id='4vM2j'><q id='4vM2j'></q></dir></style></legend><tfoot id='4vM2j'></tfoot>

                    <small id='4vM2j'></small><noframes id='4vM2j'>