TypeError“module”对象不是callab

2024-10-03 23:26:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我在一个项目中使用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

在主.py在

^{pr2}$

在加载.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

Tags: inpyselfmainlinetestingsurfacepygame
1条回答
网友
1楼 · 发布于 2024-10-03 23:26:14
def makeSurface(self):
    tiledSurface = pygame.Surface((self.mapWidth, self.mapWidth))
    self.render(tiledSurface)
    return tiledSurface

注意,我更改了上面第二行的大写字母。游戏。表面是你要找的班级,游戏表面不是一个类。在

相关问题 更多 >