How to use the pytmx.tmxloader3.TiledElement function in PyTMX

To help you get started, we’ve selected a few PyTMX examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitcraft / PyTMX / pytmx / tmxloader3.py View on Github external
else:
            try:
                return self.tile_properties[gid]
            except (IndexError, ValueError):
                msg = "Coords: ({0},{1}) in layer {2} has invaid GID: {3}/{4}.".format(x, y, layer, gid, len(self.images))
                raise Exception(msg)

    def getTilePropertiesByGID(self, gid):
        try:
            return self.tile_properties[gid]
        except KeyError:
            return None

# the following classes get their attributes filled in with the loader

class TiledTileset(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)

        # defaults from the specification
        self.firstgid = 0
        self.lastgid = 0
        self.name = None
        self.tilewidth = 0
        self.tileheight = 0
        self.spacing = 0
        self.margin = 0

class TiledLayer(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)
        self.data = None
github bitcraft / PyTMX / pytmx / tmxloader3.py View on Github external
self.data = None

        # defaults from the specification
        self.name = None
        self.opacity = 1.0
        self.visible = 1

class TiledObjectGroup(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)
        self.objects = []

        # defaults from the specification
        self.name = None

class TiledObject(TiledElement):
    __slots__ = ['name', 'type', 'x', 'y', 'width', 'height', 'gid']

    def __init__(self):
        TiledElement.__init__(self)

        # defaults from the specification
        self.name = None
        self.type = None
        self.x = 0
        self.y = 0
        self.width = 0
        self.height = 0
        self.gid = 0


def load_tmx(filename):
github bitcraft / PyTMX / pytmx / tmxloader3.py View on Github external
self.tilewidth = 0
        self.tileheight = 0
        self.spacing = 0
        self.margin = 0

class TiledLayer(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)
        self.data = None

        # defaults from the specification
        self.name = None
        self.opacity = 1.0
        self.visible = 1

class TiledObjectGroup(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)
        self.objects = []

        # defaults from the specification
        self.name = None

class TiledObject(TiledElement):
    __slots__ = ['name', 'type', 'x', 'y', 'width', 'height', 'gid']

    def __init__(self):
        TiledElement.__init__(self)

        # defaults from the specification
        self.name = None
        self.type = None
github bitcraft / PyTMX / pytmx / tmxloader3.py View on Github external
# internal flags
FLIP_X = 1
FLIP_Y = 2


# Tiled gid flags
GID_FLIP_X = 1<<31
GID_FLIP_Y = 1<<30


class TiledElement(object):
    pass

class TiledMap(TiledElement):
    """
    not really useful unless "loaded"  ie: don't instance directly.
    see the pygame loader for inspiration
    """

    def __init__(self):
        TiledElement.__init__(self)
        self.layers = []            # list of all layer types (tile layers + object layers)
        self.tilesets = []          # list of TiledTileset objects
        self.tilelayers   = []      # list of TiledLayer objects
        self.objectgroups = []      # list of TiledObjectGroup objects
        self.tile_properties = {}   # dict of tiles that have additional metadata (properties)
        self.filename = None

        # this is a work around to tiled's strange way of storing gid's
        self.images = [0]
github bitcraft / PyTMX / pytmx / tmxloader3.py View on Github external
# the following classes get their attributes filled in with the loader

class TiledTileset(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)

        # defaults from the specification
        self.firstgid = 0
        self.lastgid = 0
        self.name = None
        self.tilewidth = 0
        self.tileheight = 0
        self.spacing = 0
        self.margin = 0

class TiledLayer(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)
        self.data = None

        # defaults from the specification
        self.name = None
        self.opacity = 1.0
        self.visible = 1

class TiledObjectGroup(TiledElement):
    def __init__(self):
        TiledElement.__init__(self)
        self.objects = []

        # defaults from the specification
        self.name = None