The XML File Specification

The intent is that you may have a tile set defined in one XML file which is shared amongst many map files (or indeed within a single XML file). Images may be shared amongst multiple tiles with the tiles adding different meta-data in each case.

These may be constructed manually or loaded from XML resource files which are used to store the specification of tile sets and tile maps. A given resource XML file may define multiple tile sets and maps and may even reference other external XML resource files. This would allow a single tile set to be used by multiple tile maps.

Assuming the following XML file called "example.xml":

<?xml version="1.0"?>
<resource>
  <requires file="ground-tiles.xml" namespace="ground" />

  <rectmap id="level1">
   <column>
    <cell tile="ground:grass" />
    <cell tile="ground:house">
      <property type="bool" name="secretobjective" value="True" />
    </cell>
   </column>
  </map>
</resource>

You may load that resource and examine it:

>>> r = load('example.xml')
>>> map = r['level1']

and then, assuming that level1 is a map:

>>> scene = cocos.scene.Scene(map)

and then either manually select the tiles to display:

>>> map.set_view(0, 0, window_width, window_height)

or if you wish for the level to scroll, you use the ScrollingManager:

>>> from cocos import layers
>>> manager = layers.ScrollingManager()
>>> manager.add(map)

and later set the focus with:

>>> manager.set_focus(focus_x, focus_y)

See the section on controlling map scrolling below for more detail.