From 71a77dbdcacbf0cbf10f0e045e344b39e97128c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Thu, 28 Aug 2025 06:55:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(ItemShow):=20=E4=B8=BA=E7=89=A9=E5=93=81?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E9=87=8A?= =?UTF-8?q?=E6=94=BE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在ItemShow.generate方法中新增isAutoFree参数,控制物品展示节点是否自动释放。这解决了需要手动管理物品展示节点内存的问题。 --- scripts/Statemachine/EntityBase.gd | 2 +- scripts/Statemachine/ItemShow.gd | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 50d112c..1abb597 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -84,7 +84,7 @@ func _ready(): ) itemCollected.connect( func(itemType, amount): - UIState.itemCollect.add_child(ItemShow.generate(itemType, amount)) + UIState.itemCollect.add_child(ItemShow.generate(itemType, amount, true)) ) else: currentFocusedBoss = get_tree().get_nodes_in_group("players")[0] diff --git a/scripts/Statemachine/ItemShow.gd b/scripts/Statemachine/ItemShow.gd index cdda528..e2c611f 100644 --- a/scripts/Statemachine/ItemShow.gd +++ b/scripts/Statemachine/ItemShow.gd @@ -19,8 +19,9 @@ func _physics_process(_delta): avatarTexture.texture = ItemStore.getTexture(type) countLabel.text = str(count) -static func generate(itemType: ItemStore.ItemType, itemCount: int = 1): +static func generate(itemType: ItemStore.ItemType, itemCount: int = 1, isAutoFree: bool = false): var item = preload("res://components/UI/ItemShow.tscn").instantiate() item.type = itemType item.count = itemCount + item.autoFree = isAutoFree return item