mac上StudioCode中的Pygame不会闪电战



我无法在mac上使用工作室代码将任何东西闪电式地写入我的pygame屏幕。这是一个已知的问题,还是有办法解决我忽视的问题?我没有犯任何错误,只是什么都没做。我对pygame有点陌生,所以任何事情都可以。这是我的代码:

pygame.display.set_caption('The space Simulator')
red=(255, 0, 0)
white=(255, 255, 255)
black=(0, 0, 0)
green=(0, 255, 0)
blue=(0, 0, 255)
image = pygame.image.load(r'/Users/Mr.Penguin280/Desktop/Photos/Logo.jpg')
screen = pygame.display.set_mode([1000, 1000])
background = pygame.Surface((1000,1000))
text1 = myfont.render('WELCOME TO MY SIMULATOR.', True, red)
textpos = text1.get_rect()
textpos.centerx = background.get_rect().centerx


running=True
while running:
screen.blit(image, (textpos))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

您只是没有将绘图图元刷新/更新到屏幕上。实际上,在所有闪电战完成后,您只需要一个pygame.display.update()pygame.display.flip()

我想你删除了部分代码是为了让问题变得简单,但我把它们放回原处是为了得到一个有效的答案。

我还重新安排了代码,并删除了background曲面的创建,只是为了获得中心坐标。此操作可以在现有的screen曲面上执行。

import pygame

red=(255, 0, 0)
white=(255, 255, 255)
black=(0, 0, 0)
green=(0, 255, 0)
blue=(0, 0, 255)
pygame.init()
pygame.display.set_caption('The space Simulator')
screen = pygame.display.set_mode([1000, 1000])
#image = pygame.image.load(r'/Users/Mr.Penguin280/Desktop/Photos/Logo.jpg')
image  = pygame.image.load('background.png' ).convert()
image  = pygame.transform.smoothscale( image, (1000,1000) )
#background = pygame.Surface((1000,1000))
myfont  = pygame.font.SysFont( None, 24 )
text1   = myfont.render('WELCOME TO MY SIMULATOR.', True, red)
textpos = text1.get_rect()
textpos.centerx = screen.get_rect().centerx

running=True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.blit(image, (0,0))
screen.blit(text1, (textpos))
pygame.display.flip()
pygame.quit()

最新更新