Python Pygame中为矩形赋值时出错

Python Pygame中为矩形赋值时出错,python,pygame,typeerror,rect,Python,Pygame,Typeerror,Rect,我试图制作一个函数,在屏幕上绘制一个矩形地图。此功能是: def parseMap(mapIndex): tileRect = pygame.Rect(0, 0, 32, 32) for x in maps.mapData[mapIndex]: tileRect.x = x*16 for y in x: tileRect.y = y*16 c.blit(maps.grass, tileRect) if maps.ma

我试图制作一个函数,在屏幕上绘制一个矩形地图。此功能是:

def parseMap(mapIndex):
    tileRect = pygame.Rect(0, 0, 32, 32)
    for x in maps.mapData[mapIndex]:
    tileRect.x = x*16
    for y in x:
        tileRect.y = y*16
        c.blit(maps.grass, tileRect)
        if maps.mapData[mapIndex][x][y] == 1: c.blit(maps.tallGrass, tileRect)
虽然我犯了个错误

TypeError: invalid rect assignment
在线:

tileRect.x = x*16

我看不出代码有什么问题。谢谢

如果
x
是一个列表,那么
x*16
会列出重复,而不是乘法

i、 你得到的是

tileRect.x = [1, 1, 1, 1, ...]

什么是
x
?(在
maps.mapData[…]
中有什么?)在下一行,您迭代了它(
对于x中的y:
),它可能是一个列表吗?您确定有错误并且缩进正确吗?我运行了相同的代码,没有错误。@Seth maps.mapData是一个三维列表,其中[mapIndex]是地图,然后它有坐标[x]和[y]。@Seth天哪,我不敢相信我没有意识到这一点!非常感谢你!移动评论以回答问题。