Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | SebSharper |
Hello.
I am making an inventory system for my game, but I got one issue: I need to get the UI Node (TextureRect) that is in a certain position.
For example, to swap items between the inventory, I drag one item to another slot, and then I release the mouse button. I should be able to get the node that is in the position of the mouse (only when it is released).
Note: I use a GridContainer
Is there any way that I can achieve this?
Perhaps you can get the mouse’s local position relative to the GridContainer. Then have a function that calculates which square that is based on GridContainer’s square size, and number of columns and rows?
eod | 2020-04-25 01:12
Do you know the name of the function?
SebSharper | 2020-04-25 01:15
I was thinking this function, which you may be able to use as a standalone
get_local_mouse_position()
Or it might be something like:
$"GridContainer".get_local_mouse_position()
Here’s some other mouse positions that may be of help:
CanvasItem — Godot Engine (3.2) documentation in English
I would just try a few ways of getting the mouse position and print the result of those functions to the debug/output console until you get the position you want.
eod | 2020-04-25 01:26