简体   繁体   English

Phaser 3 - 如何在 HEIGHT_CONTROLS_WIDTH 上获得实际屏幕尺寸?

[英]Phaser 3 - How to get actual screen size on HEIGHT_CONTROLS_WIDTH?

I'm making a game primarily targeted to mobile devices on Phaser 3 using scale mode HEIGHT_CONTROLS_WIDTH .我正在使用缩放模式HEIGHT_CONTROLS_WIDTH制作主要针对 Phaser 3 上的移动设备的游戏。
With fixed height, I can just make the game on 3:4 aspect ratio and make it centered so it will automatically crop the sides for tall devices.在固定高度的情况下,我可以以 3:4 的纵横比制作游戏并使其居中,这样它就会自动裁剪高设备的侧面。

I'm following this example.我正在关注这个例子。

However, now I have a problem: I can't get the actual visible screen size.但是,现在我遇到了一个问题:我无法获得实际的可见屏幕尺寸。
I have UI buttons located at the top left and top right of the game.我的 UI 按钮位于游戏的左上角和右上角。
But with the game cropped for tall devices, they're not visible on those devices.但是随着游戏为高设备裁剪,它们在这些设备上是不可见的。
I need to be able to get the visible screen size to anchor them on the correct position.我需要能够获得可见的屏幕尺寸以将它们锚定在正确的位置。

I have tried this.cameras.main.width , window.innerWidth , window.outerWidth , and many more but nothing works.我试过this.cameras.main.widthwindow.innerWidthwindow.outerWidth等等,但没有任何效果。
Is there any way for me to get the actual visible screen size after getting cropped?有什么方法可以让我在裁剪后获得实际的可见屏幕尺寸?

Try this:尝试这个:

this.canvas.getBoundingClientRect();

It should give you the info you need about your canvas.它应该为您提供有关画布所需的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM