3
\$\begingroup\$

I want to split a texture into variously shaped pieces with libgdx, like the pieces of a puzzle game. TextureRegion.split() is not an option, as it splits into equally sized rectangular texture regions.

The "Similar Questions" section here is helpful (particularly this question How do I break an image into 6 or 8 pieces of different shapes?), but I'm not sure yet if it's possible to implement the solution with libgdx.

Any pointers?

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

I assume you want to create something like a "jigsaw" puzzle. Off the top of my head, an algorithm that might get you started is as follows.

  • Begin by splitting your image into equal pieces, it seems like the TextureRegion.split can do this for you.
  • After this, you will have some pieces that have been split. Generate a 2D array mapping each puzzle pieces position. For example:

enter image description here

Essentially, the top left would be your "top left" piece, and everything running across y = 0 excluding the end points would be your "top centers".

  • With your array in hand, you can map these pieces accordingly:

enter image description here

You should be able to come up with some logic based on your array on how each piece should be created. Then, using some texture manipulating you can punch "holes" in the texture pieces if you're trying to create a jigsaw effect.

\$\endgroup\$
3
  • \$\begingroup\$ This is a nice conceptual overview to what I thought was an implementation question. \$\endgroup\$
    – Anko
    Apr 9, 2014 at 10:44
  • \$\begingroup\$ @Anko The edit makes that a bit more clear, so I'll try and add a more concrete explanation regarding to what VictorB wants later today. \$\endgroup\$ Apr 9, 2014 at 17:29
  • \$\begingroup\$ Hi, do you have any update on this one? Thanks. \$\endgroup\$
    – VictorB
    Apr 16, 2014 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .