pytmx를 이용하여 tmx파일 읽어오기
asset은 Tiled 프로그램내의 샘플을 이용(http://www.mapeditor.org)
<실행화면>
<소스코드>
# -*- coding: utf-8 -*- # # tmx_file_load.py # coding with python 3.5.3 # # http://codememo.tistory.com # import sys import os import pygame import pytmx pygame.init() display = pygame.display.set_mode((512, 368)) pygame.display.set_caption("tmx file load") tmx_data = pytmx.load_pygame("smw_background.tmx") clock = pygame.time.Clock() running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: running = False display.fill((0, 96, 184)) for layer in tmx_data.visible_layers: for x, y, gid, in layer: tile = tmx_data.get_tile_image_by_gid(gid) if tile: display.blit(tile, (x * tmx_data.tilewidth, y * tmx_data.tileheight)) pygame.display.update() clock.tick(60)
<첨부파일>