The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

When i launch my game on my PC ('play the project'), get_viewport().get_rect().size returns (1280,720), and so to make a sprite be at the bottom of my "window" i just do

pos.y = get_viewport().get_rect().size.height - 50

where 50 is my sprite height

Well on my PC everything works as expected, but on my android device where the "window" size is (1920, 1080), doing the same trick to position my sprite at the bottom, it looks like the sprite is out of bounds

So i need to write

pos.y = get_viewport().get_rect().size.height - 410

In project settings > Display i got stretch_aspect = keep_height and stretch_mode = 2d

And i don't understand cause my sprite should be at the bottom !
I come from cocos2d where everything fit well everywhere, and i'm kind of lost in Godot ^^
So do you guys know how to resolve my this ?
Thanks !

in Engine by (30 points)

I'm not sure if understand the problem but if place your sprite on the screen, Godot will correct positions with the stretch options, for common things you don't need to deal with viewport.

For more complex stuff (like things that need to be drawn near the border on any resolution) you will need to get the scale of the viewport instead of a simple hardcoded number and scale all your values.

Yeah, i noticied that, but, well, it's just an habit to position with code :p !
Anyway, i did not thought i will have to deal with ratios and that kind of stuff, thanks for clearing my mind :)

Another option is to use Controls, these have anchors that are useful to keep an element in a position relative to part of the screen.

1 Answer

0 votes

If your GDScript is on the sprite node, try to use

"pos.y = getviewport().getrect().size.height -

I'm on my phone, but I think this will work!

by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.