How to use the pytmx.TiledTileLayer 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 lukeshorejones / rpg-test / map.py View on Github external
def render(self, surface):
        tileImage = self.tmxdata.get_tile_image_by_gid

        for layer in self.tmxdata.visible_layers:
            if isinstance(layer, pytmx.TiledTileLayer):
                for x, y, gid, in layer:
                    tile = tileImage(gid)
                    if tile:
                        surface.blit(tile, (x*self.tmxdata.tilewidth, y*self.tmxdata.tileheight))

        for tile_object in self.tmxdata.objects:
            if tile_object.type == 'blue_cam':
                self.blue_cam_spawn = (tile_object.x, tile_object.y)
            if tile_object.type == 'red_cam':
                self.red_cam_spawn = (tile_object.x, tile_object.y)
            if tile_object.type == 'blue_spawn':
                self.blue_spawns.append((int(tile_object.name), tile_object.x, tile_object.y))
            if tile_object.type == 'red_spawn':
                self.red_spawns.append((int(tile_object.name), tile_object.x, tile_object.y))
            elif tile_object.type == 'obstacle':
                for i in range(int(tile_object.width/WIDTH)):
github bitcraft / PyTMX / apps / test_pygame.py View on Github external
size as the map.
        
        Scrolling is a often requested feature, but pytmx is a map
        loader, not a renderer!  If you'd like to have a scrolling map
        renderer, please see my pyscroll project.
        """

        # fill the background color of our render surface
        if self.tmx_data.background_color:
            surface.fill(pygame.Color(self.tmx_data.background_color))

        # iterate over all the visible layers, then draw them
        for layer in self.tmx_data.visible_layers:
            # each layer can be handled differently by checking their type

            if isinstance(layer, TiledTileLayer):
                self.render_tile_layer(surface, layer)

            elif isinstance(layer, TiledObjectGroup):
                self.render_object_layer(surface, layer)

            elif isinstance(layer, TiledImageLayer):
                self.render_image_layer(surface, layer)
github bitcraft / PyTMX / apps / test_pysdl2_cffi.py View on Github external
def render_map(self):
        """ Render the entire map

        Only tile layer drawing is implemented
        """
        for layer in self.tmx_data.visible_layers:

            # draw map tile layers
            if isinstance(layer, TiledTileLayer):
                self.render_tile_layer(layer)
github kidscancode / gamedev / dash / dash.py View on Github external
def render(self, surface):
        tw = self.tmxdata.tilewidth
        th = self.tmxdata.tileheight
        gt = self.tmxdata.get_tile_image_by_gid

        if self.tmxdata.background_color:
            surface.fill(self.tmxdata.background_color)

        test_img = pygame.Surface([32, 32])
        test_img.fill(GREEN)
        for layer in self.tmxdata.visible_layers:
            if isinstance(layer, pytmx.TiledTileLayer):
                for x, y, gid in layer:
                    tile = gt(gid)
                    if tile:
                        surface.blit(tile, (x*tw, y*th))
                    # else:
                    #     surface.blit(test_img, (x*tw, y*th))
            elif isinstance(layer, pytmx.TiledObjectGroup):
                pass
            elif isinstance(layer, pytmx.TiledImageLayer):
                image = gt(layer.gid)
                if image:
                    surface.blit(image, (0, 0))
github kidscancode / gamedev / tutorials / tilemap / working / tilemap.py View on Github external
def render(self, surface):
        ti = self.tmxdata.get_tile_image_by_gid
        for layer in self.tmxdata.visible_layers:
            if isinstance(layer, pytmx.TiledTileLayer):
                for x, y, gid, in layer:
                    tile = ti(gid)
                    if tile:
                        surface.blit(tile, (x * self.tmxdata.tilewidth,
                                            y * self.tmxdata.tileheight))