Window.get_size() not returning the actual size

Hi,
I set a window resolution in the game.project file of 1280x720
When I use window.get_size() it returns 2560x1440
If I resize the window the returned value changes so it’s not always returning 2560x1440
Any idea why it’s not returning the actual window size though?

Thanks.

window.get_size() - This returns the current window size (width and height).

So when you resize your window it will change the width and height of the window to different dimensions depending on how you resized your window. You can resize the game window with both html5 and desktop applications but may get different initial results depending on what you are building for.

For html5 it will generally give the viewport of the browser which is usually set as full screen of the users monitor.

When building the desktop application it is set more closely to the display settings in the game project settings because you have more control with a desktop application versus web development in how it is displayed to the end user.

1 Like

Since it is twice as large, my guess is that you are using a highdpi/retina screen? Which OS are you using?

1 Like

I’m using mac so I guess it’s my monitor that’s the problem. Is there a way to avoid/fix this within defold so it gets the right resolution no matter which OS I’m on?

Yes, you can use the DefOS extension to query the scaling_factor of the display and then simply multiple the width and height you get. It’s a workaround at least.

1 Like

I’ll look into that thank you.