【发布时间】:2023-02-09 04:34:06
【问题描述】:
我有我在 visual studio code 中运行的代码,扩展名为 pygame,但我有很多滞后!我不知道该怎么办,这是代码:
import pygame, sys
pygame.init()
clock = pygame.time.Clock()
screen_width = 900
screen_height = 600
screen = pygame.display.set_mode((screen_width,screen_height))
pygame.display.set_caption('Hungry Plant')
bird = pygame.Rect(screen_width/2 - 15,screen_height/2 - 15,30,30)
player = pygame.Rect(screen_width/2 - 25, screen_height/1.20,50,300)
bg_color = pygame.Color('grey12')
light_grey = (200,200,200)
light_green = (144, 238, 144)
bird_speed_x = 7
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
bird.x += bird_speed_x
if bird.left <= 0 or bird.right >= screen_width:
bird_speed_x *= -1
screen.fill(bg_color)
pygame.draw.rect(screen,light_green, player)
pygame.draw.ellipse(screen, light_grey, bird)
pygame.display.flip()
clock.tick(30)
我试图在网上找到解决方案,但没有成功!
【问题讨论】: