是否可以 font.render 列表中的元素以正确的顺序排列 pygame?

Is it possible to font.render elements of list in right order pygame?

我不明白是否可以从列表中用 pygame 个单词逐一显示。我找到了以随机顺序显示的不同方法,但我不知道如何以正确的顺序显示。

places = ["London", "India", "America", "Australia", "Cambodia", "China",
          "Dubai", "Egypt", "France", "Germany", "Japan", "Jordan",
          "Korea", "Myanmar", "Peru", "Russia", "Singapore", "Spain"]


def text():
    game_font = pygame.freetype.SysFont("monospace", 35)
    text_surface, rect = game_font.render(places[0], (0, 0, 0))
    screen.blit(text_surface, (680, 420))


interval = 2  # Set interval in seconds
last_time = time.time()  # Get the current time in seconds


# Game loop
running = True
while running:
    screen.fill((255, 255, 255))  # RGB
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    #    card()
    # If 2 seconds has past since the last update to last_time
    if time.time() - last_time >= interval:
        for i in places:
            a=i
        last_time = time.time()

    text()
    pygame.display.update()

pygame.quit()

此代码以随机顺序显示 places。我想按 LondonIndia 等顺序显示它们。 有可能吗?因为当我尝试迭代列表时,它会显示 Spain(我不知道为什么)并停止。谢谢

答案很简单,它显示了西班牙,因为 a 最终成为地点列表的最后一个元素,因为 a 最终成为最后一个 i,您只需创建一个变量 index 在循环之前并将其值设置为 0 并在来自 places[0] 的文本函数中将其转换为 places [index] 然后添加一行 index +=1。同时删除 for 循环迭代 places