How to automatically detect screen size in Android using playn?

I recently noticed that layers can be changed as 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 the screen size of a device from playn?

And is there another way to adjust the size of the game on Android devices depending on the screen size using playn?

+4
source share
3 answers

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

Copied from 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 painted surface in pixels.
  • height () - Gets the height of the drawn surface in pixels.

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

+4
source

PlayN.graphics().width() and PlayN.graphics().height() give the desired image size (via PlayN.graphics().setSize() ) rather than the maximum available screen size.

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

+1
source

Have you tried this?

This gives you an accessible visualization surface of the device.

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

Or did I miss your problem?

0
source

Source: https://habr.com/ru/post/1396054/


All Articles