Skip to content

Migration to version 3.x

bitcraft edited this page Sep 14, 2014 · 1 revision

Greetings!

Several months ago, I started a new branch just for Python 3 compatibility, using the great six module. It is now the focus of development for PyTMX. If you have an existing project, you can continue to use the old 2.x series of PyTMX, but I encourage you to check out the python3 branch for anything new.

The biggest benefit will be better feature parity with Tiled, and your games/applications that use PyTMX will have greater python 2 and 3 compatibility for free!

Migration

Using the new 3.x library will break your code, but not by much!

  • CamelCase method names have been changed to match PEP 8 standards. Please check your existing code and search/replace all CamelCase method names with their new _underscore variants.
  • TiledObjects do not need metadata to be accessed through dict

Examples

Old

image = tmxdata.getTileImage(x, y, layer)
props = tmxdata.getTileProperties(x, y, layer)
for obj in tmxdata.getObjects():
    ...do stuff...
for obj in layer.objects:
    ...do stuff...
for key, value in tiled_object.__dict__:
    ...do stuff...

New

image = tmxdata.get_tile_image(x, y, layer)
props = tmxdata.get_tile_properties(x, y, layer)
for obj in tmxdata.objects:
    ...do stuff...
for obj in layer:
    ...do stuff...
for key, value in tiled_object.properties.items():
    ...do stuff...
Clone this wiki locally