I'm new to LibGDX and android development in general and am trying to do a puzzle game. Being a level-based game, i'm trying to make it so in every level a certain number of blocks (just rectangular sprites) appear in a certain position / rotation, like in the image linked below:


I've doodled some levels already but i'm really not sure about how to make the blocks's rearrangement over the levels. How exactly should one manage this? As the position of the blocks won't be random i was thinking about reading from files the information from every level (x, y, rotation, colors, etc. for every block) but to do that i would have to manually organize every level's blocks properties information (to then save), and, considering it would have atleast 100+ levels, it would take too long... Other than that, i could have them as plain assets but having an asset for every single level doesnt't look like an efficient solution either. Do you have any tips, please?

  • 2
    \$\begingroup\$ Your first step would be to create a level editor :) \$\endgroup\$
    – Vaillancourt
    Commented Nov 15, 2015 at 19:37
  • \$\begingroup\$ Hey, thanks alot for the quick answer! Sorry to bother, but would you mind explaining a little bit about how exactly would the level editor work(or tell me where i could find more information about it), please? \$\endgroup\$
    – Francisco
    Commented Nov 15, 2015 at 19:55
  • \$\begingroup\$ You have to make the level editor yourself, using LibGDX. Play around with mouse events. To draw rectangles, for example, you'd listen for when the mouse is down and record where the cursor was dragged across, creating your rectangle there etc. \$\endgroup\$
    – Lucien
    Commented Nov 15, 2015 at 20:03
  • \$\begingroup\$ "How to get started" are off-topic questions for Game Development, and your question is very close to be off topic. However, I can try and point you in the right direction in the comments. When making a level editor, you have 2 options: in-game and out-of-game. In-game: you add the feature to your game to create, edit and save the levels. This has the advantage that you only have to code 1 engine, even if you need more than 1 'mode'. Out-of-game: you program a 2nd app which you use to create your levels. This makes the "mode management" easier, but you have to build 2 different engines. \$\endgroup\$
    – Vaillancourt
    Commented Nov 15, 2015 at 20:04
  • \$\begingroup\$ Think i got it, thank you very much! \$\endgroup\$
    – Francisco
    Commented Nov 15, 2015 at 20:06

1 Answer 1


In a puzzle game that I have been working on I have found that an XML file has been a rather efficient way to store level data.

For example, you could have an xml file for each level pack

      <Level number="1">
        <Block x="0" y="0" rotation="90" color="#FF0000" />
        <Block x="50" y="22" rotation="45" color="#00FF00" />
      <Level number="2">

You could then serialize the xml file into some sort of model object in your code. Even with 100+ levels this should be easy to manage and is way less time consuming than making a level editor.

  • \$\begingroup\$ Hey, thank you very much for the answer! That does look like quite a good way to do it; i still remain with one question though: what would be best way to tell the x and y values of the blocks considering one block would start where the other block ends? I've tried some stuff, but the fact that each block has it's own rotation / height is making it a bit difficult... :( (I know this isn't really related to the question, but any help would be highly appreciated) i.gyazo.com/df8046a3879d3a90374d82de2c7c7867.png \$\endgroup\$
    – Francisco
    Commented Nov 16, 2015 at 22:34
  • \$\begingroup\$ You can use Trig to calculate this. If you know the x,y rotation, and the length of the rectangle, then you can calculate its other endpoint by endX = x + cos(rotation)*length and endY = y + sin(rotation)*length If you want, you can even specify in the XML that some blocks have relative positioning and you can calculate this when you load the level \$\endgroup\$ Commented Nov 16, 2015 at 23:05
  • \$\begingroup\$ Hey, i did try using trig but the values i was getting weren't matching the ones i tried manually :( Like, manually a block would start at let's say x= 110 but using trig the value would be like 85. Not quite sure why to be honest, but i will try it out again for sure, thank you so much. \$\endgroup\$
    – Francisco
    Commented Nov 16, 2015 at 23:12

You must log in to answer this question.

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