屏幕僅在我移動光標時更新有人知道如何解決此問題import pygame, sysdef draw_floor():? ? screen.blit(floor_surface, (floor_animation, 400))? ? screen.blit(floor_surface, (floor_animation + 275,400))pygame.init()screen = pygame.display.set_mode((275,512))clock = pygame.time.Clock()bg_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/background-day.png').convert()floor_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/base.png').convert()floor_animation = 0bird_surface = pygame.image.load('C:/Users/cuerv/Downloads/flappy-bird-assets-master/flappy-bird-assets-master/sprites/bluebird-midflap.png').convert()bird_rect = bird_surface.get_rect(center = (100,256))while True:? ?? ? for event in pygame.event.get():? ? ? ? if event.type == pygame.QUIT:? ? ? ? ?? ? ? ? ? ? pygame.quit()? ? ? ? ? ? sys.exit()? ? ? ? screen.blit(bg_surface, (0, 0))? ? ? ? screen.blit(bird_surface, (bird_rect))? ? ? ??? ? ? ? floor_animation -= 1? ? ? ? draw_floor()? ? ? ? if floor_animation <= -275:? ? ? ? ? ? floor_animation = 0? ? ? ? ? ??? ? ? ? screen.blit(floor_surface, (floor_animation, 400))? ? pygame.display.update()? ? clock.tick(120)? ? enter code here
2 回答

精慕HU
TA貢獻1845條經驗 獲得超8個贊
這是縮進的問題。在應用程序循環而不是事件循環中繪制場景:
# application loop
while True:
? ?
? ? # event loop
? ? for event in pygame.event.get():
? ? ? ? if event.type == pygame.QUIT:
? ? ? ? ?
? ? ? ? ? ? pygame.quit()
? ? ? ? ? ? sys.exit()
? ??
? ? #<--| INDENTATION
? ? screen.blit(bg_surface, (0, 0))
? ? screen.blit(bird_surface, (bird_rect))? ? ?
? ? floor_animation -= 1
? ? draw_floor()
? ? if floor_animation <= -275:
? ? ? ? floor_animation = 0? ? ? ? ? ??
? ? screen.blit(floor_surface, (floor_animation, 400))
? ? pygame.display.update()
注意,事件循環僅在事件發生時執行,但應用程序循環是連續執行的。
添加回答
舉報
0/150
提交
取消