How to change position of new child

Godot Version



its as a said in the title how do i move the new child so they are not stacked on top of each other

here is my code

extends Node2D
#holds points
@export var player_points = 0
@export var dealers_points = 18

#stores the random card
var random_card

@onready var test = $test1
@onready var test2 = $test2

#adds sprite and card
@onready var sprite_2d = $Sprite2D
const CARD = preload(“res://scenes/card.tscn”)

#card deck
var Deck = {“CTwo”: [2, preload(“res://textures/2C.png”)], “CThree”: [3, preload(“res://textures/3C.png”)],
“CFour”: [4, preload(“res://textures/4C.png”)], “CFive”: [5, preload(“res://textures/5C.png”)],
“CSix”: [6, preload(“res://textures/6C.png”)], “CSeven”: [7, preload(“res://textures/7C.png”)],
“CEight”: [8, preload(“res://textures/8C.png”)],“CNine”: [9, preload(“res://textures/9C.png”)],
“CTen”: [10, preload(“res://textures/10C.png”)], “CJack”: [10, preload(“res://textures/JC.png”)],
“CQueen”: [10, preload(“res://textures/QC.png”)], “CKing”: [10, preload(“res://textures/KC.png”)],
“CAce”: [11, preload(“res://textures/AC.png”)], “STwo”: [2, preload(“res://textures/2S.png”)],
“SThree”: [3, preload(“res://textures/3S.png”)], “SFour”: [4, preload(“res://textures/4S.png”)],
“SFive”: [5, preload(“res://textures/5S.png”)], “SSix”: [6, preload(“res://textures/6S.png”)],
“SSeven”: [7, preload(“res://textures/7S.png”)], “SEight”: [8, preload(“res://textures/8S.png”)],
“SNine”: [9, preload(“res://textures/9S.png”)], “STen”: [10, preload(“res://textures/10S.png”)],
“SJack”: [10, preload(“res://textures/JS.png”)], “SQueen”: [10, preload(“res://textures/QS.png”)],
“SKing”: [10, preload(“res://textures/KS.png”)], “SAce”: [11, preload(“res://textures/AS.png”)],
“HTwo”: [2, preload(“res://textures/2H.png”)], “HThree”: [3, preload(“res://textures/3H.png”)],
“HFour”: [4, preload(“res://textures/4H.png”)], “HFive”: [5, preload(“res://textures/5H.png”)],
“HSix”: [6, preload(“res://textures/6H.png”)], “HSeven”: [7, preload(“res://textures/7H.png”)],
“HEight”: [8, preload(“res://textures/8H.png”)], “HNine”: [9, preload(“res://textures/9H.png”)],
“HTen”: [10, preload(“res://textures/10H.png”)], “HJack”: [10, preload(“res://textures/JH.png”)],
“HQueen”: [10, preload(“res://textures/QH.png”)], “HKing”: [10, preload(“res://textures/KH.png”)],
“HAce”: [11, preload(“res://textures/AH.png”)], “DTwo”: [2, preload(“res://textures/2D.png”)],
“DThree”: [2, preload(“res://textures/3D.png”)], “DFour”: [4, preload(“res://textures/4D.png”)],
“DFive”: [5, preload(“res://textures/5D.png”)], “DSix”: [6, preload(“res://textures/6D.png”)],
“DSeven”: [7, preload(“res://textures/7D.png”)], “DEight”: [8, preload(“res://textures/8D.png”)],
“DNine”: [9, preload(“res://textures/9D.png”)], “DTen”: [10, preload(“res://textures/10D.png”)],
“DJack”: [10, preload(“res://textures/JD.png”)], “DQueen”: [10, preload(“res://textures/QD.png”)],
“DKing”: [10, preload(“res://textures/KD.png”)], “DAce”: [11, preload(“res://textures/AD.png”)] }

var CopyDeck

@onready var button = $TextureButton

func _ready():

#makes copy for use
CopyDeck = Deck
for i in range(2):

func get_points():
# gets the points
player_points += random_card[0]
return player_points

func get_card():
var notinport = 0
#gets random card
random_card = CopyDeck.values()[randi() % CopyDeck.size()]
#adds the card
var instance = CARD.instantiate()
#sets texture
sprite_2d.texture = random_card[1]
#test for diff spawns
if notinport == 0:
#adds points
return random_card

func _button_pressed():


It seems like you should just be able to reference “instance” directly to adjust position.

After adding child, instance.position = Vector3(x,y,z) where x, y, z are the new LOCAL position you want.

Let me know if this helps!

1 Like

i add it but it doesnt change where it is being added

Hmm that’s strange, could you share any more information? Where in the code did you add the positioning line? Did you include it in both the if and the else statements after adding the instance as a child?

i added it right after the add child. the else is commented out.

if notinport == 0:
	instance.position = Vector2(700,0)

this is the main scene

this is the card scene

this is the main scene
the right icon is the button
the middle one is to find the middle
the things on the bottom right and left are test 1 and test 2

I’ve thought about this more and I can’t guess another reason why it wouldn’t work. If you are willing to share a minimal reproducible project with the bug in it, I can take a look and give it another shot. I think you can share it via public GitHub perhaps.

My apologies, hopefully, someone else can shed some light otherwise.