Shows correct position, but node ends up at different position
I'm trying to make a card game using Godot 3.2. I have a "tabletop" scene, which has a ColorRect as its root node, and a bunch of MarginContainers, VBoxContainers and HBoxContainers as children holding my UI elements. I've instanced this scene on top of a CanvasLayer in my "main" scene (Node2D), and I'm having my cards (Area2D's) instance on top of that as they are drawn one after the other.
To set the positions of the spawned cards, I'm using
$node.rect_position on the control nodes, and when I draw the cards this is working just fine. Here is an example:
drawncard.position = $gui/CanvasLayer/tabletop/.../MarginContainer.rect_position drawncard.position += $gui/CanvasLayer/tabletop/.../MarginContainer/TextureRect.rect_position drawncard.position += Vector2($gui/CanvasLayer/tabletop/.../MarginContainer/TextureRect.rect_size.x/2, $gui/CanvasLayer/tabletop/.../MarginContainer/TextureRect.rect_size.y/2)
This spawns my card right in the center of my play area (TextureRect), which is exactly where I want it.
When a certain condition arises, I want a pair of cards from the main node to be reparented to another node (TextureRect), and moved to the center of the new node. I'm using signals, remove_child(), add_child() and the exact same code above, but pointing to a different node. Here is where the problem arises. When I run the code, I get the following:
screen_size = OS.get_window_size()correctly returns 750x1334 px, which is my target resolution,
drawncard.positioncorrectly returns (0, 507) px, which is where I want it moved,
- but the card is at a completely different position, looks to be around (0, 1050)px, too far towards the bottom of the game window.
WHY IS THIS HAPPENING? I'm getting the same results on an iPhone 8 running iOS 13.5, built using Xcode 11.5. Debugger prints out (0, 507), but that definitely is not where the card's at.
Further more, if I set
card.position = OS.get_window_size(), it does NOT end up at the right bottom corner of the screen.
What am I doing wrong? I'm very new to Godot Engine and game development in general, so I would appreciate it if y'all could point me in the right direction. My guess is that using control nodes to set positions of non-control nodes is not the best practice.