내가 작업중인 프로젝트에서 pytmx를 사용하여 투명성에 문제가 있었지만 꽤 길고 잘 작성되지 않았습니다. 그래서 방금 tiledmap (이 게시물)을 만든 더 작은 버전을 만들려고했지만이 오류가 발생합니다.
편집하다:
Traceback (most recent call last):
File "E:/advcomp/testing/main.py", line 34, in <module>
playGame.gameLoop()
File "E:/advcomp/testing/main.py", line 21, in gameLoop
self.loadMap()
File "E:/advcomp/testing/main.py", line 30, in loadMap
self.map_img = self.map.makeSurface()
File "E:\advcomp\testing\loading.py", line 19, in makeSurface
tiledSurface = pygame.surface((self.mapWidth, self.mapWidth))
TypeError: 'module' object is not callable
main.py
import pygame
from settings import *
from loading import *
class game():
def __init__(self):
self.screen = pygame.display.set_mode((displayWidth, displayHeight))
pygame.display.set_caption(title)
self.clock = pygame.time.Clock()
self.gameRunning = True
def loop(self):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.gameRunning = False
def gameLoop(self):
self.clock.tick(fps)
self.loop()
self.loadMap()
self.editScreen()
def editScreen(self):
self.screen.blit(self.map_img, (0,0))
pygame.display.update()
def loadMap(self):
self.map = tiledMap()
self.map_img = self.map.makeSurface()
playGame = game()
while playGame.gameRunning == True:
playGame.gameLoop()
loading.py
import pygame
import pytmx
pygame.init()
class tiledMap():
def __init__(self):
self.gameMap = pytmx.load_pygame("maps\_testingMap.tmx")
self.mapWidth = self.gameMap.width * self.gameMap.tilewidth
self.mapHeight = self.gameMap.height * self.gameMap.tilewidth
def render(self, surface):
for layer in self.gameMap.visible_layers:
for x,y,gid in layer:
tile = pytmx.get_tile_image_by_gid(gid)
surface.blit(tile, (x * self.gameMap.tilewidth, y * self.gameMap.tileheight))
def makeSurface(self):
tiledSurface = pygame.surface((self.mapWidth, self.mapWidth))
self.render(tiledSurface)
return tiledSurface
def makeSurface(self):
tiledSurface = pygame.Surface((self.mapWidth, self.mapWidth))
self.render(tiledSurface)
return tiledSurface
위 두 번째 줄의 대소 문자를 변경했습니다. pygame.Surface는 찾고있는 클래스이고 pygame.surface는 클래스가 아닙니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다