moved decoding of layers up to TileMap
[2dworld.git] / tiledtmxloader3 / examples / 00_load-a-map / 00_load_map.py
blob9660b58586c3339a7b2c570d0ba5e08bec0905cd
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 """
6 This is the pygame minimal example.
8 """
10 __revision__ = "$Rev$"
11 __version__ = "3.0.0." + __revision__[6:-2]
12 __author__ = 'DR0ID @ 2009-2011'
15 import sys
16 import os
18 try:
19 import _path
20 except:
21 pass
23 import tiledtmxloader
25 # -----------------------------------------------------------------------------
27 def main():
28 """
29 Main method.
30 """
31 args = sys.argv[1:]
32 if len(args) < 1:
33 path_to_map = os.path.join(os.pardir, "001-1.tmx")
34 print(("usage: python %s your_map.tmx\n\nUsing default map '%s'\n" % \
35 (os.path.basename(__file__), path_to_map)))
36 else:
37 path_to_map = args[0]
39 demo_pygame(path_to_map)
41 # -----------------------------------------------------------------------------
43 def demo_pygame(file_name):
44 """
45 Example showing how to load a map.
46 """
48 # parser the map (it is done here to initialize the
49 # window the same size as the map if it is small enough)
50 world_map = tiledtmxloader.tmxreader.TileMapParser().parse_decode(file_name)
52 # print the filename
53 print("loaded map:", world_map.map_file_name)
55 # let see how many pixels it will use
56 x_pixels = world_map.pixel_width
57 y_pixels = world_map.pixel_height
58 print("map size in pixels:", x_pixels, y_pixels)
61 # let see the tilesize
62 print("tile size used:", world_map.tilewidth, world_map.tileheight)
64 # number of tiles
65 print("tiles used:", world_map.width, world_map.height)
67 # count the layers
68 print("found '", len(world_map.layers), "' layers on this map")
70 # # just to see if the map was loaded correctly we print
71 # # it on the console, warning: may be huge output!
72 # # tiledtmxloader.tmxreader.printer(world_map)
74 # -----------------------------------------------------------------------------
76 if __name__ == '__main__':
77 main()