I have 2 TextureRect nodes. They are not siblings, they are cousins. They do not share the same parent, but they share the same grandparent.

Clicking on them is responsive. That's good!
However, using the method in the above screenshot returns the initial dice when I release the mouse button.

I want something that'll return the dice I click on AND the dice I release the mouse button on.
Preferably at the same time (after the mouse button is released).

  • poombus You'll need to implement a simple drag and drop system. There are numerous ways to do it. Here's one.

    Have a top level script that at all times tracks which dice icon is currently under the mouse. This can be done by receiving mouse_entered end mouse_exited signals from all visible dice icons. This script should also track global mouse button press/release events via _input() callback.

    When mouse is pressed, if there is a dice under the mouse, store it as a source for dragging operation and set internal state to dragging. When mouse is released, if the script is in dragging state and there is a dice under mouse, store it as a destination for dragging operation. At this point you know that drag has been performed and you know the source and the destination dice, so you can notify whomever is interested about it, either by emitting a custom signal or invoking an explicit callback. After the mouse has been released, set internal state back to not-dragging.

I was thinking of using a global signal, but that doesn't sound like the most simplest solution. Is there a better way?

  • xyz replied to this.

    poombus You'll need to implement a simple drag and drop system. There are numerous ways to do it. Here's one.

    Have a top level script that at all times tracks which dice icon is currently under the mouse. This can be done by receiving mouse_entered end mouse_exited signals from all visible dice icons. This script should also track global mouse button press/release events via _input() callback.

    When mouse is pressed, if there is a dice under the mouse, store it as a source for dragging operation and set internal state to dragging. When mouse is released, if the script is in dragging state and there is a dice under mouse, store it as a destination for dragging operation. At this point you know that drag has been performed and you know the source and the destination dice, so you can notify whomever is interested about it, either by emitting a custom signal or invoking an explicit callback. After the mouse has been released, set internal state back to not-dragging.

      xyz

      Worked like a charm! Thanks!

      GlobalMouseDiceTracker.gd

      New Dice Script