How to use the pytmx.TiledMap 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 openai / neural-mmo / forge / blade / core / map.py View on Github external
def loadTiled(fPath, tiles, nCounts):
    import pytmx
    tm = pytmx.TiledMap(fPath)
    assert len(tm.layers) == 1
    layer = tm.layers[0]
    W, H = layer.width, layer.height
    tilemap = np.zeros((H, W), dtype=object)
    for w, h, dat in layer.tiles():
       f = dat[0]
       tex = f.split('/')[-1].split('.')[0]
       tilemap[h, w] = core.Tile(tiles[tex], h, w, nCounts, tex)
    return tilemap
github bitcraft / PyTMX / pytmx / util_pyglet.py View on Github external
def load_pyglet(filename, *args, **kwargs):
    kwargs['image_loader'] = pyglet_image_loader
    kwargs['invert_y'] = True
    return pytmx.TiledMap(filename, *args, **kwargs)
github bitcraft / PyTMX / pytmx / util_pysdl2.py View on Github external
def load_pysdl2(renderer, filename, *args, **kwargs):
    kwargs['image_loader'] = partial(pysdl2_image_loader, renderer)
    return pytmx.TiledMap(filename, *args, **kwargs)
github etmaifo / BoilerPlate2D / gamelib / levelparser.py View on Github external
def load_assets(self):
        self.data = pytmx.TiledMap(self.filename)
        self.width = self.data.width * self.data.tilewidth
        self.height = self.data.height * self.data.tileheight

        for layer in self.data.layers:
            if layer.name.upper() == "PLAYER":
                self.players = layer
                self.lifts = layer
            elif layer.name.upper() == "BLOCKS":
                self.blocks = layer
github bitcraft / PyTMX / pytmx / util_pygame.py View on Github external
this utility has 'smart' tile loading.  by default any tile without
    transparent pixels will be loaded for quick blitting.  if the tile has
    transparent pixels, then it will be loaded with per-pixel alpha.  this is
    a per-tile, per-image check.

    if a color key is specified as an argument, or in the tmx data, the
    per-pixel alpha will not be used at all. if the tileset's image has colorkey
    transparency set in Tiled, the util_pygam will return images that have their
    transparency already set.

    TL;DR:
    Don't attempt to convert() or convert_alpha() the individual tiles.  It is
    already done for you.
    """
    kwargs['image_loader'] = pygame_image_loader
    return pytmx.TiledMap(filename, *args, **kwargs)
github Tuxemon / Tuxemon / tuxemon / core / components / map.py View on Github external
'parent': ,
         'priority': '1',
         'rotation': 0,
         'type': 'action',
         'visible': 1,
         'width': 16,
         'x': 0,
         'y': 0}

        """
        # Load the tmx map data using the pytmx library.
        self.filename = filename

        # Scale the loaded tiles if enabled
        if prepare.CONFIG.scaling:
            self.data = pytmx.TiledMap(filename,
                                       image_loader=scaled_image_loader,
                                       pixelalpha=True)
            self.data.tilewidth, self.data.tileheight = prepare.TILE_SIZE
        else:
            self.data = load_pygame(filename, pixelalpha=True)

        # Get the properties of the map
        if type(self.data.properties) == dict:
            # Get the edge type of the map
            if "edges" in self.data.properties:
                self.edges = self.data.properties["edges"]

        # make a scrolling renderer
        self.renderer = self.initialize_renderer()

        # Get the map dimensions