Godot Version
4.4
Question
i was doing as the video says but when it got to part around minute 8 it does not do as in the video. instead it just makes one card and it appears on top of the card manager node and i cant move it and it disappears when i click on it
extends Node2D
const hand_count = 8
const card_path_scene = "res://Cards_scene/testcard.tscn"
const card_w = 200
const hand_y_pos = 890
var player_hand=[]
var center_screen_x
func _ready() -> void:
center_screen_x=get_viewport().size.x/2
var card_scene = preload(card_path_scene)
for i in range(hand_count):
var new_card = card_scene.instantiate()
$"../cardmanager".add_child(new_card)
new_card.name = "card"
add_card_to_hand(new_card)
func add_card_to_hand(card):
player_hand.insert(0, card)
func update_hand_position():
for i in range(player_hand.size()):
var new_postion = Vector2( calculate_card_position(i), hand_y_pos)
var card = player_hand[i]
animate_card_to_pos(card, new_postion)
func calculate_card_position(index):
var total_w=(player_hand.size() -1 ) * card_w
var x_offset = center_screen_x + index * card_w - total_w / 2
return x_offset
func animate_card_to_pos(card, new_postion):
var tween = get_tree().create_tween()
tween.tween_property(card, "position", new_postion, 0.1)