'游戏。表面'对象不是subscriptab

2024-06-16 14:56:50 发布

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

有人能修好我的密码吗?我一直收到一个错误消息:

'pygame.Surface' object is not subscriptable

在第40行,上面写着

SURF.blit(Dirt[tilemap[row][column]], (column*tilesize, row*tilesize))

我使用的是pygame,我对python非常陌生。谢谢你的帮助,非常感谢。在

    import pygame, sys
    import Sprites
    import random

    pygame.init()

    from pygame.locals import *

    #DISPLAY = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)

    pygame.init()

    infoObject = pygame.display.Info()

    print(infoObject.current_w, infoObject.current_h)

    tilesize = 40

    TILESX = infoObject.current_w // 40
    TILESY = infoObject.current_h // 40

    print(TILESX, TILESY)

    WHITE = (255, 255, 255)
    BLACK = (0, 0, 0)

    Dirt = pygame.image.load('Sprites/Dirt.png')

   textures = {
       Dirt
   }
   tilemap = [[Dirt for w in range(TILESX)] for h in range(TILESY)]

   SURF = pygame.display.set_mode((TILESX * tilesize, TILESY * tilesize))

   while True:

for row in range(TILESY):
    for column in range(TILESX):
        SURF.blit(Dirt[tilemap[row][column]], (column * tilesize, row * tilesize))

pygame.display.update()
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        pygame.quit()
        sys.exit()

输入()


Tags: inimportfordisplayrangecolumncurrentpygame