Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

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
add comment

1 Answer

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  
+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
add comment

Your Answer

 
discard

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.