问题描述
import pygame
import time
pygame.init()
black = (0,0)
white = (255,255,255)
display = pygame.display.set_mode((800,600))
pygame.display.set_caption('fitness')
font = pygame.font.SysFont(None,200)
def message_to_screen(msg,color):
screen_text = font.render(msg,True,color)
display.blit(screen_text,[800/2,600/2])
exercises =["pelvic shift","hanging","single leg hopping","puppy pose","side strech","low lunge arcs","cobra strech","jogging,skipping","vertical bends","standing strechs","side bends","swimming","toe lifts","land swimming","legs up alternate","leg kicks","wake up stretchinggutes and hip bridges","forward spine stretch","cat camel back stetch","mermaid stretch","cycling","jump squats","cobra stretch","downward facing dog","bird dog","inversion table exercise","surya namaskars","side planks"]
def exerciseLoop():
for x in exercises:
for number_of_exercise in range(1,29):
z = exercises.index(x)
if number_of_exercise == (z+1):
final={}
final.update({number_of_exercise:x})
message_to_screen("start",black)
clock = pygame.time.Clock()
FPS = 30
clock.tick(FPS)
display.fill(white)
pygame.display.update()
exerciseLoop()
解决方法
白色涂在文字上方。你需要先把它涂成白色,然后写下文字:
import pygame
import time
pygame.init()
black = (0,0)
white = (255,255,255)
Display = pygame.display.set_mode((800,600))
pygame.display.set_caption('fitness')
font = pygame.font.SysFont(None,200)
def message_to_screen(msg,color):
screen_text = font.render(msg,True,color)
Display.blit(screen_text,[800/2,600/2])
exercises =["pelvic shift","hanging","single leg hopping","puppy pose","side strech","low lunge arcs","cobra strech","jogging,skipping","vertical bends","standing strechs","side bends","swimming","toe lifts","land swimming","legs up alternate","leg kicks","wake up stretchinggutes and hip bridges","forward spine stretch","cat camel back stetch","mermaid stretch","cycling","jump squats","cobra stretch","downward facing dog","bird dog","inversion table exercise","surya namaskars","side planks"]
def exerciseLoop():
for x in exercises:
for number_of_exercise in range(1,29):
z = exercises.index(x)
if number_of_exercise == (z+1):
final={}
final.update({number_of_exercise:x})
Display.fill(white)
message_to_screen("start",black)
clock = pygame.time.Clock()
FPS = 30
clock.tick(FPS)
pygame.display.update()
exerciseLoop()
,
您必须处理应用程序循环中的事件。分别见pygame.event.get()
pygame.event.pump()
:
对于游戏的每一帧,您都需要对事件队列进行某种调用。这可确保您的程序可以在内部与操作系统的其余部分进行交互。
def exerciseLoop():
clock = pygame.time.Clock()
FPS = 30
run = True
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
for x in exercises:
for number_of_exercise in range(1,29):
z = exercises.index(x)
if number_of_exercise == (z+1):
final={}
final.update({number_of_exercise:x})
Display.fill(white)
message_to_screen("start",black)
pygame.display.update()
exerciseLoop()
典型的 PyGame 应用程序循环必须:
- 通过
pygame.event.pump()
或pygame.event.get()
处理事件。 - 根据输入事件和时间(分别为帧)更新游戏状态和对象位置
- 清除整个显示或绘制背景
- 绘制整个场景(
blit
所有对象) - 通过
pygame.display.update()
或pygame.display.flip()
更新显示