set drag preview is far away from the cursor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By powervette

The preview is around -70, 20 away from the actual mouse pointer, I have searched and searched for an answer to this, found nothing so far. If i read the function right it returns the mouse pointer position? Is there somewhere I can check the mouse position while the app is running? Or something else to check?

This is for an inventory system, and if I drag the item and drop on a new slot that works fine, so it seem to be getting the proper mouse position, just the preview is so far away.

Thanks

 func get_drag_data(_pos):
	if slot.item_struct != null:
		var preview = TextureRect.new()
		preview.texture = slot.item_struct.i_image
		preview.expand = true
		preview.rect_size = Vector2(24, 24)
		preview.add_child(preview)
		set_drag_preview(preview)
		return slot
:bust_in_silhouette: Reply From: Lopy

The Node given as preview can have children. You could Set a basic Node2D as preview, with your TextureRect as child. The advantage is that you can set the position of the child relative to it’s parent, to counteract the offset you where experiencing.

Will give that a try, thanks

powervette | 2020-12-25 16:36