Prevent overlapping DragDrop Images in Flex
I am trying to create basically a puzzle in Flex Builder 3. I display images from an array onto a canvas that can be dragged and dropped around the canvas. My problem is that I don't want the images to be able to overlap each other. Any ideas on how to prevent this??
They can overlap as you drag but not when dropped, they need to "snap" to the nearest point that is not already开发者_如何学运维 occupied by another image.
I did something similar to this. What you do is onDrop add the target (x,x + object.width)
and (y,y + object.height)
to an array. Prior to this, if array is not null, check to see if your new object's x or y value is within an existing range in the array. If so, do not allow drop else allow the drop. All images, regardless of "picture" are square/rectangles so this would prevent the overlapping. However, if you have complex pictures (i.e. circles/hexagons) and are trying to butt the edges together, then this method will not work.
精彩评论