Java 屏幕分辨率更改

发布于 2025-01-04 18:06:24 字数 535 浏览 1 评论 0原文

我正在关注 Youtube 上 thenewboston 提供的一系列关于 Java 游戏开发的教程。我现在可以制作全屏窗口,但分辨率拒绝调整为 800x600。我已经测试了 vc(一个 GraphicsEnvironment.getDefaultScreenDevice 对象)和 dm(一个 DisplayMode),它们似乎不是问题。我正在运行雪豹。有什么想法吗?

if(dm != null && vc.isDisplayChangeSupported()){
        try{
            vc.setDisplayMode(dm);
            System.out.println("Display mode set");
        }catch(Exception ex){System.out.println("Despite the vc saying it is display change supported and the DM is not null, something went wrong");}

    }
}

I am following a series of tutorials on game development in Java by thenewboston on Youtube. I am at the point where I can make a fullscreen window, but the resolution refuses to resize to 800x600. I have tested vc, a GraphicsEnvironment.getDefaultScreenDevice object, and dm, a DisplayMode, and they don't seem to be the problem. I am running Snow Leopard. Any ideas?

if(dm != null && vc.isDisplayChangeSupported()){
        try{
            vc.setDisplayMode(dm);
            System.out.println("Display mode set");
        }catch(Exception ex){System.out.println("Despite the vc saying it is display change supported and the DM is not null, something went wrong");}

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笔绘流年 2025-01-11 18:06:24

将此代码添加到您的 Core.java(或 GameClient.java)类中。问题可能是您没有将所需的 DM[] 参数传递给 ScreenManager.java 类。

private static final DisplayMode modes[] = { //common monitor DMs 
    new DisplayMode(1366,768,32, DisplayMode.REFRESH_RATE_UNKNOWN), //1366x768px w/32-bit depth
    new DisplayMode(1366,768,24, DisplayMode.REFRESH_RATE_UNKNOWN), //    '      w/24-bit depth
    new DisplayMode(1366,768,16, DisplayMode.REFRESH_RATE_UNKNOWN), //    '      w/16-bit depth     
    new DisplayMode(800,600,32, DisplayMode.REFRESH_RATE_UNKNOWN),  //800x600px  w/32-bit depth
    new DisplayMode(800,600,24, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/24-bit depth
    new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/16-bit depth 
    new DisplayMode(640,480,32, DisplayMode.REFRESH_RATE_UNKNOWN),  //640x480px  w/32-bit depth
    new DisplayMode(640,480,24, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/24-bit depth
    new DisplayMode(640,480,16, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/16-bit depth
};

我假设错误与您的 public void setFullScreen(DisplayMode dm) 方法有关。在这种情况下,此方法的完整语法是:

/*****************************************************************************
 * @description: Creates window for program to run in, using appropriate DM
 * @param DisplayMode dm 
 */
    public void setFullScreen(DisplayMode dm){
        JFrame f = new JFrame();
        f.setUndecorated(true); //no titlebars/scroll bars etc.
        f.setIgnoreRepaint(true);
        f.setResizable(false); //user cannot resize window
        vc.setFullScreenWindow(f);

        if(dm!=null && vc.isDisplayChangeSupported()){ //if DM is changeable
            try {
                vc.setDisplayMode(dm);
            } catch (Exception e){/*Catch 'em all*/}
        }
        f.createBufferStrategy(2); //set # of screen buffers to 2
    }//setFullScreen()

注意这是发布后的温和死灵帖子。啊啊啊……

Add this code to your Core.java (or GameClient.java) class. The issue may be that you are not passing the required DM[] args to your ScreenManager.java class.

private static final DisplayMode modes[] = { //common monitor DMs 
    new DisplayMode(1366,768,32, DisplayMode.REFRESH_RATE_UNKNOWN), //1366x768px w/32-bit depth
    new DisplayMode(1366,768,24, DisplayMode.REFRESH_RATE_UNKNOWN), //    '      w/24-bit depth
    new DisplayMode(1366,768,16, DisplayMode.REFRESH_RATE_UNKNOWN), //    '      w/16-bit depth     
    new DisplayMode(800,600,32, DisplayMode.REFRESH_RATE_UNKNOWN),  //800x600px  w/32-bit depth
    new DisplayMode(800,600,24, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/24-bit depth
    new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/16-bit depth 
    new DisplayMode(640,480,32, DisplayMode.REFRESH_RATE_UNKNOWN),  //640x480px  w/32-bit depth
    new DisplayMode(640,480,24, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/24-bit depth
    new DisplayMode(640,480,16, DisplayMode.REFRESH_RATE_UNKNOWN),  //    '      w/16-bit depth
};

I'm assuming that the error is with your public void setFullScreen(DisplayMode dm) method. In that case, the full syntax for this method is:

/*****************************************************************************
 * @description: Creates window for program to run in, using appropriate DM
 * @param DisplayMode dm 
 */
    public void setFullScreen(DisplayMode dm){
        JFrame f = new JFrame();
        f.setUndecorated(true); //no titlebars/scroll bars etc.
        f.setIgnoreRepaint(true);
        f.setResizable(false); //user cannot resize window
        vc.setFullScreenWindow(f);

        if(dm!=null && vc.isDisplayChangeSupported()){ //if DM is changeable
            try {
                vc.setDisplayMode(dm);
            } catch (Exception e){/*Catch 'em all*/}
        }
        f.createBufferStrategy(2); //set # of screen buffers to 2
    }//setFullScreen()

Noticed this was a mild necro-post after posting. Aaahh...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文