2014-02-28 461 views
2

如何從pygame sprites中的一組圖像中獲取圖像?到目前爲止,我得到了這個:如何從一組圖像中獲取隨機圖像?

for i in range(1,3): 
    img = pygame.image.load("house"+str(i)+".png").convert() 
    img.set_colorkey(white) 
    self.images.append(img) 

但我不太清楚如何從圖像列表中隨機收集圖像。我該怎麼做呢?如果可能的話,我怎樣才能讓它成爲圖像列表中的圖像的機會,比如圖像將出現在pygame窗口上的1/10的可能性? Python 2.6,Pygame,windows 7

回答

3

您似乎有一個圖像列表綁定到名稱self.images
如果你想隨機選擇其中之一:

import random 

random_image = random.choice(self.images)