This simple piece of code crashes (the window is not responding) after a few seconds (around 5).
import pygame
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 24)
#clock = pygame.time.Clock()
#font = pygame.font.Font(None, 32)
cycles = 0
while True:
screen.fill(0)
# text = font.render('Cycles : %d' % cycles, True, (255, 255, 255))
# screen.blit(text, (100, 100))
cycles += 1
pygame.display.update()
If I uncomment the commented lines, I can clearly see the program going out of control when displaying values between 47 and 50.
I use python 2.7 and pygame 1.9.2, Windows 8 (64 bits) and Eclipse + PyDev.
pygame. QUIT is sent when the user clicks the window's "X" button, or when the system 'asks' for the process to quit.
The pygame. init() error is caused by its function not being called and can be solved with the import and initialization of pygame modules.
flip() for software displays. It allows only a portion of the screen to updated, instead of the entire area. If no argument is passed it updates the entire Surface area like pygame.
Call pygame.event.get()
at the beginning of the while loop.
You need to regularly make a call to one of four functions in the pygame.event
module in order for pygame to internally interact with your OS. Otherwise the OS will think your game has crashed. So make sure you call one of these:
pygame.event.get()
returns a list of all events currently in the event queue.pygame.event.poll()
returns a single event from the event queue or pygame.NOEVENT
if the queue is empty.pygame.event.wait()
returns a single event from the event queue or waits until an event can be returned.pygame.event.pump()
allows pygame to handle internal actions. Useful when you don't want to handle events from the event queue.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With