I’ve got a number of draggable objects in my scene (all with the draggable behaviour), and want some to be chosen over others. Is it possible to do this? Or, what’s the order that the draggable behaviour uses to determine which object is dragged if two or more are under the mouse pointer when the LMB is clicked?
I’ve tried changing the z-order, so my preferred object has a higher value, but that doesn’t make a difference.
I’ve tried creating another layer for my preferred objects, and placing that above the base layer where the other objects reside. It too makes no difference.
I’ve even changed the order in which I create the objects. No change to what gets selected.
What can I do to get one object selected over another when they are both under the mouse pointer and I click the LMB?
Here’s an example of what I mean. Even though the flower is has a higher z-order than the white square, the white square is always selected. But I want the flower to be selected. How do I achieve that?
If I remember right, draggable works from lowest Z-order up, and then from object creation ID up? So the lowest Z order number is always picked first.
Not sure there’s a way to control it, except for maybe adding all of the objects to a group, and tracking which object’s Zorder is the highest, and disabling any other group member’s draggable behavior if the Zorder doesn’t match that highest order?
This isn’t 100% a solution, as you have to click twice to re-enable the behavior. But it’s close.
What I would do is disable the draggable behavior for the white square when
- it is in collision with the flower
- the Z order of the flower is higher than the white square
- the white square is not dragged
In other case, enable it so I can drag the white square.
I’ve ended up doing a bit of a hybrid of your solutions; I can separate the objects into distinct groups, and if the mouse is over one group, I’ll disable drag on the other.
Thanks for your help and suggestions
Is it possible to stop processing an event? Suppose you have determined that you have selected a flower and then execute a command that stops processing the click event for other objects (in fact, it “destroys” the event).
There is no such concept as destroying an event. If it’s a behavior you disable the behavior, for other actions you’re better off just setting a variable.
Thanks. But such a possibility would be convenient to limit the processing of the event.
Yes, and as mentioned you can simply do this with using a variable as a condition for the event, then changing the variable value to something other than what is in the comsition.