如何获取 pygame 中某个精灵的图像编号

How can i get the number of an image of a certain sprite in pygame

我随机分享屏幕上的房子图片。然后我开车穿过 screen.When 车撞到了一个房子,那个房子的图像应该换成那个房子的修改副本。 我使用以下函数分发图像

while len(land) < anzahl_gegenstaende:
        ii = len(land)
        img = pygame.image.load(f"Bilder/Gegenstaende/geg{ii}.png").convert_alpha() 
        zb,zh = img.get_rect().size
        scale_hoehe =100
        scale_breite = int(100 * zb / zh)        
        img = pygame.transform.scale(img,(scale_breite,scale_hoehe))            
        m = Landschaft(img)
        
        if not pygame.sprite.spritecollide(m, land, False):           
            land.add(m)    

我查车撞房子

treffer = pygame.sprite.spritecollide( auto, land, False, pygame.sprite.collide_mask)    
  
for bumbs in treffer: 

..... 那么如何获取碰撞房屋的门牌号或图片号,以便我可以用稍微修改过的副本替换图片?

将图像编号存储在 Sprite 的属性中 class:

class Landschaft(pygame.sprite.Sprite):
    def __init__(self, img, ii):
        super().__init__() 
        self.img = img
        self.ii = ii
        # [...]
while len(land) < anzahl_gegenstaende:
    ii = len(land)
    img = pygame.image.load(f"Bilder/Gegenstaende/geg{ii}.png").convert_alpha() 
    # [...]

    m = Landschaft(img, ii)
    if not pygame.sprite.spritecollide(m, land, False):           
        land.add(m)    
treffer = pygame.sprite.spritecollide(auto, land, False, pygame.sprite.collide_mask)    
for bumbs in treffer: 
    ii = bomb.ii
    # [...]