can't make my sprite be on the bottom

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Alexande Daubricourt
:warning: Old Version Published before Godot 3 was released.

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 !

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.

eons | 2017-06-11 23:36

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

Alexande Daubricourt | 2017-06-12 01:19

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.

eons | 2017-06-12 05:54

:bust_in_silhouette: Reply From: hissapower

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

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

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