korlibs / docs.korge.org

MIT License
1 stars 1 forks source link

Get actual screen size #40

Open codetreras opened 4 years ago

codetreras commented 4 years ago

I'm not sure if this is an actual issue, but I want to create a Game Window that matches my actual Android screen size. I haven't been able to retrieve the actual size in pixels of my screen.

soywiz commented 4 years ago

I could add it, though normally you don't do it. The typical way is to define a virtual size for your application. For example 720x1280. Then there is an "extended"/"actual" virtual rect: https://github.com/korlibs/korge/blob/ff21596f9bbd69dc3eae15c1a843f2719a3da695/korge/src/commonMain/kotlin/com/soywiz/korge/view/Views.kt#L64

Then you can disable clipBorders: https://github.com/korlibs/korge/blob/ff21596f9bbd69dc3eae15c1a843f2719a3da695/korge/src/commonMain/kotlin/com/soywiz/korge/view/Views.kt#L100

The minesweeper sample shows how to adapt to a slightly different aspect ratio with a 800x600 virtual size: https://github.com/korlibs/korge-samples/blob/3ced591e97950b3521fdb669e0a0afc82462ae42/sample-minesweeper/src/commonMain/kotlin/com/soywiz/korge/samples/minesweeper/main.kt#L15

scaleMode = ScaleMode.SHOW_ALL,
clipBorders = false

Then uses dockedTo: https://github.com/korlibs/korge-samples/blob/3ced591e97950b3521fdb669e0a0afc82462ae42/sample-minesweeper/src/commonMain/kotlin/com/soywiz/korge/samples/minesweeper/main.kt#L27 to attach some views to specific corners of the screen

codetreras commented 4 years ago

Btw, what does clipborder does?

soywiz commented 4 years ago

It is enabled by default, and what it does is to create a rectangle clip that effectively doesn't paint to those "borders" that get a background color paint when the window/screen aspect ratio doesn't match the virtual size.

The hello world defines a virtual size of 512x512. This is a aspect ratio of 1:1: https://korge.soywiz.com/samples/korge-hello-world/index.html

So when the width is larger than the height, there are borders to the left and the right, and for the opposite, the borders are at the top and the bottom. Those borders are the grey area that doesn't include the korge logo.