TypeError 'module' 对象不可调用
TypeError 'module' object is not callable
我在一个项目中使用 pytmx 时遇到透明度问题,但它很长而且写得不是很好。所以我试图制作一个较小的版本,它只是制作了 tiledmap(this post) 但我收到了这个错误。
编辑:
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是你要找的class,pygame.surface不是class。
我在一个项目中使用 pytmx 时遇到透明度问题,但它很长而且写得不是很好。所以我试图制作一个较小的版本,它只是制作了 tiledmap(this post) 但我收到了这个错误。
编辑:
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是你要找的class,pygame.surface不是class。