3

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?

4

3 に答える 3

1

ウルスはタングラムゲームのようなものです。画像を使って最終的な絵を描くことはできないと思います。これは、android.Graphicsパッケージを使用してジオメトリシェイプ(最終シェイプと最終画像のピース/スライスの両方)を作成することで実行できます。ピース/スライスのエッジと頂点から最終的な形状を決定するのは非常に簡単です。

于 2012-01-02T11:59:38.317 に答える
0

それぞれの形の周りにボックスを描くのはどうですか。その後、その中央を定義します。次に、各ピースの回転の値を保存できます。そして、あなたはそれらの真ん中のベクトルと一緒に隣人を保存する必要があります。

次に、ベクトルが妥当な範囲内にあり、回転が+-X度であることを計算する必要があります。たとえば、ベクトルが+ -10ピクセルの範囲にあり、回転が+ -3°の場合、ピースを回転させてパズルに合わせることができます。

于 2012-01-02T14:31:58.053 に答える
0

http://code.google.com/p/photogaffe/はチェックする価値があります。これは15ピースで構成されるオープンソースのスライディングパズルであり、ユーザーはギャラリーから画像を選択できます。

あなたはあなたの様々な形とそれらを回転させる方法を理解する必要があるだけでしょう。そして、あなたがあなた自身の画像を提供しているなら...それらをロードする方法。

お役に立てば幸いです。

于 2012-01-02T12:09:49.450 に答える