LibGdx参与者边界不正确

LibGdx参与者边界不正确,libgdx,Libgdx,我正在开发一个简单的游戏,遇到了一个问题。我的虚拟屏幕大小是640x360,但如果我在设备上启动游戏时屏幕分辨率为1920x1080,那么演员的边界将保留在我的虚拟世界坐标中,而不是1920x1080,因此我无法检测到任何输入。有人能帮我吗 private Stage stage; private Preferences SoundPrefs; private Texture TitleTexture, PlayTexture, BallsTexture, RatingsTexture, S

我正在开发一个简单的游戏,遇到了一个问题。我的虚拟屏幕大小是640x360,但如果我在设备上启动游戏时屏幕分辨率为1920x1080,那么演员的边界将保留在我的虚拟世界坐标中,而不是1920x1080,因此我无法检测到任何输入。有人能帮我吗

private Stage stage;

private Preferences SoundPrefs;

private Texture TitleTexture, PlayTexture, BallsTexture, RatingsTexture, ShopTexture, NoadsTexture, SoundOnTexture, SoundOffTexture;

private MenuTextureActor Title, Play, Balls, Ratings, Shop, Noads, Sound;

public MenuScreen(MainGame gam) {
    super(gam);
    stage = new Stage(new FitViewport(640, 360));
    SoundPrefs = Gdx.app.getPreferences("Sound");
    Gdx.input.setInputProcessor(new InputProcessor() {
        @Override
        public boolean keyDown(int keycode) {
            return false;
        }

        @Override
        public boolean keyUp(int keycode) {
            return false;
        }

        @Override
        public boolean keyTyped(char character) {
            return false;
        }

        @Override
        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (screenX >= Play.getX() && screenY >= Play.getY() && screenX <= (Play.getX() + Play.getWidth())
                    && screenY <= (Play.getY() + Play.getHeight())) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                game.setScreen(new PlayScreen(game));
            }
            if (screenX >= Sound.getX() && screenY >= Sound.getY() && screenX <= (Sound.getX() + Sound.getWidth())
                    && screenY <= (Sound.getY() + Sound.getHeight())){
                if (SoundPrefs.getBoolean("Sound", true) == true){
                    SoundPrefs.putBoolean("Sound", false);
                    Sound.ChangeTexture(SoundOffTexture);
                } else if (SoundPrefs.getBoolean("Sound", true) == false) {
                    SoundPrefs.putBoolean("Sound", true);
                    Sound.ChangeTexture(SoundOnTexture);
                }
                SoundPrefs.flush();
            }
            return false;
        }

        @Override
        public boolean touchUp(int screenX, int screenY, int pointer, int button) {
            return false;
        }

        @Override
        public boolean touchDragged(int screenX, int screenY, int pointer) {
            return false;
        }

        @Override
        public boolean mouseMoved(int screenX, int screenY) {
            return false;
        }

        @Override
        public boolean scrolled(int amount) {
            return false;
        }
    });
}

@Override
public void show() {
    TitleTexture = game.getManager().get("title.png");
    TitleTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    PlayTexture = game.getManager().get("play.png");
    PlayTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    BallsTexture = game.getManager().get("balls.png");
    BallsTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    RatingsTexture = game.getManager().get("ratings.png");
    RatingsTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    ShopTexture = game.getManager().get("shop.png");
    ShopTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    NoadsTexture = game.getManager().get("noads.png");
    NoadsTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    SoundOnTexture = game.getManager().get("sound_on.png");
    SoundOnTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    SoundOffTexture = game.getManager().get("sound_off.png");
    SoundOffTexture.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
    Title = new MenuTextureActor(TitleTexture, 170, 270, 300, 70);
    Play = new MenuTextureActor(PlayTexture, 255, 150, 130, 120);
    Balls = new MenuTextureActor(BallsTexture, 105, 40, 70, 70);
    Ratings = new MenuTextureActor(RatingsTexture, 195, 40, 70, 70);
    Shop = new MenuTextureActor(ShopTexture, 285, 40, 70, 70);
    Noads = new MenuTextureActor(NoadsTexture, 375, 40, 70, 70);
    Sound = new MenuTextureActor(SoundOnTexture, 465, 40, 70, 70);
    if (SoundPrefs.getBoolean("Sound", true) == false) {
        Sound.ChangeTexture(SoundOffTexture);
    }
    stage.addActor(Title);
    stage.addActor(Play);
    stage.addActor(Balls);
    stage.addActor(Ratings);
    stage.addActor(Shop);
    stage.addActor(Noads);
    stage.addActor(Sound);
}

@Override
public void resize(int width, int height) {
    stage.getViewport().update(width, height);
}

@Override
public void render(float delta) {
    Gdx.gl.glClearColor((float) (255 / 255.0), (float) (240 / 255.0), (float) (212 / 255.0), 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    if (Gdx.input.isTouched()) {

    }
    stage.draw();
}
私有阶段;
私人偏好;
私有纹理标题纹理、播放纹理、球纹理、分级纹理、商店纹理、无纹理、声音纹理、声音纹理;
私人菜单演员名称、剧本、舞会、收视率、商店、Noads、声音;
公共菜单屏幕(主游戏gam){
超级(gam);
阶段=新阶段(新阶段(640360));
SoundPrefs=Gdx.app.getPreferences(“声音”);
setInputProcessor(新的InputProcessor(){
@凌驾
公共布尔键关闭(int-keycode){
返回false;
}
@凌驾
公共布尔键控(int-keycode){
返回false;
}
@凌驾
公共布尔键类型(字符字符){
返回false;
}
@凌驾
公共布尔接地(整数屏幕X、整数屏幕Y、整数指针、整数按钮){

如果(screenX>=Play.getX()&&screenY>=Play.getY()&&screenX=Sound.getY()&&screenX这是与视口相关的常见问题。对于处理多个移动屏幕,您必须使用视口。此问题的答案已在下面的链接中完成,请检查一次。它将帮助您维护所有设备的常量屏幕比率

   http://stackoverflow.com/questions/39718125/java-libgdx-keep-actors-position-even-screens-resolution-changes/39946985#39946985

请检查一次。这可能会对您有所帮助。谢谢您这是与视口相关的常见问题。对于处理多个移动屏幕,您必须使用视口。此问题的答案已准备就绪,请在下面的链接中检查一次。它将帮助您维护所有设备的常量屏幕比率

   http://stackoverflow.com/questions/39718125/java-libgdx-keep-actors-position-even-screens-resolution-changes/39946985#39946985

请检查一下。它可能会对您有所帮助。谢谢您

使用
viewport.unproject()将屏幕(输入)坐标转换为世界坐标
。当用户按下播放按钮时,你为什么要休眠线程?谢谢!这对我很有帮助!但是我如何才能获得世界坐标中的宽度和高度?宽度和高度不是坐标。你的演员的宽度和高度已经是世界单位。将输入的screenX和screenY转换为世界坐标,然后你可以直接进行比较根据演员的位置和大小。谢谢!这对我帮助很大!使用
viewport.unproject()将屏幕(输入)坐标转换为世界坐标
。当用户按下播放按钮时,你为什么要休眠线程?谢谢!这对我很有帮助!但是我如何才能获得世界坐标中的宽度和高度?宽度和高度不是坐标。你的演员的宽度和高度已经是世界单位。将输入的screenX和screenY转换为世界坐标,然后你可以直接进行比较你的演员的位置和体型。谢谢!这对我帮助很大!