Pygame Wait For Screen To Update
I just started with pygame, and I am just trying to move points across my screen. The problem is that it happens way to fast and my pygame screen freezes (Not Responding) while the
Solution 1:
You have an application loop, use if. Use pygame.time.Clock()
to control the framerate . The application loop has to
- control the framerate (
clock.tick(60)
) - handel the events and move the objects
- clear the display
- draw the scene
- update the display
e.g:
classApp:
def__init__(self):
# [...]
self.clock = pygame.time.Clock()
defrun(self):
self.food_spread()
self.spawn_animal()
run = Truewhile run:
# control the framerate
self.clock.tick(60) # 60 FPS# handel the eventsfor event in pygame.event.get():
if event.type == pygame.QUIT:
run = False# move the objectsfor member in self.zoo:
self.move(member)
# clear the display
self.screen.fill(black)
# draw the scenefor i inrange(self.food_locations.shape[0]):
pygame.draw.rect(self.screen, white, (self.food_locations[i,1], self.food_locations[i,2],1,1))
for member in self.zoo:
pygame.draw.circle(self.screen, green,(member.location[0], member.location[1]), 2,1)
# update the display
pygame.display.update()
Post a Comment for "Pygame Wait For Screen To Update"