Window.get_size does not get actual width on iOS

Here’s the code on the player, the only other code I’m running is a fixed_fit_projection message in a separate script:

function init(self)
	local wwidth, wheight = window.get_size()
	local p = go.get_position()
	go.set_position(vmath.vector3(wwidth / 2, p.y, p.z))
end

This is what the game looks like in a local window:

This is what the game looks like on my iPhone:

Is there something I’m missing?

What’s the iPhone model? Is high dpi enabled?

This is an iPhone XR. It seems to produce this result regardless of whether High Dpi is enabled or not.

Could you post a screenshot of how this game looks? It’s using RenderCam for render script.

This is what the main menu looks like, seems to work fine.

Does this mean I should be using Rendercam? I was planning on using Orthographic Camera later.

If you are not planning to use any 3d effects you don’t need RenderCam. Orthographic is a good option. You should test it to make sure it’s working how you would expect though.

It is also very worth figuring out what’s wrong in the original post of this thread.

Should do some tests with window.get_size() like to see if it reports anything differently on update vs init on your device.

The version of fixed_fit_projection in builtins might also have issues in portrait orientation it should be checked.

it doesn’t work on android either, same issue

I did some testing, window.get_size gives the same result in both init and update. I have also tried Orthographic Camera’s get_window_size and get_display_size, but they depend too much on game.project settings and wouldn’t work for every screen size.

I found a solution to my specific problem though. Since I wanted to place the player in the center of the screen, I can use Orthographic Camera and keep the camera’s X position at 0. This means 0 is the center, and I can set an object’s X position to 0 whenever I want to center something. This continues to work on different screen sizes since the content stays centered.

3 Likes