gpt4 book ai didi

python - 在 Pygame 中为矩形赋值时出错

转载 作者:行者123 更新时间:2023-11-28 18:45:35 24 4
gpt4 key购买 nike

我试图制作一个在屏幕上绘制矩形 map 的函数。这个函数是:

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 执行列表重复,而不是乘法。

也就是说,你会得到类似的东西

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

关于python - 在 Pygame 中为矩形赋值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20716990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com