防止 Flex 中拖放图像重叠
我试图在 Flex Builder 3 中创建一个基本的谜题。我将数组中的图像显示到画布上,可以在画布上拖放图像。我的问题是我不希望图像能够相互重叠。关于如何防止这种情况的任何想法?
它们可以在您拖动时重叠,但在放置时不会重叠,它们需要“捕捉”到尚未被另一图像占据的最近点。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我做了类似的事情。您所做的是将目标
(x,x + object.width)
和(y,y + object.height)
添加到数组中。在此之前,如果数组不为空,请检查新对象的 x 或 y 值是否在数组中的现有范围内。如果是这样,则不允许丢弃,否则允许丢弃。所有图像,无论“图片”如何,都是正方形/矩形,因此这可以防止重叠。但是,如果您有复杂的图片(即圆形/六边形)并尝试将边缘对接在一起,那么此方法将不起作用。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.