-2
我做了一个while循环和.blit()工作正常,但是当它到达if语句时,我的加载符号出现,似乎没有任何工作。我正在做我的while循环吗?我也希望我的menu1 == False
触发下一个while循环。为什么我的while循环中的任何if语句都不起作用?
#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)
menu1 = True
#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
while menu1 == True:
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()):
menu1 == False
while menu1 == False:
screen.fill(color)
pygame.display.update()
pygame.display.update()
'menu1 == False'是一个比较,评估为'False'为'True!= False',** not **一个任务。你也可以“打破”。 – jonrsharpe
游戏的每个状态(菜单,选项,游戏,帮助等)都应该有自己的循环并包含:** 1 **。保持恒定帧速率的时钟。 ** 2 **。事件循环。 ** 3 **。更新对象。 ** 4 **。 Blit /绘制物体。 ** ** 5。更新显示。 [Here](http://stackoverflow.com/documentation/pygame/3959/getting-started-with-pygame/14697/a-simple-game#t=201702041456298336222)是一个简单的演练。 –
也许你需要'如果menu1 == True'而不是'while menu1 == True'。你也可以将它分成独立的循环:http://imgur.com/MT7tZ4s – furas