I'm trying to make an inventory system similar to Stardew and Terraria. The hotbar should duplicate the first row of items in the inventory's dictionary. The problem happens when I open the inventory and move an item from a Panel to an empty Panel the sprite will not clear and I'll be left with duplicate items. Is there a way to clear the Panel and empty it out?
This is the script for my hotbar:
extends Node2D
const SLOT_CLASS = preload("res://Slot.gd")
onready var inventory_slots = $TextureRect/GridContainer
var holdingItem = null
var tempItem
var stackSize
var ableToAdd
var slots
var item
func _process(_delta):
slots = inventory_slots.get_children()
for i in range(slots.size()):
slots[i].slotIndex = i
_initialize_inventory()
func _initialize_inventory():
slots = inventory_slots.get_children()
for i in range(slots.size()):
if PlayerInventoryScript.dicInventory.has(i):
slots[i]._initialize_item(PlayerInventoryScript.dicInventory[i][0],PlayerInventoryScript.dicInventory[i][1])