3

I am trying to create a game map in pygame with Tiled but I don't know how to setup the collision for every tile. I successfully displayed the map on the screen, but how to verify the collisions? Here is the code:

import pytmx
import pygame

pygame.init()

display = pygame.display.set_mode((800,400))
clock = pygame.time.Clock()

gameMap = pytmx.load_pygame("map.tmx")

for layer in gameMap.visible_layers:
    for x, y, gid in layer:
        tile = gameMap.get_tile_image_by_gid(gid)
        if(tile != None):
            display.blit(tile, (x * gameMap.tilewidth, y * gameMap.tileheight))
while(True):

    clock.tick(60)
    keys = pygame.key.get_pressed()

    if(keys[pygame.K_ESCAPE]):
        quit()

    for event in pygame.event.get():
        if(event.type == pygame.QUIT):
            quit()

    pygame.display.update()

I didn't setup any collisions in Tiled because I don't know how.

user193464
  • 380
  • 1
  • 6
  • 25
  • Does [this post](https://gamedev.stackexchange.com/questions/121832/how-to-integrate-tiled-maps-and-collision-detection-with-pygame) help? (I haven't checked it out yet.) – skrx Sep 01 '17 at 16:04

0 Answers0