小编use*_*129的帖子

LibGDX阶段坐标在窗口大小调整时更改

我已经看到很多关于LibGDX和屏幕/凸轮坐标的主题,还有一些关于窗口大小调整的主题,但我找不到解决我遇到的以下问题的方法.

在这个阶段制作基本舞台和基本演员时,比如说windowsize 480x320,一切都还可以.我可以点击我的演员,它会回应.但是当我调整窗口大小时,说600x320,一切看起来都正确,但我的clicklistener不再工作了.此外,舞台坐标被移动或搞砸了.

我使用以下代码:

stage.addListener(new InputListener() {
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {

        //determine if actor was hit
        System.out.println(stage.hit(x, y, true));
        return true;
    }
});
Run Code Online (Sandbox Code Playgroud)

另外,我正在调整舞台摄像机视口的大小以对应窗口:

    stage.getCamera().viewportWidth = Gdx.graphics.getWidth();
    stage.getCamera().viewportHeight = Gdx.graphics.getHeight();
Run Code Online (Sandbox Code Playgroud)

因此,在调整大小时,我会在屏幕上获得所需的效果,但是我的听众没有回应 - 演员似乎对我点击的位置有"偏移".我究竟做错了什么?我应该根据调整大小移动我的演员或我的摄像头,还是缩放我的摄像头?有人可以向我解释一下吗?

非常感谢提前!

编辑:下面是我班级的完整代码.

public class HelpMePlease implements ApplicationListener{

// A standard simple Actor Class
class CustomActor extends Actor {

    Texture texture = new Texture(Gdx.files.internal("data/testTex2.png"));
    TextureRegion pixelTexture = new TextureRegion(texture, 0, 0, 1, 1);
    Sprite sprite = new …
Run Code Online (Sandbox Code Playgroud)

resize window stage coordinates libgdx

3
推荐指数
1
解决办法
7091
查看次数

标签 统计

coordinates ×1

libgdx ×1

resize ×1

stage ×1

window ×1