Pygame清除屏幕

时间:2018-07-15 16:31:45

标签: python pygame

我制作了一个类,在draw函数中,我绘制了一个textarea,一些静态文本并为屏幕着色。绘制函数处于while循环中。除了输入框,我希望整个pygame屏幕都清除,并且我希望屏幕更改颜色。我怎么做?我的代码如下:

import pygame

from Settings import *

from TextInput import *

from Draw import *

pygame.init() pygame.font.init()

Txt()类:

def __init__(self):

    self.running = True

    pygame.display.set_caption('TruTxt')

    self.input_box = InputBox(50, 550, 1200, 300)

def run(self):

    while self.running:

        self.events()

        self.draw()

def events(self):

    events = pygame.event.get()

    for event in events:

        if event.type == pygame.QUIT:

            self.running = False

        if event.type == pygame.K_RETURN:

            pass

        self.input_box.handle_event(event)

def draw(self):

    start()

    self.input_box.draw(screen)

    pygame.display.flip()

t = Txt()

运行时:

t.run()

pygame.quit()

def start():

screen.fill((0, 0, 255))

myfont = pygame.font.SysFont('Comic Sans MS', 64, True)
displaytxt = myfont.render(hellotxt , True, (255, 255, 255))
screen.blit(displaytxt, (300, 30))

myfont = pygame.font.SysFont('Comic Sans MS', 24)
displaytxt = myfont.render(wlcmtxt , True, (255, 215, 0))        
screen.blit(displaytxt, (30, 200))

myfont = pygame.font.SysFont('Comic Sans MS', 39, True)
displaytxt = myfont.render(strttxt , True, (255, 255, 255))        
screen.blit(displaytxt, (28, 370))

myfont = pygame.font.SysFont('Comic Sans MS', 28, False, True)
displaytxt = myfont.render(destxt , True, (255, 215, 0))        
screen.blit(displaytxt, (165, 450))`

1 个答案:

答案 0 :(得分:1)

从帖子顶部的摘要中,我可以得出结论,您需要做的就是在循环的每次迭代中简单地重新绘制屏幕

screen.fill(color)
#redraw screen