Is Collision/Overlap Prevention Possible? #470
Replies: 1 comment
-
Update on this. While I'd still like to know if there is already a built in way to handle this, I did figure out a way to do this. I dug into the source code to see what I can see and found the "Intersects" method of the Rectangle class. I took this code and made an extension method for the ModelNode class to detect overlaps:
Then I extended the ModelNode class to keep track of it's original location so if an overlap was detected it would move back to where it was originally. I did run into an issue with this at first where it wasn't always working. Then I realized that if the node being moved was underneath a node, focus swapped to the overlapping node so the intersection check wasn't firing properly. In my case Z-Index is not important so I added a call to SendToFront to put the node to be moved to the front and thus maintain focus. Again, this is working but if there is a better way I'd love to learn about it. |
Beta Was this translation helpful? Give feedback.
-
I am working on a project for creating storage tray layouts and need to not allow any of the rectangles to overlap. Is this something that can be done out of the box or do I need to "roll my own".
Thanx!
\M/ilo
Beta Was this translation helpful? Give feedback.
All reactions