Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Faizan Ahmad Mir |
So I am new to godot and I want a drag and drop functionality in Godot,
I was able to check an online tutorial but wasnt able to replicate the functionality as “get_drag_data(position)” wouldnt trigger ,Can someone guide me with the same please.
For what I have tried is this
1)Make 2 control nodes inside a node2d
2)one is origin and the other is the destination
3) each node has a background color and a foreground color property which are actually colorrects
4)the code for origin is as follows
extends Control
func get_drag_data(position):
print("called")
var preview = self.duplicate()
preview.modulate.a =1
preview.get_node("color").rect_position = self.rect_size/2
preview.get_node("bkg").hide()
set_drag_preview(preview)
return self
the code for destination is as follows :
extends Control
func can_drop_data(position, data):
return true
func drop_data(position, data):
$color.color = data.get_node("color").color
data.get_node("color").color = Color(randf(), randf(), randf(), 1)
The problem here is when I start drag in the origin none of the functions gets called
Can you give more info about what you’ve tried?
andersmmg | 2020-04-03 16:03
Hi I have edited the OP for the same,Please check
Faizan Ahmad Mir | 2020-04-04 09:13
In Godot 4 is
_get_drag_data(at_position)
luislodosm | 2022-09-25 19:08