1
\$\begingroup\$

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(e.target.data);
            xmlFilter = levelXML.*
            for each (var levelTest:XML in levelXML.*)
            {
                crack = levelTest;
            }
            levelArray = crack.split('');
            trace(levelArray);
            count = 0;
            for(i = 0; i <= 23; i++)
            {
                for(j = 0; j <= 35; j++)
                {
                    if(levelArray[i*36+j] == 1)
                    {
                        block = new Platform;
                        s.addChild(block);
                        block.x = j*20;
                        block.y = i*20;
                        count++;
                        trace(i);
                        trace(block.x);
                        trace(j);
                        trace(block.y);
                    }
                }
            }
            trace(count);

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

\$\endgroup\$
  • \$\begingroup\$ Can you share the "Level1.oel" file so we can figure out how data are organised and how they should be parsed ? \$\endgroup\$ – Valkea Jun 23 '12 at 18:58
3
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ +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). \$\endgroup\$ – Valkea Jun 24 '12 at 0:10
  • \$\begingroup\$ 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 \$\endgroup\$ – inzombiak Jun 24 '12 at 1:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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