A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: XML in Platformers

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    12

    XML in Platformers

    i would like to ask how to use XML (to refer to game pieces and objects in a Flash library) and create a level editor that generates XML based on manipulation of those Flash library objects. also, how do i make an XML parser? thanks.

  2. #2
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    a very fague question imo. I usually first create an xml template in a xml editor (scite,xmlmaker,notepad,...) and create sample scenarios on how the data should be stored in certain conditions.
    So the first thing to code would be something that understand´s the xml structure and logic behind your generated file.

    take for example the following xml file:
    PHP Code:
    <xml startPos="8,2">
        <
    r>5,2,1</r>
        <
    r>1,1,1</r>
        <
    r>5,4,3</r>
    </
    xml
    wich in this case represents a very simple level with a 2d grid (3*3 rows = 9 cells) and a X & Y start position.

    if I wanted to read that xml file (I´ll name it sample.xml in this case) within flash I´d write something like this 1 the first frame:

    PHP Code:
    xml = new XML();
    xml.ignoreWhite true;
    xml.onLoad xmlInit;

    xmlInit = function(ok){
        if (
    ok){
            
    readLevel(xml);
        }else{    
            
    trace("no such XML file");
        }
    }
    xml.load("sample.xml");

    readLevel = function(xmlFile){
        var 
    pos = new Object();
        
    pos.NumberxmlFile.firstChild.attributes.startPos.split(",")[0] );
        
    pos.NumberxmlFile.firstChild.attributes.startPos.split(",")[1] );

        
    trace("start position : "+pos.x+"/"+pos.y);


        
        var 
    map = new Array();

        var 
    node xmlFile.firstChild.childNodes;
        for (var 
    i=1;i<=node.length;i++){

            
    map[i-1] = new Array();
            var 
    tempRow node[i-1].firstChild.nodeValue.split(",");
            for (var 
    j=1;j<=tempRow.length;j++){
                
                var 
    cell Number(tempRow[j-1])
                
    map[i-1].push(cell);
                
                
    trace("cell x:"+i+",y:"+j+" = "+cell);
            }
        }

    that way it should be possible to read this particular structure, if you want to save or store the xml data e.g getting it back you either can manipulate the xml object (rather not recomended) or run paralel array data such as the map array in my exemple and work with that one furtherone in your engine or editor. Manipulate the values and or add/remove them.
    then write some xml string generator or xml object generator that backwards generates a xml string (something you can display in a textfield and or pass it to php to save it on the server) or an xml object and convert it to a string wich is basicly the same as it results in a String wich is XML code.

    maybe there were some usefull insights for you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center