Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a little platformer and wanted to use Ogmo to create my level. I've gotten everything to work except the level that my code generates is not the same as what I see in Ogmo. I've checked the array and it fits with the level in Ogmo, but when I loop through it with my code I get the wrong thing. I've included my code for creating the level as well as an image of what I get and what I'm supposed to get.

EDIT: I tried to add it, but I couldn't get it to display properly

Also, if any of you know of better level editors please let me know.

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("Level1.oel"));
        function LoadXML(e:Event):void
            levelXML = new XML(;
            xmlFilter = levelXML.*
            for each (var levelTest:XML in levelXML.*)
                crack = levelTest;
            levelArray = crack.split('');
            count = 0;
            for(i = 0; i <= 23; i++)
                for(j = 0; j <= 35; j++)
                    if(levelArray[i*36+j] == 1)
                        block = new Platform;
                        block.x = j*20;
                        block.y = i*20;

enter image description here Left: What I get, Right: What I should get

share|improve this question
Can you share the "Level1.oel" file so we can figure out how data are organised and how they should be parsed ? – Valkea Jun 23 '12 at 18:58
up vote 3 down vote accepted

this is just a guess but can you make sure your "levelArray" does't contain "\n" at the end of each line. maybe changing your condition to if(levelArray[i*37+j] == 1) solve the problem. note that it might also have an extra "\n\r" at the end of each line. In that case you need to multiply i by 38 in that condition.

actually after checking the image you provided again, I'm now pretty sure the lines are ending with an only extra "\n", meaning each line is 37 character not 36 as you expected.

share|improve this answer
+1, I second that idea. I tried the exact same algo (the one in the question) and it does works fine with an array I created myself (so without any \n). – Valkea Jun 24 '12 at 0:10
YES! Thank you. I've never worked with XML before so i thought by splitting it it would just magically turn into what i needed it to be – inzombiak Jun 24 '12 at 1:18

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.