Friday, 23 August 2013

Screen pausing and updating slowly

Screen pausing and updating slowly

This program is running too slow and pausing frequently in my computer.
Any clue on what may be happening? Is it because of the image format?
import sys, pygame
from pygame.locals import *
pygame.init()
WINDOW_WIDTH = 640
WINDOW_HEIGHT = 480
SPEED = [2, 2]
BLACK = ( 0, 0, 0)
BGCOLOR = BLACK
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
ball = pygame.image.load("ball.png")
ballrect = ball.get_rect()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
ballrect = ballrect.move(SPEED)
if ballrect.left < 0 or ballrect.right > WINDOW_WIDTH:
SPEED[0] = -SPEED[0]
if ballrect.top < 0 or ballrect.bottom > WINDOW_HEIGHT:
SPEED[1] = -SPEED[1]
screen.fill(BLACK)
screen.blit(ball, ballrect)
pygame.display.flip()

No comments:

Post a Comment