Godot Version
4.3
Question
I am making an endless top down mobile game. Bottom of the screen, there will be buttons(in canvas layer → margin container etc) which will be scaled depending on mobile size. So what i want is, anything (node2ds) above that buttons should be repositioned just above it like i see in editor. That anything should end where the canvas layer begin. How do i achieve that? Because currently, if i increase height, canvas layer is where it should be but node2ds are much close to middle than bottom buttons canvas layer. They “are” not just top each other. Shortly, i want my nodes to anchored to canvas layer regardless of height of the phone (strecth is keep_width)
Only control nodes have built-in anchoring. If you want other nodes to have something similar, you will either need to move the nodes or the camera in code to suit the size of the game window.
Move the nodes? Should i change their y position in script?
Something like that?
var ground_y:float = ground_text_rect.global_position.y
player.global_position.y = ground_y - 73
also i didnt understand camera method, can you explain?
yes, something like that for moving the nodes. for the camera, you need to add a Camera2D
node to the scene if you do not have one already, and change its position property as well.
Hmm so if i add camera and change its position only, it should be enough rite? Since camera only tends to work with nodes, not canvas layers right? Isn’t camera way way more efficient or easier? What about independant collision shapes? will they move as with camera?
yes, it better to move the camera. when you move the camera, only what you see moves, not the nodes themselves, so you don’t have to worry about moving collision shapes