Python 删除Pygame中的渲染文本
我有一些在窗口上呈现的文本。当我使用screen.fill()函数时,文本仍然保留在屏幕前面,因此背景会发生变化,但文本仍然没有覆盖Python 删除Pygame中的渲染文本,python,pygame,render,Python,Pygame,Render,我有一些在窗口上呈现的文本。当我使用screen.fill()函数时,文本仍然保留在屏幕前面,因此背景会发生变化,但文本仍然没有覆盖 #Importing Stuff import pygame import sys import time import random from pygame.locals import* pygame.init() #Naming Variables menu = 0 color = (65,105,225) tcolor = (255,255,255) pc
#Importing Stuff
import pygame
import sys
import time
import random
from pygame.locals import*
pygame.init()
#Naming Variables
menu = 0
color = (65,105,225)
tcolor = (255,255,255)
pcolor = (255,255,255)
hcolor = (255,255,255)
width, height = 1920, 1080
screen = pygame.display.set_mode((width, height))
hecolor = (255,255,255)
sys_font = pygame.font.SysFont \
("None", 60)
#Initializing Screen
pygame.display.set_caption("TSA Trend Game")
screen.fill(((color)))
pygame.display.update()
#Making Menu
while 1 == 1 and menu == 0:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
#More Variables
rendered = sys_font.render \
("Welcome to Trends of 2016!", True, ((tcolor)))
play = sys_font.render \
("Play Game", True, ((pcolor)))
help = sys_font.render \
("Help", True, ((hcolor)))
play_r = play.get_rect()
play_r.x, play_r.y = 710, 500
help_r = help.get_rect()
help_r.x, help_r.y = 1170, 500
render_r = play.get_rect()
render_r.x, render_r.y = 710, 500
#Display Text
screen.blit(rendered, (710, 440))
screen.blit(help, (1170, 500))
screen.blit(play, (710, 500))
pygame.display.update()
if render_r.collidepoint(pygame.mouse.get_pos()):
pcolor = (255,255,0)
else:
pcolor = (255,255,255)
if help_r.collidepoint(pygame.mouse.get_pos()):
hcolor = (255,255,0)
else:
hcolor = (255,255,255)
if event.type == pygame.MOUSEBUTTONDOWN and help_r.collidepoint(pygame.mouse.get_pos()):
screen.fill(pygame.Color("black"))
pygame.display.update()
在
while
循环中,调用fill
函数,然后循环返回并打印文本
您应该认为所有元素都位于层上。当从顶部开始循环时,函数的顺序是定义哪个元素在哪个其他元素前面
通常从绘制背景开始,然后打印各个元素(考虑图层)
如果你想点击一个按钮,隐藏菜单(我猜你是想这么做的),你需要在一个变量中保存状态的内存。例如,在菜单中有一个
inMenu
,当True
显示文本时,它会显示背景。否则,当您返回循环时,所有内容都将再次打印。相反,1==1
您可以使用True
-,而True和menu==0:
,但当menu==0:时使用。但是您可以使用menu=True
而不是menu=0
,然后使用while菜单:
您可以在while
和while中以两种颜色呈现文本,而while只能替换blit()中的图像