OS.min_window_size 如何在 iOS 视网膜屏幕上工作

发布于 2025-01-10 02:10:17 字数 240 浏览 0 评论 0原文

我了解您可以在 gdscript 中设置最小和最大窗口大小,以适应您的应用程序在台式机或笔记本电脑上运行并且可调整大小的情况。即

OS.min_window_size = Vector2(500, 500)
OS.max_window_size = Vector2(6000, 4000)

这如何转化为具有视网膜屏幕的 iOS。最小和最大尺寸代表物理像素宽度还是逻辑像素宽度?该文档没有明确说明这一点:

I understand you can set a minimum and maximum window size in gdscript, for the situation when your application is running on a desktop or laptop and is resizable. i.e.

OS.min_window_size = Vector2(500, 500)
OS.max_window_size = Vector2(6000, 4000)

How does this translate into iOS with retina screens. Does the minimum and maximum size represent the physical pixel width, or the logical pixel width? The documentation doesn't make this clear:

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

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

发布评论

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

评论(1

只是我以为 2025-01-17 02:10:17

首先,项目设置中有一个名为“允许 Hidpi”的选项,您应该启用该选项才能使用操作系统缩放。 它并不会真正引起问题,但由于向后兼容性,它在 Godot 3.x 中默认被禁用。

现在,您可以查询 OS.get_screen_dpi(), OS.get_screen_scale()OS.get_screen_max_scale() 以了解游戏当前的缩放比例。

而且,你是对的,文档没有指定 min_window_sizemax_window_size 是在缩放之前还是之后......

答案:我确信min_window_sizemax_window_size 是缩放后的结果(在任何缩放下,而不是在当前缩放下)。如果我理解正确的话,这是物理像素。


找出答案

从现在开始,这个答案就是找出我上面所说的内容。

现在,我相信在 iOS 中 Godot 将始终处于全屏模式。在这种情况下,min_window_sizemax_window_size 将被忽略。

因此,与 iOS 不同的是,这是 OSX 的 set_max_window_size (来源):

void OS_OSX::set_max_window_size(const Size2 p_size) {
    if (is_no_window_mode_enabled()) {
        return;
    }

    if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
        ERR_PRINT("Maximum window size can't be smaller than minimum window size!");
        return;
    }
    max_size = p_size;

    if ((max_size != Size2()) && !zoomed) {
        Size2 size = max_size / get_screen_max_scale();
        [window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
    } else {
        [window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
    }
}

那么,让我们看看......

  • 全屏时它会被忽略。
  • 最大尺寸必须大于或等于最小尺寸。

到目前为止,一切都很好。

然后我们就有了这个zoomed字段。据我所知,它在全屏上设置为 true,否则设置为 false。

因此,这就是我们正在寻找的逻辑:

Size2 size = max_size / get_screen_max_scale();
[window_object setContentMaxSize:NSMakeSize(size.x, size.y)];

它是这样的(伪代码):OS_max_size = max_size / max_scaling


好的,现在我想看看 setContentMaxSize

窗口基本坐标系中窗口内容视图的最大尺寸。

First of all, there is an option in Project Setting called "Allow Hidpi" which you should enable to use OS scaling. It does not really cause problems, but it is disabled by default in Godot 3.x because of backwards compatibility.

Now, you can query OS.get_screen_dpi(), OS.get_screen_scale() and OS.get_screen_max_scale() to find out about the scaling the game is currently at.

And, you are correct, the documentation does not specify if min_window_size and max_window_size are before or after that scaling…

The answer: I'm convinced that min_window_size and max_window_size are after scaling (at any scaling, not at the current scaling). Which - if I understand correctly - is physical pixels.


The figuring out of the answer

From here on, this answer is figuring out what I claim above.

Now, I believe that in iOS Godot will always be in full screen mode. In which case min_window_size and max_window_size are ignored.

So, instead of looking at iOS, this is set_max_window_size for OSX (source):

void OS_OSX::set_max_window_size(const Size2 p_size) {
    if (is_no_window_mode_enabled()) {
        return;
    }

    if ((p_size != Size2()) && ((p_size.x < min_size.x) || (p_size.y < min_size.y))) {
        ERR_PRINT("Maximum window size can't be smaller than minimum window size!");
        return;
    }
    max_size = p_size;

    if ((max_size != Size2()) && !zoomed) {
        Size2 size = max_size / get_screen_max_scale();
        [window_object setContentMaxSize:NSMakeSize(size.x, size.y)];
    } else {
        [window_object setContentMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
    }
}

So, let us see…

  • It is ignored in full screen.
  • The max size must be greater or equal to the min size.

So far so good.

Then we have this zoomed field. As far as I can tell it is set to true on full screen, and false otherwise.

Thus, this is the logic we are looking for:

Size2 size = max_size / get_screen_max_scale();
[window_object setContentMaxSize:NSMakeSize(size.x, size.y)];

It is something like this (pseudo code): OS_max_size = max_size / max_scaling.


Ok, now I want to see setContentMaxSize:

The maximum size of the window’s content view in the window’s base coordinate system.

????


Ok, there are four possibilities:

  1. setContentMaxSize sets the maximum size in pixels before scaling. And max_window_size is the maximum size in pixels before scaling.

    If this was the case, we would set it directly. So, this isn't the case.

  2. setContentMaxSize sets the maximum size in pixels before scaling. And max_window_size is the maximum size in pixels after scaling.

    If this was the case, we would have to divide max_window_size by the scaling. So, this could be it.

  3. setContentMaxSize sets the maximum size in pixels after scaling. And max_window_size is the maximum size in pixels before scaling.

    If this was the case, we would have to multiply max_window_size by the scaling. So, I don't this is the case.

  4. setContentMaxSize sets the maximum size in pixels after scaling. And max_window_size is the maximum size in pixels after scaling.

    If this was the case, we would set it directly. So, this isn't the case.

Therefore, unless this is a bug, max_window_size is the size in pixels after scaling. And that is the maximum size in pixels at any scaling instead of the current one since it uses get_screen_max_scale() instead of get_screen_scale(). And min_window_size would work the same way.
*

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