Godot Version
4.2
Question
Hi, guys. I’m a bit new here so if the format’s off, sorry about that.
Right now I’m trying to make something akin to a point-and-click adventure game where the player ahs to find certain items and put them in their inventory.
The inventory appears in the top left corner of the screen, and I’m trying to make so that if the player drags the item to the inventory, it then becomes added to one of the slots.
The logic I had behind this process was that the item would be dragged to the inventory window in a collision signal and then that item would then delete from the scene and become part of the inventory as one of the inventory slots. But fiddling with it now that may not be the case.
Sorry if this seems like a newbie question, I’ve just been messing around with this for a while now and am not sure how to go about this portion of the project.
Here’s the code for the item (a cake):
extends Node2D
class_name Item
@export var item_name: String = ""
@export var icon: Texture2D
@export var is_stackable: bool = false
@export var itemresource: Item
@onready var window : Panel = get_node("inventorywindow")
@onready var inventoryarea : StaticBody2D = get_node("invarea/inventoryarea")
@onready var cake : Item = get_node("cake/StaticBody2D/cake/Sprite2D")
var can_grab = false
var grabbed_offset = Vector2()
var spawn_position = Vector2(722,364)
func _input_event(viewport, event, shape_idx):
if event is InputEventMouseButton:
can_grab = event.pressed
grabbed_offset = position - get_global_mouse_position()
func _process(delta):
if Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and can_grab:
position = get_global_mouse_position() + grabbed_offset
else : global_position = spawn_position
func _on_cake_body_entered(body):
if body.name == "inventoryarea" :
$Timer.start()
func _on_Timer_timeout():
queue_free()
func _on_invarea_mouse_entered():
if MOUSE_BUTTON_LEFT and cake:
var cake = get_node("cake/StaticBody2D/cake/Sprite2D")
cake.queue_free()
I hope I made things a little clearer and thanks in advance!