Reputation: 457
I am trying to do a drag & drop on a number of rectangle objects that are draggable.
There is another set of rectangle objects acting as container for dropping objects - I have added them to a group.
Everything is in a single layer.
Also when the draggable element is placed over the group box, it does not listen to the mouse over event (which is assigned to it) - is there a way to delegate the events(mouseover, mouseout) to the low level object when another element drags over it.
box.on("mouseover", function(e) { console.log("mouseover");});
Thanks.
Upvotes: 0
Views: 912
Reputation: 3160
I believe that KineticJS doesn't support it's own collision detection so you would have to write your own function. These 2 SO questions are good starting points:
Referencing the answer to this question: How to start mouseover event while dragging
We see that we can follow similarly on KineticJS, and that the solution goes hand in hand with creating your own collision detection function. The only difference here is instead of calculating the coordinates for hit detection on divs, you can calculate the 4 corner point coordinates of each shape (in your case, a rectangle). Also, instead of writing your own drag functions, you can use getMousePos() and the events: dragstart, dragend, and mousemove to rewrite the code from the fiddle example and cater to your kinetic rectangles.
Upvotes: 0