构建具有对齐对齐功能的拖放拼图式界面

发布于 2024-12-24 22:31:51 字数 366 浏览 2 评论 0原文

我正在构建一个 Android 益智游戏,用户可以旋转并移动拼图的各个部分以形成最终的图片。它有点像滑块拼图,但碎片的形状和大小并不统一 - 更像是俄罗斯方块的滑块版本。

目前,我已经将拼图块作为图像视图,可以选择它们并在视图中移动以定位它们。我在幕后得到了形状的矢量形式作为点的数组列表。

但是......我对如何将各个部分对齐在一起感到困惑。即,当一个片段靠近另一个片段时,移动一个片段以使附近的边缘彼此重叠(即本质上共享边界)。

我确信这已经做过很多次了,但找不到代码示例(任何语言)。它类似于捕捉到网格,但不一样,并且与您可以将对象彼此捕捉时在图表类型界面中获得的功能相同。

任何人都可以向我指出教程(任何语言)/代码/或就如何实现它提供建议吗?

I'm building an Android puzzle game where the user rotates and shifts pieces of a puzzle to form a final picture. It's a bit like a sliding block puzzle but the shape and size of pieces is not uniform - more like a sliding block version of tetris.

At the moment I've got puzzle pieces as imageViews which can be selected and moved around a view to position them. I've got the vector forms of the shapes behind the scenes as ArrayLists of Points.

But...I'm stuck on how to snap align the pieces together. I.e. when a piece is nearby another, shift one piece so that the nearby edges overlay each other (i.e. essentially share a boundary).

I'm sure this has been done plenty of times but can't find examples with code (in any language). It's similar to snapping to a grid but not the same and is the same kind of functionality you get in a diagramming type interface when you can snap objects to each other.

Can anyone point me toward a tutorial (any langauge) / code / or advise on how to implement it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天生の放荡 2024-12-31 22:31:51

Urs 就像七巧板游戏。我认为不可能用一些图像来形成最终的图片。它可以通过使用 android.Graphics 包创建几何形状(对于最终形状和最终图片的片段/切片)来完成。从块/切片的边缘和顶点确定最终形状非常容易。

Urs is like Tangram game. I think it cannot be done with pieces of image to form a final picture. It can be done by Creating Geometry shapes(for both Final shape and pieces/slices of final picture) using android.Graphics package. Its quite easy to determine the final shape from the edges and vertices of pieces/slices.

携余温的黄昏 2024-12-31 22:31:51

http://code.google.com/p/photogaffe/ 值得一看。它是一个开源滑动拼图,由 15 块组成,允许用户从图库中选择图像。

您只需要弄清楚各种形状以及如何旋转它们即可。如果您提供自己的图像...如何加载它们。

希望有帮助。

http://code.google.com/p/photogaffe/ is worth checking out. It is an opensource sliding puzzle consisting of 15 pieces and allows the user to choose an image from their gallery.

You would only have to figure out your various shapes and how to rotate them. And if you are supplying your own images...how to load them.

Hope that helps.

空名 2024-12-31 22:31:51

在每个形状周围画一个盒子怎么样?然后定义它的中间。然后您可以存储每个部件的旋转值。您需要将邻居与中间的向量存储在一起。

然后你只需计算向量在合理的范围内并且旋转为+-X度。例如,如果矢量在 +-10 像素范围内且旋转为 +-3°,则可以旋转该部分并将其放入拼图中。

What about drawing a box around each shape. Afterwards you define the middle of it. Then you can store a value for the rotation for each piece. And you would need to store the neighbours together with a vector the their middle.

Then you simply have to compute that the vector is in a reasonable range and the rotation is +-X degree. For example if the vector is in a range of +-10pixels and the rotation is +-3° you could rotate the piece and fit it into the puzzle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文