2017-02-04 7 views
1

ウィンドウにレンダリングされたテキストがあります。 screen.fill()関数を使用すると、テキストは画面の前に残っているので、背景は変わりますが、テキストはまだ覆い残ります。あなたのwhileループではPygameのレンダリングされたテキストを削除する

#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() 
+0

の代わりに 'True ='と 'True =と' == 0: 'を使うことができますが、' menu == 0: 'は同じです。しかし、 'menu = 0'の代わりに' menu = True'を使い、その後 'while menu:' – furas

+0

を使うと 'while 'の前に両方の色でテキストをレンダリングし、' while'では 'blit()' – furas

答えて

2

、あなたはfill関数を呼び出し、その後、あなたループバックアップし、あなたのテキストを印刷します。

すべての要素がレイヤーであると考える必要があります。上からループを開始するとき、関数の順序は、どの要素が他の要素の前にあるかを定義することです。

通常、背景を描画してから、個々の要素を印刷します(レイヤーを考えている)。

ボタンをクリックして、私がやろうとしていると思われるメニューを非表示にするには、状態のメモリを変数に保存する必要があります。たとえば、の場合は、Trueがテキストを表示し、それ以外の場合は背景のみを表示します。それ以外の場合は、ループの途中に戻ると、すべてが再度印刷されます。

関連する問題