Today, when testing the card generation issue in the card game, I found that when using the following method to generate multiple cards, a problem occurred where each card shared the same health value. When one card’s health drops to zero, all objects disappear.
and the process of being destroyed repeats continuously, followed by an error.
extends GameScene
@onready var pre_card_scn = preload("res://卡片保存/卡片.tscn")
@onready var card_test = preload("res://卡牌对象新建测试.tscn")
var dragging_card: Card = null
var mounse_card_offset : Vector2 = Vector2.ZERO
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
_new_card_test(Vector2(600, 500))
_new_card_test(Vector2(700, 500))
_new_card_test(Vector2(800, 500))
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
#if dragging_card:
#dragging_card.position = get_global_mouse_position() + mounse_card_offset
pass
func _new_card_test(posititon: Vector2):
var card_test = load("res://卡牌对象新建测试.tscn")
var card = card_test.instantiate()
card.position = posititon # 设置卡牌位置
add_child(card)
pass
I want to find a way to generate a large number of cards to build the deck of my game. When using the Visual Studio Editor as the script, generating objects can only be done by specifying the generation path, and calling database data can only be specified by constants, which troubles me. When I tried to batch generate using the add_child method, I encountered such an error. I would like to ask the experts in the forum if there is a good solution.
If you can reply, I would be extremely grateful.







