• <bdo id='imgvD'></bdo><ul id='imgvD'></ul>
    <tfoot id='imgvD'></tfoot>

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

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

      <legend id='imgvD'><style id='imgvD'><dir id='imgvD'><q id='imgvD'></q></dir></style></legend>
    1. 渲染和触摸输入之间的 libgdx 坐标系差异

      时间:2023-05-18

        <tbody id='8m0Ak'></tbody>
    2. <tfoot id='8m0Ak'></tfoot>
        <bdo id='8m0Ak'></bdo><ul id='8m0Ak'></ul>
      • <small id='8m0Ak'></small><noframes id='8m0Ak'>

        <legend id='8m0Ak'><style id='8m0Ak'><dir id='8m0Ak'><q id='8m0Ak'></q></dir></style></legend>

            • <i id='8m0Ak'><tr id='8m0Ak'><dt id='8m0Ak'><q id='8m0Ak'><span id='8m0Ak'><b id='8m0Ak'><form id='8m0Ak'><ins id='8m0Ak'></ins><ul id='8m0Ak'></ul><sub id='8m0Ak'></sub></form><legend id='8m0Ak'></legend><bdo id='8m0Ak'><pre id='8m0Ak'><center id='8m0Ak'></center></pre></bdo></b><th id='8m0Ak'></th></span></q></dt></tr></i><div id='8m0Ak'><tfoot id='8m0Ak'></tfoot><dl id='8m0Ak'><fieldset id='8m0Ak'></fieldset></dl></div>
                本文介绍了渲染和触摸输入之间的 libgdx 坐标系差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有一个渲染 PNG 图像的屏幕(BaseScreen 实现 Screen 接口).单击屏幕时,它会将角色移动到触摸的位置(用于测试目的).

                I have a screen (BaseScreen implements the Screen interface) that renders a PNG image. On click of the screen, it moves the character to the position touched (for testing purposes).

                public class DrawingSpriteScreen extends BaseScreen {
                    private Texture _sourceTexture = null;
                    float x = 0, y = 0;
                
                    @Override
                    public void create() {
                        _sourceTexture = new Texture(Gdx.files.internal("data/character.png"));
                    }
                
                    .
                    .
                }
                

                在屏幕渲染过程中,如果用户触摸屏幕,我会抓取触摸的坐标,然后用这些坐标来渲染角色图像.

                During rendering of the screen, if the user touched the screen, I grab the coordinates of the touch, and then use these to render the character image.

                @Override
                public void render(float delta) {
                    if (Gdx.input.justTouched()) {
                        x = Gdx.input.getX();
                        y = Gdx.input.getY();
                    }
                
                    super.getGame().batch.draw(_sourceTexture, x, y);
                }
                

                问题是绘制图像的坐标从左下角开始(如 LibGDX Wiki 中所述),而触摸输入的坐标从左上角开始.所以我遇到的问题是我点击右下角,它将图像移动到右上角.我的坐标可能是 X 675 Y 13,触摸时它会在屏幕顶部附近.但是字符显示在底部,因为坐标从左下角开始.

                The issue is the coordinates for drawing the image start from the bottom left position (as noted in the LibGDX Wiki) and the coordinates for the touch input starts from the upper left corner. So the issue I'm having is that I click on the bottom right, it moves the image to the top right. My coordinates may be X 675 Y 13, which on touch would be near the top of the screen. But the character shows at the bottom, since the coordinates start from the bottom left.

                为什么是什么?为什么坐标系颠倒了?我是否使用了错误的对象来确定这一点?

                Why is what? Why are the coordinate systems reversed? Am I using the wrong objects to determine this?

                推荐答案

                为了检测碰撞,我使用 camera.unproject(vector3).我将 vector3 设置为:

                To detect collision I use camera.unproject(vector3). I set vector3 as:

                x = Gdx.input.getX();     
                y = Gdx.input.getY();
                z=0;
                

                现在我在 camera.unproject(vector3) 中传递这个向量.使用这个向量的 xy 来绘制你的角色.

                Now I pass this vector in camera.unproject(vector3). Use x and y of this vector to draw your character.

                这篇关于渲染和触摸输入之间的 libgdx 坐标系差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:获取 LIBGDX 中的光标位置 下一篇:为什么我在使用 Tiled 的 libgdx 游戏中出现线条?

                相关文章

                最新文章

                1. <small id='RZvyM'></small><noframes id='RZvyM'>

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

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

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

                    <tfoot id='RZvyM'></tfoot>