Pygame文字未显示在窗口中

时间:2019-05-03 06:08:29

标签: python python-3.x pygame

我正在代码中实现文本,以便我可以准确地告诉用户正在发生的事情,但是在pygame显示屏上显示的文本似乎存在问题,尤其是当我调用它时。

我已经尝试了在pygame窗口中显示文本的各种方法,但似乎不起作用。

class 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窗口上,但是除了背景之外什么都没有显示。

1 个答案:

答案 0 :(得分:2)

问题在于您仅在初始渲染中渲染标签,但是在主循环中渲染了背景,这基本上清除了屏幕,因此您需要为每一帧再次渲染所有内容。移线

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

在行之前

pygame.display.flip()