如何使用playn在Android中自动检测屏幕尺寸?

发布于 01-05 04:16 字数 145 浏览 4 评论 0原文

我最近注意到图层可以在需要时调整大小,因此我尝试实现一种方法来将主图层的大小调整为运行时的 Android 屏幕的大小。

如何从 playn 中获取设备屏幕尺寸?

还有另一种方法可以根据所玩屏幕的大小来调整 Android 设备中游戏的大小吗?

I have recently noticed that layers can be resized when needed, so I'm trying to implement a method to resize the main layer to the size of the android screen where it is running.

How do I access to the device screen size from playn?

And there is another way to adjust the size of the game in android devices depending on the size of the screen with playn?

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

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

发布评论

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

评论(3

淡淡的优雅2025-01-12 04:16:40

我相信您正在寻找的是 PlayN.graphics().screenHeight()PlayN.graphics().screenWidth()

从 Graphics.java 文件中复制:

  • screenWidth() - 获取可用屏幕空间的宽度(以像素为单位)。
  • screenHeight() - 获取可用屏幕空间的高度(以像素为单位)。
  • width() - 获取可绘制表面的宽度(以像素为单位)。
  • height() - 获取可绘制表面的高度(以像素为单位)。

正如描述所述, screenHeight() 和 screenWidth() 提供实际的屏幕高度/宽度。使用这些值,您可以调整游戏的大小或比例以适合屏幕。

I believe what you are looking for is PlayN.graphics().screenHeight() and PlayN.graphics().screenWidth().

Copied out of the Graphics.java file:

  • screenWidth() - Gets the width of the available screen real-estate, in pixels.
  • screenHeight() - Gets the height of the available screen real-estate, in pixels.
  • width() - Gets the width of the drawable surface, in pixels.
  • height() - Gets the height of the drawable surface, in pixels.

As the descriptions state, screenHeight() and screenWidth() provide the actual screen height/width. With these values, you can adjust the size or scale of your game to fit the screen.

叹梦2025-01-12 04:16:40

PlayN.graphics().width()PlayN.graphics().height() 为您提供您请求的视图大小(通过PlayN.graphics().setSize()),而不是最大可用屏幕尺寸。

要获取最大可用屏幕尺寸,请使用 PlayN.graphics().availableWidth()PlayN.graphics().availableHeight()

PlayN.graphics().width() and PlayN.graphics().height() give you the view size that you requested (via PlayN.graphics().setSize()), not the maximum available screen size.

To obtain the maximum available screen size, use PlayN.graphics().availableWidth() and PlayN.graphics().availableHeight().

梦纸2025-01-12 04:16:40

你试过这个吗?

这为您提供了可用的设备渲染表面。

PlayN.graphics().width()
PlayN.graphics().height()

还是我误解了你的问题?

Have you tried this?

This gives you the available device rendering surface.

PlayN.graphics().width()
PlayN.graphics().height()

Or I missunderstood your problem?

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