Render.get_window_width() vs. GUI width

I want to set a GUI node to the real screen width. render.get_window_width() returns 1080 on my Android test device, which is much wider that the GUI.

When testing locally by changing the window size it works fine.

How can I get a window size that I can use in a GUI on device?

Are you saying that render.get_window_width() returns the wrong value? What is the value you have in game.project, what value does the function return, and what is the actual width?

1 Like

Well, render.get_window_width() returns a value that doesn’t seem to match the GUI.

I have set the game project width to 414. The function returns width 1080 on device. Not sure about the actual width, is there a way to get the actual width of a GUI?

I thought this might be relevant, but can’t get it to work:

ps. I am actually using Orthographic camera.get_window_size(), which in turn uses render.get_window_width(). That shouldn’t matter, right?

The thing that confuses me about this is that it works exactly as it should locally, but it doesn’t work on device.

No, not really. You can get the size of individual nodes, but that can change based on adjust mode.

No, that shouldn’t matter.

The html template will resize the canvas so that it fills out the entire screen width while maintaining aspect ratio. 1080 sounds like a screen width that you could encounter on a device. Which device are you testing on?

It’s a OnePlus 6T and a native Android app. I know I’ve been hanging on about the Facebook Instant HTML5 game, but this is a separate project. :slight_smile:

I created a minimal version of the project, and I’m getting nowhere. I’ll post it here as a sign of defeat, for now: StretchNodeToScreenWidth.zip (227.8 KB)

The 6T has a resolution of 1080 x 2280. So, render.get_window_width() is correct. And window.set_listener() should fire when orientation changes, but you will not be able to use it on app start to detect screen size. render.get_window_width() is the way to get the size on app start.

Yes, I figured that was the case. I’ve yet to figure out how to translate this figure to be usable with the GUI, though.

Actually, that’s not entirely true - if I set the GUI’s “Adjust Reference” to “Disabled” the size correlates to the GUI. With the huge drawback of having to code all the alignment manually. It may be that I can redesign the game input mechanics themselves, to avoid this problem!

I guess I’d have to modify the render script for this? I was hoping to use Orthographic, a tool I adore. :slight_smile:

If you set all three nodes to stretch you’ll at least get something that stretches as you’d expect:



That’s clever! Is there any way to use the scale9, so the visual buttons are not deformed? That would solve it.

Sure, 9 slice is supported.

When I test, slice 9 objects are deformed, rather than retaining the corners nicely. How would I get them to stretch nicely when they’re stretched by Defold (rather than me setting the size manually)?



1 Like

I’ve added a feature request for this chestnut: Use scale 9 when GUI node's Adjust Mode is set to Stretch

3 Likes