Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | justin |
I have the following UI with playing cards being dealt as shown by the red arrow:
Cards dealt out of screen bounds
I’m trying to make them be dealt relative to the “Deal” button towards the center of the screen. So I have something like this on button click:
deck.add_child(card)
var pos1 = deal_btn.rect_position + Vector2(-200, 0)
print_debug(deal_btn.rect_position)
print_debug(pos1)
print_debug(deck.rect_position)
tween.interpolate_property(card, "rect_position",
card.rect_position, pos1, 0.5,
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()
The deck (which is the green square), is giving me a position of (0,0)
, whereas the deal_btn
is giving me a reasonable value of 819.200012, 512
and pos1
is being calculated relative to it at (619.200012, 512)
.
The problem seems to be with deck
being at (0,0)
. card
is added as it’s child and is also at (0,0)
… so I’m animating from (0,0)
to (619.200012, 512)
- off screen!
deck
is a child of a control node… maybe that’s the reason? (as child nodes of control nodes don’t get to decide their position). See same link above - 2nd image for scene tree.
How can I get the “absolute” position of the deck in the screen (not relative to where the control node decides to put deck)? I assume I can then use this to do some vector math and get the right position.
(Added screenshot of Deck’s parent’s anchors).