簡體   English   中英

Pygame文本未出現在窗口中

[英]Pygame text not appearing in window

我正在代碼中實現文本,以便我可以准確地告訴用戶正在發生的事情,但是在pygame顯示屏上顯示的文本似乎存在問題,尤其是當我調用它時。

我已經嘗試了在pygame窗口中顯示文本的各種方法,但它似乎不起作用。

類maze():def init (自我,新):self.new =新的self.walls = [] self.lab_walls = [] self.cells = []

    a = 0
    v = 0

    for q in range(23):
        for r in range(39):
            deed = q in (0,1,2) and r > 60
            if not deed:
                self.cells.append(cell((a + 8, v, 25,8), (a + 8, v + 33, 25, 8), (a, v + 8, 8 ,25), (a + 33, v + 8, 8, 25)))
            a += 33
        a = 0
        v += 33

    for w in self.cells[0].walls:
        self.lab_walls.append(w)
        self.walls.append(w)

    self.cells[0].view = True

    while len(self.walls) > 0:
        bounds = random.choice(self.walls)
        divcells = []
        for p in self.cells:
            if bounds in p.walls:
                divcells.append(p)

        if len(divcells) > 1 and (not ((divcells[0].view and divcells[1].view) or ((not divcells[0].view) and (not divcells[1].view)))):

            for g in divcells:
                g.walls.remove(bounds)

                if g.view == False:
                    g.view = True

                for o in g.walls:
                    if not o in self.walls:
                        self.walls.append(o)

                    if not o in self.lab_walls:
                        self.lab_walls.append(o)

                if bounds in self.lab_walls:
                    self.lab_walls.remove(bounds)

        self.walls.remove(bounds)

    for j in range(0, 789, 33):
        for i in range(0, 1290, 33):
            self.lab_walls.append((i, j, 8, 8))

 def draw(self, win):
    displaysurf.fill(WHITE)

    for g in self.lab_walls:
        pygame.draw.rect(displaysurf, BLACK, pygame.Rect(g[0], g[1], g[2], g[3]))
    pygame.draw.rect(displaysurf, PURPLE, win)

文本應該顯示在pygame窗口上,但是除了背景之外什么都沒有顯示。

問題在於您僅在初始渲染中渲染標簽,但是在主循環中渲染了背景,這基本上清除了屏幕,因此您需要為每一幀再次渲染所有內容。 移動線

screen.blit(label, (600,600))

上線前

pygame.display.flip()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM