0
votes

I have created Pygame, which has objects (balls) which randomly move around the screen and the mouse control a character which the user moves around to avoid the other objects. but the random ball that move around the screen have slow refresh rate (you can see them flashing while moving).

I don't know which part of the code is to blame, the objects that move around are loaded here:

ballpic = pygame.image.load('ball.png').convert_alpha()

I don't which other part of the game is to blame so I can include in question, so I have created a pastebin http://pastebin.com/H6KkTvZU which has the game code (short game).

Thank you

2
It's missing resources, like bg.jpg. pygame.error: Couldn't open bg.jpg - jgritty
backdrop = pygame.image.load('bg.jpg').convert_alpha() menu = pygame.image.load('green.jpg').convert_alpha() ballpic = pygame.image.load('ball.png').convert_alpha() mouseball = pygame.image.load('mouseball.gif').convert_alpha() - jgritty
@jgritty I'm following what your saying sorry ? - ErHunt
Can you post the image resource files somewhere? - jgritty

2 Answers

2
votes

You call display.update() on every iteration of for i in range(enemies) loop. Try doing it once per frame, after you have blitted all the sprites.

Even better, learn how to use display.flip() properly; it's faster if you update large portions of the screen.

2
votes

The Pygame newbie tutorial has some other useful advice, particularly how to use "Dirty rect animation" if your frame-rate is still too low.