Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your parser code will have to remember which sort of layer it's currently in at the time of the START_TAG event for a tile tag.</p> <p>One way to do this is to create a field <code>String currentLayer;</code> and somewhere in your code have code segments resembling</p> <pre><code>if (xrp.getEventType() == XmlResourceParser.END_TAG) { String s = xrp.getName(); if (s.equals("layer")) { currentLayer = null; // or something ... } } </code></pre> <p>and</p> <pre><code>if (xrp.getEventType() == XmlResourceParser.START_TAG) { String s = xrp.getName(); if (s.equals("layer")) { currentLayer = xrp.getAttributeValue(null, "name", 0); } } </code></pre> <p>Then in your code dealing with the tile tag, you'll use that field to decide which action to take with something resembling</p> <pre><code>if (xrp.getEventType() == XmlResourceParser.START_TAG) { String s = xrp.getName(); if (s.equals("tile")) { int a = xrp.getAttributeIntValue(null, "gid", 0); if ("layer1".equals(currentLayer) { // process layer1 tile. } else if ("layer2".equals(currentLayer) { // process layer2 tile. } else { // handle occurrence of tile outside layer. } } } </code></pre> <p>This is not necessarily the best approach, especially if it leads to huge nested if-else constructs, but this might get you started.</p> <p>A better approach might be to have a field for a delegate that handles tiles, set it to an appropriate "tile-processor" object (which you'll have to define as a separate class) during the start event handling for the layer tag and use it in the handling of the tile tag. But that's harder to put in code snippets.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload