J'ai été sturggling un peu, j'essaye d'exécuter du code qui montre mon tilemap que j'ai fait dans Tiled, mais je semble avoir messedit jusqu'à , car la fenêtre pygame reste bloquée et ne répond pas. Aucune idée si j'ai formaté correctement mais je ne fais pas cela beaucoup, et beaucoup de cela est commenté de toute façon. Voici le code:Essayer de charger la carte en mosaïque dans pygame, pas d'erreurs lancées mais pygame ne répond pas
import pygame as pg
import pytmx
from settings import *
import os
import time
def collide_hit_rect(one, two):
return one.hit_rect.colliderect(two.rect)
class TiledMap:
def __init__(self, filename):
#loads .tmx tilemap, pixelalpha make sure transparency
tm = pytmx.load_pygame(filename, pixelalpha=True)
#multiplies how many tiles across the map by how many pixels each tile uses
self.width = tm.width * tm.tilewidth
self.height = tm.height * tm.tileheight
#stores all data above in variable tmxdata
self.tmxdata = tm
#draws Tiled map onto pg surface
def render(self, surface):
#stores command that finds image that goes with specific tiles by searching tmx data into ti
ti = self.tmxdata.get_tile_image_by_gid
#for all visible layers in map
for layer in self.tmxdata.visible_layers:
#if statement dependant on layer being Tile layer
if isinstance(layer, pytmx.TiledTileLayer):
#gets coordinates and gid(from .tmx) for each tile in layer
for x, y, gid, in layer:
#ti command gets images for the gid from last line
tile = ti(gid)
if tile:
#draws tile on surface
surface.blit(tile, (x * self.tmxdata.tilewidth,
y * self.tmxdata.tileheight))
def make_map(self):
#creates surface(as big as tilemap) to draw map onto
temp_surface = pg.Surface((self.width, self.height))
#render function will draw tilemap onto temp_surface
self.render(temp_surface)
return temp_surface
class Camera:
def __init__(self, width, height):
self.camera = pg.Rect(0, 0, width, height)
self.width = width
self.height = height
def apply(self, entity):
return entity.rect.move(self.camera.topleft)
#takes rectangle
def apply_rect(self, rect):
# returns rectangle moved by offset position from top left
return rect.move(self.camera.topleft)
def update(self, target):
x = -target.rect.centerx + int(WIDTH/2)
y = -target.rect.centery + int(HEIGHT/2)
# limit scrolling to map size
x = min(0, x) # left
y = min(0, y) # top
x = max(-(self.width - WIDTH), x) # right
y = max(-(self.height - HEIGHT), y) # bottom
self.camera = pg.rect(x, y, self.width, self.height)
class Display():
#This is the class that makes the changes that you want to display. You would add most of your changes here. """
def __init__(self):
self.displayRunning = True
self.displayWindow = pg.display.set_mode((500, 200))
self.clock = pg.time.Clock()
def update(self):
pg.display.set_caption("{:.2f}".format(self.clock.get_fps()))
pg.display.update()
def loadMap(self):
self.map = TiledMap('tilemap skeleton.tmx')
self.map_img = self.map.make_map()
self.map_rect = self.map_img.get_rect()
def displayLoop(self):
self.clock.tick()
self.update()
self.loadMap()
# Here is the start of the main driver
runDisplay = Display()
runDisplay.update()
runDisplay.loadMap()
time.sleep(60)
S'il vous plaît coller exception vous obtenez. – JJAACCEeEKK
Je ne reçois aucune exception la fenêtre de jeu python cesse tout simplement de répondre tout en restant noir. –